ajoute Quiz flash (chantier vrai cockpit, étape 2) : QCM et vrai/faux, lancé en direct, indépendant d'une séance de lab
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
45f8a69e26
commit
16d1293911
24 changed files with 1249 additions and 5 deletions
48
portail/app/Models/QuestionQuiz.php
Normal file
48
portail/app/Models/QuestionQuiz.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class QuestionQuiz extends Model
|
||||
{
|
||||
public const QCM = 'qcm';
|
||||
|
||||
public const VRAI_FAUX = 'vrai_faux';
|
||||
|
||||
protected $table = 'questions_quiz';
|
||||
|
||||
protected $fillable = ['quiz_id', 'enonce', 'type', 'ordre', 'reponse_vrai_faux'];
|
||||
|
||||
protected $casts = [
|
||||
'reponse_vrai_faux' => 'boolean',
|
||||
];
|
||||
|
||||
/** @return BelongsTo<Quiz, $this> */
|
||||
public function quiz(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Quiz::class);
|
||||
}
|
||||
|
||||
/** @return HasMany<ChoixQuestionQuiz, $this> */
|
||||
public function choix(): HasMany
|
||||
{
|
||||
return $this->hasMany(ChoixQuestionQuiz::class)->orderBy('ordre');
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrai si $choixId (QCM) ou $reponseVraiFaux (vrai/faux) est la bonne
|
||||
* réponse à cette question. Un seul des deux arguments compte, selon
|
||||
* le type de la question.
|
||||
*/
|
||||
public function estCorrecte(?int $choixId, ?bool $reponseVraiFaux): bool
|
||||
{
|
||||
if ($this->type === self::VRAI_FAUX) {
|
||||
return $reponseVraiFaux !== null && $reponseVraiFaux === $this->reponse_vrai_faux;
|
||||
}
|
||||
|
||||
return $choixId !== null && $this->choix()->where('id', $choixId)->where('est_correct', true)->exists();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue