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:
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\{Quiz, QuizQuestion, QuizAnswerOption, Subject};
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class QuizController extends Controller {
|
||||||
|
|
||||||
|
public function index() {
|
||||||
|
$quizzes = Quiz::with('subject')->withCount('questions')->latest()->get();
|
||||||
|
return view('admin.quizzes.index', compact('quizzes'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create() {
|
||||||
|
$subjects = Subject::all();
|
||||||
|
return view('admin.quizzes.create', compact('subjects'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $r) {
|
||||||
|
$r->validate(['title'=>'required|string|max:120','subject_id'=>'required|exists:subjects,id','description'=>'nullable|string|max:500']);
|
||||||
|
$quiz = Quiz::create($r->only('title','subject_id','description') + ['active'=>true]);
|
||||||
|
return redirect()->route('admin.quizzes.edit', $quiz)->with('success','Quiz erstellt – jetzt Fragen hinzufügen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(Quiz $quiz) {
|
||||||
|
$subjects = Subject::all();
|
||||||
|
$questions = $quiz->questions()->with('answerOptions')->get();
|
||||||
|
return view('admin.quizzes.edit', compact('quiz','subjects','questions'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $r, Quiz $quiz) {
|
||||||
|
$r->validate(['title'=>'required|string|max:120','subject_id'=>'required|exists:subjects,id','description'=>'nullable|string|max:500']);
|
||||||
|
$quiz->update($r->only('title','subject_id','description') + ['active'=>$r->boolean('active')]);
|
||||||
|
return back()->with('success','Quiz gespeichert.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Quiz $quiz) {
|
||||||
|
$quiz->delete();
|
||||||
|
return redirect()->route('admin.quizzes.index')->with('success','Quiz gelöscht.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function export(Quiz $quiz) {
|
||||||
|
$quiz->load('subject','questions.answerOptions');
|
||||||
|
$data = [
|
||||||
|
'subject' => $quiz->subject->slug,
|
||||||
|
'title' => $quiz->title,
|
||||||
|
'description' => $quiz->description,
|
||||||
|
'questions' => $quiz->questions->map(fn($q) => [
|
||||||
|
'type' => $q->type,
|
||||||
|
'question_text' => $q->question_text,
|
||||||
|
'time_limit' => $q->time_limit,
|
||||||
|
'correct_answer' => $q->correct_answer,
|
||||||
|
'options' => $q->answerOptions->map(fn($o) => [
|
||||||
|
'text' => $o->text,
|
||||||
|
'is_correct' => (bool)$o->is_correct,
|
||||||
|
])->values(),
|
||||||
|
])->values(),
|
||||||
|
];
|
||||||
|
$filename = 'quiz-'.now()->format('Y-m-d').'-'.str($quiz->title)->slug().'.json';
|
||||||
|
return response()->streamDownload(
|
||||||
|
fn() => print(json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)),
|
||||||
|
$filename, ['Content-Type'=>'application/json']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function import(Request $r) {
|
||||||
|
$r->validate(['file'=>'required|file|mimes:json|max:4096']);
|
||||||
|
$raw = json_decode(file_get_contents($r->file('file')->getRealPath()), true);
|
||||||
|
if (!is_array($raw) || !isset($raw['title'],$raw['subject'],$raw['questions'])) {
|
||||||
|
return back()->with('error','Ungültiges JSON-Format. Felder: title, subject, questions erwartet.');
|
||||||
|
}
|
||||||
|
$subject = Subject::where('slug',$raw['subject'])->first();
|
||||||
|
if (!$subject) return back()->with('error','Unbekanntes Fach: '.$raw['subject']);
|
||||||
|
|
||||||
|
DB::transaction(function() use ($raw,$subject) {
|
||||||
|
$quiz = Quiz::create([
|
||||||
|
'subject_id' => $subject->id,
|
||||||
|
'title' => $raw['title'],
|
||||||
|
'description' => $raw['description'] ?? null,
|
||||||
|
'active' => true,
|
||||||
|
]);
|
||||||
|
foreach (array_slice($raw['questions'],0,10) as $i => $item) {
|
||||||
|
$q = QuizQuestion::create([
|
||||||
|
'quiz_id' => $quiz->id,
|
||||||
|
'sort_order' => $i,
|
||||||
|
'type' => $item['type'] ?? 'multiple_choice',
|
||||||
|
'question_text' => $item['question_text'],
|
||||||
|
'time_limit' => $item['time_limit'] ?? null,
|
||||||
|
'correct_answer' => $item['correct_answer'] ?? null,
|
||||||
|
]);
|
||||||
|
foreach (($item['options'] ?? []) as $j => $opt) {
|
||||||
|
QuizAnswerOption::create([
|
||||||
|
'quiz_question_id' => $q->id,
|
||||||
|
'text' => $opt['text'],
|
||||||
|
'is_correct' => $opt['is_correct'] ?? false,
|
||||||
|
'sort_order' => $j,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return redirect()->route('admin.quizzes.index')->with('success','Quiz "'.$raw['title'].'" importiert.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\{Quiz, QuizQuestion, QuizAnswerOption};
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class QuizQuestionController extends Controller {
|
||||||
|
|
||||||
|
public function create(Quiz $quiz) {
|
||||||
|
return view('admin.quiz_questions.create', compact('quiz'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $r, Quiz $quiz) {
|
||||||
|
$r->validate([
|
||||||
|
'type' => 'required|in:multiple_choice,exclusion,true_false,free_text',
|
||||||
|
'question_text' => 'required|string',
|
||||||
|
'time_limit' => 'nullable|integer|min:5|max:120',
|
||||||
|
'correct_answer' => 'nullable|string|max:200',
|
||||||
|
'correct_option' => 'nullable|integer|min:0|max:3',
|
||||||
|
'options' => 'array',
|
||||||
|
'options.*.text' => 'nullable|string|max:200',
|
||||||
|
]);
|
||||||
|
$q = QuizQuestion::create([
|
||||||
|
'quiz_id' => $quiz->id,
|
||||||
|
'sort_order' => ($quiz->questions()->max('sort_order') ?? -1) + 1,
|
||||||
|
'type' => $r->type,
|
||||||
|
'question_text' => $r->question_text,
|
||||||
|
'time_limit' => $r->time_limit ?: null,
|
||||||
|
'correct_answer' => $r->correct_answer,
|
||||||
|
]);
|
||||||
|
if (in_array($r->type,['multiple_choice','exclusion'])) {
|
||||||
|
$correctIdx = (int)$r->input('correct_option', 0);
|
||||||
|
foreach (($r->options ?? []) as $i => $opt) {
|
||||||
|
if (!empty($opt['text'])) {
|
||||||
|
QuizAnswerOption::create([
|
||||||
|
'quiz_question_id' => $q->id,
|
||||||
|
'text' => $opt['text'],
|
||||||
|
'is_correct' => $i === $correctIdx,
|
||||||
|
'sort_order' => $i,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return redirect()->route('admin.quizzes.edit', $quiz)->with('success','Frage hinzugefügt.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(QuizQuestion $question) {
|
||||||
|
return view('admin.quiz_questions.edit', compact('question'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $r, QuizQuestion $question) {
|
||||||
|
$r->validate([
|
||||||
|
'type' => 'required|in:multiple_choice,exclusion,true_false,free_text',
|
||||||
|
'question_text' => 'required|string',
|
||||||
|
'time_limit' => 'nullable|integer|min:5|max:120',
|
||||||
|
'correct_answer' => 'nullable|string|max:200',
|
||||||
|
'correct_option' => 'nullable|integer|min:0|max:3',
|
||||||
|
'options' => 'array',
|
||||||
|
'options.*.text' => 'nullable|string|max:200',
|
||||||
|
]);
|
||||||
|
$question->update([
|
||||||
|
'type' => $r->type,
|
||||||
|
'question_text' => $r->question_text,
|
||||||
|
'time_limit' => $r->time_limit ?: null,
|
||||||
|
'correct_answer' => $r->correct_answer,
|
||||||
|
]);
|
||||||
|
if (in_array($r->type,['multiple_choice','exclusion'])) {
|
||||||
|
$question->answerOptions()->delete();
|
||||||
|
$correctIdx = (int)$r->input('correct_option', 0);
|
||||||
|
foreach (($r->options ?? []) as $i => $opt) {
|
||||||
|
if (!empty($opt['text'])) {
|
||||||
|
QuizAnswerOption::create([
|
||||||
|
'quiz_question_id' => $question->id,
|
||||||
|
'text' => $opt['text'],
|
||||||
|
'is_correct' => $i === $correctIdx,
|
||||||
|
'sort_order' => $i,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return redirect()->route('admin.quizzes.edit', $question->quiz)->with('success','Frage gespeichert.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(QuizQuestion $question) {
|
||||||
|
$quiz = $question->quiz;
|
||||||
|
$question->delete();
|
||||||
|
return redirect()->route('admin.quizzes.edit', $quiz)->with('success','Frage gelöscht.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Http\Controllers\Child;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\{Quiz, QuizAttempt, QuizAttemptAnswer, QuizQuestion, Subject};
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class QuizController extends Controller {
|
||||||
|
|
||||||
|
public function index() {
|
||||||
|
$subjects = Subject::all()->keyBy('id');
|
||||||
|
$quizzes = Quiz::with('subject')->where('active',true)
|
||||||
|
->withCount('questions')->get()->groupBy('subject_id');
|
||||||
|
$bestScores = QuizAttempt::where('user_id',auth()->id())
|
||||||
|
->where('status','completed')
|
||||||
|
->selectRaw('quiz_id, MAX(score) as best')
|
||||||
|
->groupBy('quiz_id')->pluck('best','quiz_id');
|
||||||
|
return view('child.quiz.index', compact('subjects','quizzes','bestScores'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function start(Quiz $quiz) {
|
||||||
|
abort_unless($quiz->active, 403);
|
||||||
|
$attempt = QuizAttempt::firstOrCreate(
|
||||||
|
['user_id'=>auth()->id(),'quiz_id'=>$quiz->id,'status'=>'in_progress'],
|
||||||
|
['score'=>0,'current_question'=>0,'started_at'=>now()]
|
||||||
|
);
|
||||||
|
return redirect()->route('quiz.question', $attempt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function question(QuizAttempt $attempt) {
|
||||||
|
abort_unless($attempt->user_id === auth()->id(), 403);
|
||||||
|
if ($attempt->status === 'completed') return redirect()->route('quiz.result', $attempt);
|
||||||
|
$question = $attempt->quiz->questions()->skip($attempt->current_question)->first();
|
||||||
|
$pointsIfCorrect = QuizAttempt::POINTS[$attempt->current_question];
|
||||||
|
return view('child.quiz.question', compact('attempt','question','pointsIfCorrect'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function answer(Request $r, QuizAttempt $attempt) {
|
||||||
|
abort_unless($attempt->user_id === auth()->id(), 403);
|
||||||
|
abort_if($attempt->status === 'completed', 400);
|
||||||
|
|
||||||
|
$question = $attempt->quiz->questions()->skip($attempt->current_question)->first();
|
||||||
|
$possible = QuizAttempt::POINTS[$attempt->current_question];
|
||||||
|
$timedOut = $r->input('timeout') === '1';
|
||||||
|
$answerGiven = $r->input('answer','');
|
||||||
|
$isCorrect = false;
|
||||||
|
$pointsEarned = 0;
|
||||||
|
|
||||||
|
if (!$timedOut && $answerGiven !== '') {
|
||||||
|
$isCorrect = $this->check($question, $answerGiven);
|
||||||
|
$pointsEarned = $isCorrect ? $possible : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuizAttemptAnswer::create([
|
||||||
|
'quiz_attempt_id' => $attempt->id,
|
||||||
|
'quiz_question_id' => $question->id,
|
||||||
|
'answer_given' => $timedOut ? '__timeout__' : $answerGiven,
|
||||||
|
'is_correct' => $isCorrect,
|
||||||
|
'points_earned' => $pointsEarned,
|
||||||
|
]);
|
||||||
|
|
||||||
|
session()->flash('last_answer', [
|
||||||
|
'correct' => $isCorrect,
|
||||||
|
'points' => $pointsEarned,
|
||||||
|
'possible' => $possible,
|
||||||
|
'timeout' => $timedOut,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$next = $attempt->current_question + 1;
|
||||||
|
$totalQuestions = $attempt->quiz->questions()->count();
|
||||||
|
|
||||||
|
if ($next >= $totalQuestions || $next >= 10) {
|
||||||
|
$total = QuizAttemptAnswer::where('quiz_attempt_id',$attempt->id)->sum('points_earned');
|
||||||
|
$attempt->update(['score'=>$total,'current_question'=>$next,'status'=>'completed','completed_at'=>now()]);
|
||||||
|
auth()->user()->increment('points', $total);
|
||||||
|
return redirect()->route('quiz.result', $attempt);
|
||||||
|
}
|
||||||
|
$attempt->update(['current_question'=>$next]);
|
||||||
|
return redirect()->route('quiz.question', $attempt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function result(QuizAttempt $attempt) {
|
||||||
|
abort_unless($attempt->user_id === auth()->id(), 403);
|
||||||
|
abort_unless($attempt->status === 'completed', 400);
|
||||||
|
$answers = $attempt->answers()->with('question.answerOptions')->get();
|
||||||
|
return view('child.quiz.result', compact('attempt','answers'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function check(QuizQuestion $q, string $answer): bool {
|
||||||
|
return match($q->type) {
|
||||||
|
'multiple_choice','exclusion' => ($opt = $q->answerOptions()->where('is_correct',true)->first())
|
||||||
|
&& (string)$opt->id === $answer,
|
||||||
|
'true_false','free_text' => strtolower(trim($answer)) === strtolower(trim((string)$q->correct_answer)),
|
||||||
|
default => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
class Quiz extends Model {
|
||||||
|
protected $fillable = ['subject_id','title','description','active'];
|
||||||
|
protected $casts = ['active' => 'boolean'];
|
||||||
|
public function subject() { return $this->belongsTo(Subject::class); }
|
||||||
|
public function questions() { return $this->hasMany(QuizQuestion::class)->orderBy('sort_order'); }
|
||||||
|
public function attempts() { return $this->hasMany(QuizAttempt::class); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
class QuizAnswerOption extends Model {
|
||||||
|
public $timestamps = false;
|
||||||
|
protected $fillable = ['quiz_question_id','text','is_correct','sort_order'];
|
||||||
|
public function question() { return $this->belongsTo(QuizQuestion::class,'quiz_question_id'); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
class QuizAttempt extends Model {
|
||||||
|
protected $fillable = ['user_id','quiz_id','score','current_question','status','started_at','completed_at'];
|
||||||
|
protected $casts = ['started_at' => 'datetime', 'completed_at' => 'datetime'];
|
||||||
|
public const POINTS = [1, 1, 2, 2, 3, 3, 4, 6, 8, 10];
|
||||||
|
public function user() { return $this->belongsTo(User::class); }
|
||||||
|
public function quiz() { return $this->belongsTo(Quiz::class); }
|
||||||
|
public function answers() { return $this->hasMany(QuizAttemptAnswer::class); }
|
||||||
|
public function stars(): string {
|
||||||
|
$s = $this->score;
|
||||||
|
if ($s >= 40) return '🌟🌟🌟🌟🌟';
|
||||||
|
if ($s >= 30) return '⭐⭐⭐⭐';
|
||||||
|
if ($s >= 20) return '⭐⭐⭐';
|
||||||
|
if ($s >= 10) return '⭐⭐';
|
||||||
|
if ($s >= 1) return '⭐';
|
||||||
|
return '—';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
class QuizAttemptAnswer extends Model {
|
||||||
|
protected $fillable = ['quiz_attempt_id','quiz_question_id','answer_given','is_correct','points_earned'];
|
||||||
|
public function attempt() { return $this->belongsTo(QuizAttempt::class,'quiz_attempt_id'); }
|
||||||
|
public function question() { return $this->belongsTo(QuizQuestion::class,'quiz_question_id'); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
class QuizQuestion extends Model {
|
||||||
|
protected $fillable = ['quiz_id','sort_order','type','question_text','time_limit','correct_answer'];
|
||||||
|
public function quiz() { return $this->belongsTo(Quiz::class); }
|
||||||
|
public function answerOptions() { return $this->hasMany(QuizAnswerOption::class,'quiz_question_id')->orderBy('sort_order'); }
|
||||||
|
public function typeLabel(): string {
|
||||||
|
return match($this->type) {
|
||||||
|
'multiple_choice' => 'Multiple Choice',
|
||||||
|
'exclusion' => 'Ausschluss',
|
||||||
|
'true_false' => 'Wahr/Falsch',
|
||||||
|
'free_text' => 'Freitext',
|
||||||
|
default => $this->type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void {
|
||||||
|
Schema::create('quizzes', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('subject_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('title');
|
||||||
|
$table->text('description')->nullable();
|
||||||
|
$table->boolean('active')->default(true);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
Schema::create('quiz_questions', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('quiz_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->unsignedSmallInteger('sort_order')->default(0);
|
||||||
|
$table->enum('type', ['multiple_choice','exclusion','true_false','free_text']);
|
||||||
|
$table->text('question_text');
|
||||||
|
$table->unsignedSmallInteger('time_limit')->nullable();
|
||||||
|
$table->string('correct_answer')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
Schema::create('quiz_answer_options', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('quiz_question_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('text');
|
||||||
|
$table->boolean('is_correct')->default(false);
|
||||||
|
$table->unsignedSmallInteger('sort_order')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public function down(): void {
|
||||||
|
Schema::dropIfExists('quiz_answer_options');
|
||||||
|
Schema::dropIfExists('quiz_questions');
|
||||||
|
Schema::dropIfExists('quizzes');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void {
|
||||||
|
Schema::create('quiz_attempts', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('quiz_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->unsignedSmallInteger('score')->default(0);
|
||||||
|
$table->unsignedSmallInteger('current_question')->default(0);
|
||||||
|
$table->enum('status', ['in_progress','completed'])->default('in_progress');
|
||||||
|
$table->timestamp('started_at')->nullable();
|
||||||
|
$table->timestamp('completed_at')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
Schema::create('quiz_attempt_answers', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('quiz_attempt_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('quiz_question_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('answer_given')->nullable();
|
||||||
|
$table->boolean('is_correct')->default(false);
|
||||||
|
$table->unsignedSmallInteger('points_earned')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public function down(): void {
|
||||||
|
Schema::dropIfExists('quiz_attempt_answers');
|
||||||
|
Schema::dropIfExists('quiz_attempts');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
@extends('layouts.admin')
|
||||||
|
@section('title','Neues Quiz')
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-xl">
|
||||||
|
<a href="{{ route('admin.quizzes.index') }}" class="text-sm text-slate-500 hover:text-slate-700 mb-4 inline-block">← Zurück</a>
|
||||||
|
<div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
|
||||||
|
<h2 class="font-semibold text-slate-800 mb-5">Neues Quiz</h2>
|
||||||
|
<form method="POST" action="{{ route('admin.quizzes.store') }}" class="space-y-4">
|
||||||
|
@csrf
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700 mb-1">Fach</label>
|
||||||
|
<select name="subject_id" 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">
|
||||||
|
@foreach($subjects as $s)<option value="{{ $s->id }}">{{ $s->icon }} {{ $s->name }}</option>@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700 mb-1">Titel</label>
|
||||||
|
<input name="title" required value="{{ old('title') }}" 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>
|
||||||
|
<label class="block text-sm font-medium text-slate-700 mb-1">Beschreibung (optional)</label>
|
||||||
|
<textarea name="description" rows="2" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">{{ old('description') }}</textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="w-full bg-violet-600 hover:bg-violet-700 text-white py-2 rounded-lg font-medium text-sm">Erstellen & Fragen hinzufügen →</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
@extends('layouts.admin')
|
||||||
|
@section('title','Quiz bearbeiten')
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-3xl">
|
||||||
|
<a href="{{ route('admin.quizzes.index') }}" class="text-sm text-slate-500 hover:text-slate-700 mb-4 inline-block">← Zurück</a>
|
||||||
|
|
||||||
|
{{-- Metadata --}}
|
||||||
|
<div class="bg-white rounded-xl shadow-sm border border-slate-200 p-6 mb-6">
|
||||||
|
<h2 class="font-semibold text-slate-800 mb-5">Quiz-Einstellungen</h2>
|
||||||
|
<form method="POST" action="{{ route('admin.quizzes.update',$quiz) }}" class="space-y-4">
|
||||||
|
@csrf @method('PUT')
|
||||||
|
<div class="grid grid-cols-3 gap-4">
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700 mb-1">Fach</label>
|
||||||
|
<select name="subject_id" 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">
|
||||||
|
@foreach($subjects as $s)<option value="{{ $s->id }}" {{ $s->id==$quiz->subject_id?'selected':'' }}>{{ $s->icon }} {{ $s->name }}</option>@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-span-2">
|
||||||
|
<label class="block text-sm font-medium text-slate-700 mb-1">Titel</label>
|
||||||
|
<input name="title" required value="{{ $quiz->title }}" 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>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700 mb-1">Beschreibung</label>
|
||||||
|
<textarea name="description" rows="2" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-violet-500 outline-none">{{ $quiz->description }}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<input type="checkbox" name="active" id="active" value="1" {{ $quiz->active?'checked':'' }} class="w-4 h-4 text-violet-600">
|
||||||
|
<label for="active" class="text-sm text-slate-700">Quiz aktiv (für Kinder sichtbar)</label>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="bg-violet-600 hover:bg-violet-700 text-white px-6 py-2 rounded-lg font-medium text-sm">Speichern</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Questions --}}
|
||||||
|
<div class="flex justify-between items-center mb-3">
|
||||||
|
<h3 class="font-semibold text-slate-700">Fragen
|
||||||
|
<span class="{{ $questions->count() < 10 ? 'text-amber-500' : 'text-green-600' }} font-normal text-sm ml-1">({{ $questions->count() }}/10)</span>
|
||||||
|
</h3>
|
||||||
|
@if($questions->count() < 10)
|
||||||
|
<a href="{{ route('admin.quizzes.questions.create',$quiz) }}" class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg text-sm font-medium">+ Frage hinzufügen</a>
|
||||||
|
@else
|
||||||
|
<span class="text-green-600 text-sm font-medium">✅ 10 Fragen vollständig</span>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@forelse($questions as $i => $q)
|
||||||
|
<div class="bg-white rounded-xl border border-slate-200 px-4 py-3 mb-2 flex items-start justify-between gap-4 hover:bg-slate-50">
|
||||||
|
<div class="flex items-start gap-3 flex-1 min-w-0">
|
||||||
|
<span class="text-slate-400 text-sm pt-0.5 shrink-0">{{ $i+1 }}.</span>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<span class="text-xs bg-slate-100 text-slate-500 px-2 py-0.5 rounded mr-2">{{ $q->typeLabel() }}</span>
|
||||||
|
@if($q->time_limit)<span class="text-xs text-amber-600 mr-2">⏱ {{ $q->time_limit }}s</span>@endif
|
||||||
|
<p class="text-sm text-slate-700 mt-1 line-clamp-2">{{ $q->question_text }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-3 text-sm shrink-0">
|
||||||
|
<a href="{{ route('admin.quiz-questions.edit',$q) }}" class="text-violet-600 hover:underline">Bearbeiten</a>
|
||||||
|
<form method="POST" action="{{ route('admin.quiz-questions.destroy',$q) }}" class="inline" onsubmit="return confirm('Frage löschen?')">
|
||||||
|
@csrf @method('DELETE')
|
||||||
|
<button class="text-red-500 hover:underline">Löschen</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<div class="bg-slate-50 rounded-xl border border-dashed border-slate-300 p-8 text-center text-slate-400 text-sm">
|
||||||
|
Noch keine Fragen. Füge bis zu 10 Fragen hinzu.
|
||||||
|
</div>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
@extends('layouts.admin')
|
||||||
|
@section('title','Quizzes')
|
||||||
|
@section('content')
|
||||||
|
<div class="flex justify-between items-center mb-6" x-data="{showImport:false}">
|
||||||
|
<h2 class="text-lg font-semibold text-slate-700">Quizzes</h2>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<button @click="showImport=!showImport"
|
||||||
|
class="flex items-center gap-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 px-3 py-2 rounded-lg text-sm font-medium"
|
||||||
|
:class="showImport && 'bg-amber-100 text-amber-700'">⬆ Import</button>
|
||||||
|
<a href="{{ route('admin.quizzes.create') }}" class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg text-sm font-medium">+ Neues Quiz</a>
|
||||||
|
</div>
|
||||||
|
<div x-show="showImport" x-cloak class="w-full mt-3">
|
||||||
|
<div class="bg-amber-50 border border-amber-200 rounded-xl p-4">
|
||||||
|
<p class="text-xs text-slate-500 mb-3">JSON im gleichen Format wie der Export. Erstellt immer ein neues Quiz.</p>
|
||||||
|
<form method="POST" action="{{ route('admin.quizzes.import') }}" enctype="multipart/form-data" class="flex gap-3">
|
||||||
|
@csrf
|
||||||
|
<input type="file" name="file" accept=".json" required
|
||||||
|
class="flex-1 text-sm text-slate-600 file:mr-3 file:py-1.5 file:px-3 file:rounded-lg file:border-0 file:text-sm file:font-medium file:bg-violet-100 file:text-violet-700">
|
||||||
|
<button type="submit" class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg text-sm font-medium whitespace-nowrap">Importieren</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
|
||||||
|
<table class="w-full text-sm">
|
||||||
|
<thead class="bg-slate-50 border-b border-slate-200">
|
||||||
|
<tr>
|
||||||
|
<th class="text-left px-4 py-3 font-medium text-slate-600">Fach</th>
|
||||||
|
<th class="text-left px-4 py-3 font-medium text-slate-600">Titel</th>
|
||||||
|
<th class="text-center px-4 py-3 font-medium text-slate-600">Fragen</th>
|
||||||
|
<th class="text-center px-4 py-3 font-medium text-slate-600">Status</th>
|
||||||
|
<th class="px-4 py-3"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-slate-100">
|
||||||
|
@forelse($quizzes as $quiz)
|
||||||
|
<tr class="hover:bg-slate-50">
|
||||||
|
<td class="px-4 py-3 text-slate-600">{{ $quiz->subject->icon }} {{ $quiz->subject->name }}</td>
|
||||||
|
<td class="px-4 py-3 font-medium text-slate-800">{{ $quiz->title }}</td>
|
||||||
|
<td class="px-4 py-3 text-center">
|
||||||
|
<span class="{{ $quiz->questions_count < 10 ? 'text-amber-600' : 'text-green-600' }} font-medium">
|
||||||
|
{{ $quiz->questions_count }}/10
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3 text-center">{{ $quiz->active ? '✅' : '⏸️' }}</td>
|
||||||
|
<td class="px-4 py-3 text-right whitespace-nowrap">
|
||||||
|
<a href="{{ route('admin.quizzes.export',$quiz) }}" class="text-slate-500 hover:text-slate-700 mr-3 text-xs">⬇ Export</a>
|
||||||
|
<a href="{{ route('admin.quizzes.edit',$quiz) }}" class="text-violet-600 hover:underline mr-3">Bearbeiten</a>
|
||||||
|
<form method="POST" action="{{ route('admin.quizzes.destroy',$quiz) }}" class="inline" onsubmit="return confirm('Quiz löschen?')">
|
||||||
|
@csrf @method('DELETE')
|
||||||
|
<button class="text-red-500 hover:underline">Löschen</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
<tr><td colspan="5" class="px-4 py-10 text-center text-slate-400">Noch keine Quizzes. <a href="{{ route('admin.quizzes.create') }}" class="text-violet-600 hover:underline">Erstes Quiz erstellen →</a></td></tr>
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
@extends('layouts.child')
|
||||||
|
@section('content')
|
||||||
|
<h1 class="text-2xl font-bold text-indigo-700 mb-2">🧠 Quiz</h1>
|
||||||
|
<p class="text-slate-500 mb-6">Beantworte 10 Fragen – max. 40 Münzen zu gewinnen!</p>
|
||||||
|
|
||||||
|
@foreach($subjects as $subjectId => $subject)
|
||||||
|
@php $group = $quizzes->get($subjectId, collect()) @endphp
|
||||||
|
@if($group->isNotEmpty())
|
||||||
|
<div class="mb-6">
|
||||||
|
<h2 class="font-bold text-slate-600 text-sm uppercase tracking-wide mb-3">{{ $subject->icon }} {{ $subject->name }}</h2>
|
||||||
|
<div class="grid gap-3">
|
||||||
|
@foreach($group as $quiz)
|
||||||
|
<div class="bg-white rounded-2xl border border-slate-200 shadow-sm px-5 py-4">
|
||||||
|
<div class="flex items-start justify-between gap-4">
|
||||||
|
<div class="flex-1 min-w-0">
|
||||||
|
<h3 class="font-bold text-slate-800 text-base">{{ $quiz->title }}</h3>
|
||||||
|
@if($quiz->description)<p class="text-sm text-slate-500 mt-0.5">{{ $quiz->description }}</p>@endif
|
||||||
|
<div class="flex items-center gap-3 mt-2 text-xs text-slate-400">
|
||||||
|
<span>📝 {{ $quiz->questions_count }} Fragen</span>
|
||||||
|
<span>🏆 max. 40 Münzen</span>
|
||||||
|
@if(isset($bestScores[$quiz->id]))
|
||||||
|
<span class="text-amber-600 font-medium">Bisher: {{ $bestScores[$quiz->id] }}/40 🪙</span>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form method="POST" action="{{ route('quiz.start',$quiz) }}">
|
||||||
|
@csrf
|
||||||
|
<button class="bg-indigo-600 hover:bg-indigo-700 text-white px-5 py-2.5 rounded-xl text-sm font-bold whitespace-nowrap">
|
||||||
|
{{ isset($bestScores[$quiz->id]) ? 'Nochmal' : 'Starten' }} →
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
@if($quizzes->isEmpty())
|
||||||
|
<div class="text-center py-16 text-slate-400">
|
||||||
|
<p class="text-4xl mb-3">🧩</p>
|
||||||
|
<p>Noch keine Quizzes verfügbar. Schau später nochmal vorbei!</p>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
@extends('layouts.child')
|
||||||
|
@section('content')
|
||||||
|
@php $tl = $question->time_limit ?? 0; @endphp
|
||||||
|
<div x-data="{
|
||||||
|
tl: {{ $tl }},
|
||||||
|
left: {{ $tl }},
|
||||||
|
timedOut: false,
|
||||||
|
timer: null,
|
||||||
|
init() {
|
||||||
|
if (this.tl > 0) {
|
||||||
|
this.timer = setInterval(() => {
|
||||||
|
this.left--;
|
||||||
|
if (this.left <= 0) {
|
||||||
|
clearInterval(this.timer);
|
||||||
|
this.timedOut = true;
|
||||||
|
this.$nextTick(() => {
|
||||||
|
document.querySelectorAll('[required]').forEach(e => e.removeAttribute('required'));
|
||||||
|
document.getElementById('timeout-input').value = '1';
|
||||||
|
document.getElementById('answer-form').submit();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}">
|
||||||
|
|
||||||
|
{{-- Header bar --}}
|
||||||
|
<div class="flex items-center gap-3 mb-4">
|
||||||
|
<a href="{{ route('quiz.index') }}" class="text-slate-400 hover:text-slate-600 text-sm">← Quiz</a>
|
||||||
|
<div class="flex-1 bg-slate-200 rounded-full h-2.5">
|
||||||
|
<div class="bg-violet-500 h-2.5 rounded-full transition-all duration-300"
|
||||||
|
style="width: {{ ($attempt->current_question / max($attempt->quiz->questions()->count(),1)) * 100 }}%"></div>
|
||||||
|
</div>
|
||||||
|
<span class="text-sm font-semibold text-slate-600 whitespace-nowrap">
|
||||||
|
{{ $attempt->current_question + 1 }} / {{ $attempt->quiz->questions()->count() }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Timer bar --}}
|
||||||
|
<template x-if="tl > 0">
|
||||||
|
<div class="mb-4">
|
||||||
|
<div class="bg-slate-200 rounded-full h-2">
|
||||||
|
<div class="h-2 rounded-full transition-all duration-1000"
|
||||||
|
:class="left > tl*0.5 ? 'bg-green-500' : (left > tl*0.25 ? 'bg-yellow-500' : 'bg-red-500')"
|
||||||
|
:style="'width:' + Math.max(0,(left/tl)*100) + '%'"></div>
|
||||||
|
</div>
|
||||||
|
<div class="text-right text-xs mt-1" :class="left <= 5 ? 'text-red-500 font-bold' : 'text-slate-400'">
|
||||||
|
<span x-text="left"></span>s
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
{{-- Last answer flash --}}
|
||||||
|
@if(session('last_answer'))
|
||||||
|
@php $la = session('last_answer'); @endphp
|
||||||
|
<div class="mb-4 rounded-xl px-4 py-3 text-sm font-medium flex items-center gap-2
|
||||||
|
{{ $la['timeout'] ? 'bg-slate-100 text-slate-600' : ($la['correct'] ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-700') }}">
|
||||||
|
@if($la['timeout']) ⏱ Zeit abgelaufen – 0 Münzen
|
||||||
|
@elseif($la['correct']) ✅ Richtig! +{{ $la['points'] }} 🪙
|
||||||
|
@else ❌ Leider falsch – 0 Münzen
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
{{-- Points badge --}}
|
||||||
|
<div class="text-center mb-5">
|
||||||
|
<span class="bg-amber-100 text-amber-700 text-sm font-bold px-4 py-1.5 rounded-full">
|
||||||
|
+{{ $pointsIfCorrect }} 🪙 bei richtiger Antwort
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Question card --}}
|
||||||
|
<div class="bg-white rounded-2xl shadow-sm border border-slate-200 p-6">
|
||||||
|
<h2 class="text-xl font-black text-slate-800 mb-6 leading-snug">{{ $question->question_text }}</h2>
|
||||||
|
|
||||||
|
<form method="POST" action="{{ route('quiz.answer',$attempt) }}" id="answer-form">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="timeout" value="0" id="timeout-input">
|
||||||
|
|
||||||
|
@if(in_array($question->type, ['multiple_choice','exclusion']))
|
||||||
|
<div class="grid grid-cols-2 gap-3 mb-6">
|
||||||
|
@foreach($question->answerOptions as $opt)
|
||||||
|
<label class="flex items-center gap-3 p-4 border-2 border-slate-200 rounded-xl cursor-pointer
|
||||||
|
hover:border-violet-300 hover:bg-violet-50 has-[:checked]:border-violet-500 has-[:checked]:bg-violet-50
|
||||||
|
transition-colors">
|
||||||
|
<input type="radio" name="answer" value="{{ $opt->id }}" required class="w-4 h-4 text-violet-600 shrink-0">
|
||||||
|
<span class="text-slate-700 font-medium text-sm">{{ $opt->text }}</span>
|
||||||
|
</label>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@elseif($question->type === 'true_false')
|
||||||
|
<div class="grid grid-cols-2 gap-4 mb-6">
|
||||||
|
<label class="flex items-center justify-center gap-3 p-5 border-2 border-slate-200 rounded-xl cursor-pointer
|
||||||
|
hover:border-green-400 hover:bg-green-50 has-[:checked]:border-green-500 has-[:checked]:bg-green-50
|
||||||
|
transition-colors">
|
||||||
|
<input type="radio" name="answer" value="true" required class="sr-only">
|
||||||
|
<span class="text-2xl">✅</span>
|
||||||
|
<span class="font-bold text-slate-700">Wahr</span>
|
||||||
|
</label>
|
||||||
|
<label class="flex items-center justify-center gap-3 p-5 border-2 border-slate-200 rounded-xl cursor-pointer
|
||||||
|
hover:border-red-400 hover:bg-red-50 has-[:checked]:border-red-500 has-[:checked]:bg-red-50
|
||||||
|
transition-colors">
|
||||||
|
<input type="radio" name="answer" value="false" required class="sr-only">
|
||||||
|
<span class="text-2xl">❌</span>
|
||||||
|
<span class="font-bold text-slate-700">Falsch</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@elseif($question->type === 'free_text')
|
||||||
|
<div class="mb-6">
|
||||||
|
<input type="text" name="answer" required autofocus placeholder="Deine Antwort eingeben …"
|
||||||
|
class="w-full border-2 border-slate-200 focus:border-violet-500 rounded-xl px-4 py-3 text-lg font-bold text-slate-800 outline-none text-center transition-colors">
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<button type="submit" class="w-full bg-violet-600 hover:bg-violet-700 text-white py-3 rounded-xl font-bold text-base">
|
||||||
|
Antworten →
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
@extends('layouts.child')
|
||||||
|
@section('content')
|
||||||
|
<div class="text-center mb-8">
|
||||||
|
<div class="text-6xl mb-3">{{ $attempt->stars() }}</div>
|
||||||
|
<h1 class="text-3xl font-black text-slate-800">{{ $attempt->score }} / 40 Münzen</h1>
|
||||||
|
<p class="text-slate-500 mt-1">{{ $attempt->quiz->title }}</p>
|
||||||
|
<div class="mt-3 inline-flex items-center gap-2 bg-amber-100 text-amber-700 font-bold px-5 py-2 rounded-full text-lg">
|
||||||
|
+{{ $attempt->score }} 🪙 verdient!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Per-question breakdown --}}
|
||||||
|
<div class="bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden mb-6">
|
||||||
|
<table class="w-full text-sm">
|
||||||
|
<thead class="bg-slate-50 border-b border-slate-100">
|
||||||
|
<tr>
|
||||||
|
<th class="px-4 py-3 text-left font-medium text-slate-500">#</th>
|
||||||
|
<th class="px-4 py-3 text-left font-medium text-slate-500">Frage</th>
|
||||||
|
<th class="px-4 py-3 text-center font-medium text-slate-500">Ergebnis</th>
|
||||||
|
<th class="px-4 py-3 text-center font-medium text-slate-500">Münzen</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-slate-100">
|
||||||
|
@foreach($answers as $i => $a)
|
||||||
|
@php
|
||||||
|
$display = $a->answer_given;
|
||||||
|
if ($display === '__timeout__') {
|
||||||
|
$display = '⏱ Zeit abgelaufen';
|
||||||
|
} elseif (in_array($a->question->type, ['multiple_choice','exclusion'])) {
|
||||||
|
$opt = $a->question->answerOptions->firstWhere('id', (int)$a->answer_given);
|
||||||
|
$display = $opt ? $opt->text : '–';
|
||||||
|
} elseif ($a->question->type === 'true_false') {
|
||||||
|
$display = $display === 'true' ? 'Wahr' : 'Falsch';
|
||||||
|
}
|
||||||
|
$points_scale = \App\Models\QuizAttempt::POINTS;
|
||||||
|
@endphp
|
||||||
|
<tr class="{{ $a->is_correct ? 'bg-green-50' : '' }}">
|
||||||
|
<td class="px-4 py-3 text-slate-400 font-medium">{{ $i+1 }}</td>
|
||||||
|
<td class="px-4 py-3 text-slate-700">{{ Str::limit($a->question->question_text, 55) }}</td>
|
||||||
|
<td class="px-4 py-3 text-center">
|
||||||
|
@if($a->is_correct)
|
||||||
|
<span class="text-green-700 font-medium">✅ {{ $display }}</span>
|
||||||
|
@else
|
||||||
|
<span class="text-red-600">❌ {{ $display }}</span>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3 text-center font-bold {{ $a->is_correct ? 'text-amber-600' : 'text-slate-300' }}">
|
||||||
|
{{ $a->is_correct ? '+' . $a->points_earned : '0' }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<form method="POST" action="{{ route('quiz.start',$attempt->quiz) }}" class="flex-1">
|
||||||
|
@csrf
|
||||||
|
<button class="w-full bg-slate-100 hover:bg-slate-200 text-slate-700 py-3 rounded-xl font-medium">🔁 Nochmal spielen</button>
|
||||||
|
</form>
|
||||||
|
<a href="{{ route('quiz.index') }}" class="flex-1 bg-indigo-600 hover:bg-indigo-700 text-white py-3 rounded-xl font-bold text-center">← Zur Quiz-Übersicht</a>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
@@ -23,6 +23,9 @@
|
|||||||
<a href="{{ route('admin.questions.index') }}" class="flex items-center gap-3 px-3 py-2 rounded-lg {{ request()->routeIs('admin.questions.*') ? 'bg-violet-600 text-white' : 'text-slate-300 hover:bg-slate-800' }}">
|
<a href="{{ route('admin.questions.index') }}" class="flex items-center gap-3 px-3 py-2 rounded-lg {{ request()->routeIs('admin.questions.*') ? 'bg-violet-600 text-white' : 'text-slate-300 hover:bg-slate-800' }}">
|
||||||
<span>❓</span> Fragen
|
<span>❓</span> Fragen
|
||||||
</a>
|
</a>
|
||||||
|
<a href="{{ route('admin.quizzes.index') }}" class="flex items-center gap-3 px-3 py-2 rounded-lg {{ request()->routeIs('admin.quizzes.*','admin.quiz-questions.*') ? 'bg-violet-600 text-white' : 'text-slate-300 hover:bg-slate-800' }}">
|
||||||
|
<span>🧠</span> Quizzes
|
||||||
|
</a>
|
||||||
<a href="{{ route('admin.rewards.index') }}" class="flex items-center gap-3 px-3 py-2 rounded-lg {{ request()->routeIs('admin.rewards.*') ? 'bg-violet-600 text-white' : 'text-slate-300 hover:bg-slate-800' }}">
|
<a href="{{ route('admin.rewards.index') }}" class="flex items-center gap-3 px-3 py-2 rounded-lg {{ request()->routeIs('admin.rewards.*') ? 'bg-violet-600 text-white' : 'text-slate-300 hover:bg-slate-800' }}">
|
||||||
<span>🎁</span> Belohnungen
|
<span>🎁</span> Belohnungen
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
</a>
|
</a>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex items-center gap-4">
|
||||||
<a href="{{ route('learn.subjects') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">Lernen</a>
|
<a href="{{ route('learn.subjects') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">Lernen</a>
|
||||||
|
<a href="{{ route('quiz.index') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">🧠 Quiz</a>
|
||||||
<a href="{{ route('rewards.index') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">🪙 Belohnungen</a>
|
<a href="{{ route('rewards.index') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">🪙 Belohnungen</a>
|
||||||
<a href="{{ route('reference.index') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">💡 Erinnerung</a>
|
<a href="{{ route('reference.index') }}" class="text-sm font-medium text-slate-600 hover:text-indigo-600">💡 Erinnerung</a>
|
||||||
<div class="flex items-center gap-1 bg-amber-100 text-amber-700 font-bold rounded-full px-3 py-1 text-sm">
|
<div class="flex items-center gap-1 bg-amber-100 text-amber-700 font-bold rounded-full px-3 py-1 text-sm">
|
||||||
|
|||||||
@@ -22,6 +22,14 @@ Route::middleware(['auth','admin'])->prefix('admin')->name('admin.')->group(func
|
|||||||
Route::resource('questions',Admin\QuestionController::class);
|
Route::resource('questions',Admin\QuestionController::class);
|
||||||
Route::resource('rewards', Admin\RewardController::class)->except('show');
|
Route::resource('rewards', Admin\RewardController::class)->except('show');
|
||||||
Route::resource('reference', Admin\ReferenceController::class)->except('show');
|
Route::resource('reference', Admin\ReferenceController::class)->except('show');
|
||||||
|
Route::get ('quizzes/{quiz}/export', [Admin\QuizController::class,'export'])->name('quizzes.export');
|
||||||
|
Route::post('quizzes/import', [Admin\QuizController::class,'import'])->name('quizzes.import');
|
||||||
|
Route::resource('quizzes', Admin\QuizController::class);
|
||||||
|
Route::get ('quizzes/{quiz}/questions/create',[Admin\QuizQuestionController::class,'create'])->name('quizzes.questions.create');
|
||||||
|
Route::post('quizzes/{quiz}/questions', [Admin\QuizQuestionController::class,'store']) ->name('quizzes.questions.store');
|
||||||
|
Route::get ('quiz-questions/{question}/edit', [Admin\QuizQuestionController::class,'edit']) ->name('quiz-questions.edit');
|
||||||
|
Route::put ('quiz-questions/{question}', [Admin\QuizQuestionController::class,'update']) ->name('quiz-questions.update');
|
||||||
|
Route::delete('quiz-questions/{question}', [Admin\QuizQuestionController::class,'destroy'])->name('quiz-questions.destroy');
|
||||||
Route::get ('redemptions', [Admin\RedemptionController::class,'index']) ->name('redemptions.index');
|
Route::get ('redemptions', [Admin\RedemptionController::class,'index']) ->name('redemptions.index');
|
||||||
Route::patch ('redemptions/{redemption}/approve', [Admin\RedemptionController::class,'approve'])->name('redemptions.approve');
|
Route::patch ('redemptions/{redemption}/approve', [Admin\RedemptionController::class,'approve'])->name('redemptions.approve');
|
||||||
Route::patch ('redemptions/{redemption}/reject', [Admin\RedemptionController::class,'reject']) ->name('redemptions.reject');
|
Route::patch ('redemptions/{redemption}/reject', [Admin\RedemptionController::class,'reject']) ->name('redemptions.reject');
|
||||||
@@ -34,6 +42,11 @@ Route::middleware(['auth','child'])->group(function () {
|
|||||||
Route::post('lernen/{subject:slug}/antwort', [\App\Http\Controllers\Child\LearnController::class,'answer']) ->name('learn.answer');
|
Route::post('lernen/{subject:slug}/antwort', [\App\Http\Controllers\Child\LearnController::class,'answer']) ->name('learn.answer');
|
||||||
Route::get ('belohnungen', [\App\Http\Controllers\Child\RewardController::class,'index']) ->name('rewards.index');
|
Route::get ('belohnungen', [\App\Http\Controllers\Child\RewardController::class,'index']) ->name('rewards.index');
|
||||||
Route::post('belohnungen/{reward}/einloesen', [\App\Http\Controllers\Child\RewardController::class,'redeem']) ->name('rewards.redeem');
|
Route::post('belohnungen/{reward}/einloesen', [\App\Http\Controllers\Child\RewardController::class,'redeem']) ->name('rewards.redeem');
|
||||||
|
Route::get ('quiz', [\App\Http\Controllers\Child\QuizController::class,'index']) ->name('quiz.index');
|
||||||
|
Route::get ('quiz/versuch/{attempt}', [\App\Http\Controllers\Child\QuizController::class,'question'])->name('quiz.question');
|
||||||
|
Route::post('quiz/versuch/{attempt}/antwort', [\App\Http\Controllers\Child\QuizController::class,'answer']) ->name('quiz.answer');
|
||||||
|
Route::get ('quiz/ergebnis/{attempt}', [\App\Http\Controllers\Child\QuizController::class,'result']) ->name('quiz.result');
|
||||||
|
Route::post('quiz/{quiz}/start', [\App\Http\Controllers\Child\QuizController::class,'start']) ->name('quiz.start');
|
||||||
Route::get ('erinnerung', [\App\Http\Controllers\Child\ReferenceController::class,'index'])->name('reference.index');
|
Route::get ('erinnerung', [\App\Http\Controllers\Child\ReferenceController::class,'index'])->name('reference.index');
|
||||||
Route::get ('erinnerung/{reference:slug}', [\App\Http\Controllers\Child\ReferenceController::class,'show']) ->name('reference.show');
|
Route::get ('erinnerung/{reference:slug}', [\App\Http\Controllers\Child\ReferenceController::class,'show']) ->name('reference.show');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user