diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php index 945c987..a82374c 100644 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -92,15 +92,15 @@ class AbsController throw new Exception("Erreur"); } } - public static function quiz(): void + public function quiz($match): void { global $twig; - $vocabId = $_GET['vocabID']; + $vocabId = Validation::filter_int($match['params']['id'] ?? null); $mdl = new TranslationGateway(); $allTranslation = $mdl->findByIdVoc($vocabId); $shuffle = $allTranslation; shuffle($shuffle); - echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']); + echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations' => $shuffle]); } public function login(): void { diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index f5bcf73..cdcb566 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -43,6 +43,7 @@ class FrontController break; default : + if ($id != null && !$this->checkIdExist($id)) throw new Exception("identifiant invalide"); if ($target == null) throw new Exception("pas de target"); if (isset($_SESSION['login']) && isset($_SESSION['roles'])) { diff --git a/Project/php/templates/quizzView.html b/Project/php/templates/quizzView.html index a161632..e188dd4 100755 --- a/Project/php/templates/quizzView.html +++ b/Project/php/templates/quizzView.html @@ -8,19 +8,28 @@

Quiz

- {% if translations is defined %} - {% for translation in translations %} + {% if translations is defined %} + {% for translation in translations %}

{{ translation.word1 }}

- {% set correctAnswer = translation.word2 %} - {% set otherTranslations = [translation.word2, translations[0].word2, translations[1].word2, translations[2].word2] %} - {{ correctAnswer }}
- {% for otherTranslation in otherTranslations %} - {% if otherTranslation != correctAnswer %} - {{ otherAnswer }}
+ {% set correctAnswer = translation.word2 %} + {% if randomtranslations is defined %} + {% set otherTranslations = [correctAnswer] %} + {% for randomtranslation in randomtranslations %} + {% if randomtranslation.word2 != correctAnswer and otherTranslations|length <= 3 %} + {% set otherTranslations = otherTranslations|merge([randomtranslation.word2]) %} + {% endif %} + {% endfor %} + + + + {# Affichage des réponses sous forme de radio buttons #} + {{ correctAnswer }}
+ {% for otherTranslation in otherTranslations %} + {{ otherTranslation }}
+ {% endfor %} + {% endif %} + {% endfor %} {% endif %} - {% endfor %} - {% endfor %} - {% endif %} {% if submitted %}