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:
@@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user