Add grade/Klasse system: assign class levels to users, questions, and quizzes

- users.grade: set per child in admin (Klasse 1–10)
- quizzes.grade, questions.grade: optional target class (null = all)
- Children only see content matching their grade or without grade set
- Admin views show grade badge in user list, quiz list, questions list
- Quiz create/edit and user create/edit have Klasse dropdown
This commit is contained in:
root
2026-05-06 07:19:17 +00:00
parent c66f126e99
commit 44f281514b
13 changed files with 85 additions and 9 deletions
+11 -1
View File
@@ -22,14 +22,24 @@ class LearnController extends Controller {
$answeredToday = QuestionAttempt::where('user_id',$user->id)
->whereDate('created_at', today())
->pluck('question_id');
$grade = $user->grade;
$question = $subject->activeQuestions()
->whereNotIn('id', $answeredToday)
->where(function($q) use ($grade) {
$q->whereNull('grade');
if ($grade) $q->orWhere('grade', $grade);
})
->with('answerOptions')
->inRandomOrder()
->first();
// Falls alle beantwortet: ganz random
if (!$question) {
$question = $subject->activeQuestions()->with('answerOptions')->inRandomOrder()->first();
$question = $subject->activeQuestions()
->where(function($q) use ($grade) {
$q->whereNull('grade');
if ($grade) $q->orWhere('grade', $grade);
})
->with('answerOptions')->inRandomOrder()->first();
}
if (!$question) {
return redirect()->route('learn.subjects')->with('info','Noch keine Fragen für dieses Fach.');
@@ -8,7 +8,12 @@ class QuizController extends Controller {
public function index() {
$subjects = Subject::all()->keyBy('id');
$grade = auth()->user()->grade;
$quizzes = Quiz::with('subject')->where('active',true)
->where(function($q) use ($grade) {
$q->whereNull('grade');
if ($grade) $q->orWhere('grade', $grade);
})
->withCount('questions')->get()->groupBy('subject_id');
$bestScores = QuizAttempt::where('user_id',auth()->id())
->where('status','completed')