Files
lernapp/app/Models/QuizAttempt.php
T
root 6c6dd26823 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
2026-05-05 21:14:09 +00:00

21 lines
897 B
PHP

<?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 '—';
}
}