Add Quiz feature: 10-question quizzes with progressive scoring (max 40 pts)

- Quizzes table with questions, answer options, attempts, answers
- Question types: multiple_choice, exclusion, true_false, free_text
- Progressive scoring: [1,1,2,2,3,3,4,6,8,10] = max 40 per quiz
- Alpine.js countdown timer per question with auto-submit on timeout
- Admin: CRUD for quizzes + per-question editor, JSON export/import
- Child: quiz overview with best scores, question view, result breakdown
- Nav: Quiz link in child header and admin sidebar
This commit is contained in:
root
2026-05-05 21:14:09 +00:00
parent 213d4b4832
commit 6c6dd26823
21 changed files with 984 additions and 1 deletions
@@ -0,0 +1,71 @@
@extends('layouts.admin')
@section('title','Frage hinzufügen')
@section('content')
<div class="max-w-2xl">
<a href="{{ route('admin.quizzes.edit',$quiz) }}" class="text-sm text-slate-500 hover:text-slate-700 mb-4 inline-block"> Zurück zu {{ $quiz->title }}</a>
<div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
<h2 class="font-semibold text-slate-800 mb-5">Neue Frage hinzufügen</h2>
<form method="POST" action="{{ route('admin.quizzes.questions.store',$quiz) }}" class="space-y-4">
@csrf
@php $qtype='multiple_choice'; $correctIdx=0; $question_text=''; $time_limit=''; $correct_answer=''; $options=[]; @endphp
<div x-data="{ qtype: '{{ $qtype }}', correctIdx: {{ $correctIdx }} }">
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Fragetyp</label>
<select name="type" x-model="qtype" required
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
<option value="multiple_choice">Multiple Choice Fehlersuche</option>
<option value="exclusion">Ausschlussverfahren (welches gehört nicht dazu?)</option>
<option value="true_false">Wahr / Falsch</option>
<option value="free_text">Freitext Eingabe</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Frage</label>
<textarea name="question_text" required rows="3"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm font-medium focus:ring-2 focus:ring-violet-500 outline-none">{{ $question_text ?? '' }}</textarea>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Zeitlimit in Sekunden (leer = kein Limit)</label>
<input name="time_limit" type="number" min="5" max="120" value="{{ $time_limit ?? '' }}" placeholder="z.B. 30"
class="w-32 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
{{-- MC / Exclusion options --}}
<div x-show="qtype === 'multiple_choice' || qtype === 'exclusion'" class="space-y-2">
<label class="block text-sm font-medium text-slate-700">Antwortmöglichkeiten <span class="text-slate-400 font-normal">( = richtige Antwort)</span></label>
@for($i = 0; $i < 4; $i++)
<div class="flex items-center gap-3">
<input type="radio" name="correct_option" value="{{ $i }}" x-bind:checked="correctIdx === {{ $i }}"
@change="correctIdx = {{ $i }}"
class="text-violet-600 w-4 h-4 shrink-0">
<input type="text" name="options[{{ $i }}][text]" value="{{ $options[$i]['text'] ?? '' }}"
placeholder="Option {{ $i+1 }}"
class="flex-1 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
@endfor
<p class="text-xs text-slate-400">Klicke den Radio-Button links neben der richtigen Antwort.</p>
</div>
{{-- True / False --}}
<div x-show="qtype === 'true_false'">
<label class="block text-sm font-medium text-slate-700 mb-1">Richtige Antwort</label>
<select name="correct_answer"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
<option value="true" {{ ($correct_answer ?? '') === 'true' ? 'selected' : '' }}> Wahr</option>
<option value="false" {{ ($correct_answer ?? '') === 'false' ? 'selected' : '' }}> Falsch</option>
</select>
</div>
{{-- Free text --}}
<div x-show="qtype === 'free_text'">
<label class="block text-sm font-medium text-slate-700 mb-1">Richtige Antwort (exakter Text, Groß-/Kleinschreibung egal)</label>
<input type="text" name="correct_answer" value="{{ $correct_answer ?? '' }}" placeholder="z.B. 72"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
</div>
<button type="submit" class="w-full bg-violet-600 hover:bg-violet-700 text-white py-2 rounded-lg font-medium text-sm">Frage hinzufügen</button>
</form>
</div>
</div>
@endsection
@@ -0,0 +1,80 @@
@extends('layouts.admin')
@section('title','Frage bearbeiten')
@section('content')
<div class="max-w-2xl">
<a href="{{ route('admin.quizzes.edit',$question->quiz) }}" class="text-sm text-slate-500 hover:text-slate-700 mb-4 inline-block"> Zurück zu {{ $question->quiz->title }}</a>
<div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
<h2 class="font-semibold text-slate-800 mb-5">Frage bearbeiten</h2>
<form method="POST" action="{{ route('admin.quiz-questions.update',$question) }}" class="space-y-4">
@csrf @method('PUT')
@php
$qtype = $question->type;
$question_text = $question->question_text;
$time_limit = $question->time_limit;
$correct_answer = $question->correct_answer;
$opts = $question->answerOptions->toArray();
$options = array_column($opts, null);
$correctIdx = 0;
foreach ($opts as $i => $o) { if ($o['is_correct']) { $correctIdx = $i; break; } }
@endphp
<div x-data="{ qtype: '{{ $qtype }}', correctIdx: {{ $correctIdx }} }">
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Fragetyp</label>
<select name="type" x-model="qtype" required
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
<option value="multiple_choice">Multiple Choice Fehlersuche</option>
<option value="exclusion">Ausschlussverfahren (welches gehört nicht dazu?)</option>
<option value="true_false">Wahr / Falsch</option>
<option value="free_text">Freitext Eingabe</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Frage</label>
<textarea name="question_text" required rows="3"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm font-medium focus:ring-2 focus:ring-violet-500 outline-none">{{ $question_text ?? '' }}</textarea>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">Zeitlimit in Sekunden (leer = kein Limit)</label>
<input name="time_limit" type="number" min="5" max="120" value="{{ $time_limit ?? '' }}" placeholder="z.B. 30"
class="w-32 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
{{-- MC / Exclusion options --}}
<div x-show="qtype === 'multiple_choice' || qtype === 'exclusion'" class="space-y-2">
<label class="block text-sm font-medium text-slate-700">Antwortmöglichkeiten <span class="text-slate-400 font-normal">( = richtige Antwort)</span></label>
@for($i = 0; $i < 4; $i++)
<div class="flex items-center gap-3">
<input type="radio" name="correct_option" value="{{ $i }}" x-bind:checked="correctIdx === {{ $i }}"
@change="correctIdx = {{ $i }}"
class="text-violet-600 w-4 h-4 shrink-0">
<input type="text" name="options[{{ $i }}][text]" value="{{ $options[$i]['text'] ?? '' }}"
placeholder="Option {{ $i+1 }}"
class="flex-1 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
@endfor
<p class="text-xs text-slate-400">Klicke den Radio-Button links neben der richtigen Antwort.</p>
</div>
{{-- True / False --}}
<div x-show="qtype === 'true_false'">
<label class="block text-sm font-medium text-slate-700 mb-1">Richtige Antwort</label>
<select name="correct_answer"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
<option value="true" {{ ($correct_answer ?? '') === 'true' ? 'selected' : '' }}> Wahr</option>
<option value="false" {{ ($correct_answer ?? '') === 'false' ? 'selected' : '' }}> Falsch</option>
</select>
</div>
{{-- Free text --}}
<div x-show="qtype === 'free_text'">
<label class="block text-sm font-medium text-slate-700 mb-1">Richtige Antwort (exakter Text, Groß-/Kleinschreibung egal)</label>
<input type="text" name="correct_answer" value="{{ $correct_answer ?? '' }}" placeholder="z.B. 72"
class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">
</div>
</div>
<button type="submit" class="w-full bg-violet-600 hover:bg-violet-700 text-white py-2 rounded-lg font-medium text-sm">Speichern</button>
</form>
</div>
</div>
@endsection