From 54bbd3e5a9d612a651d2eab9540c5373fd92b248 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Sun, 19 Nov 2023 18:00:03 +0100 Subject: [PATCH 1/2] avancement du quiz --- Project/php/controller/AbsController.php | 2 +- Project/php/controller/FrontController.php | 7 +---- Project/php/controller/StudentController.php | 11 +------ Project/php/templates/quizzView.html | 31 +++++++++++++------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php index 6633b4e..73630dc 100755 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -100,6 +100,6 @@ abstract class AbsController $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]); } } \ No newline at end of file diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index b2597d3..bfa626b 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -56,7 +56,7 @@ class FrontController $this->disconnect(); break; case 'quiz': - $this->quiz(); + AbsController::quiz(); break; default : @@ -128,10 +128,5 @@ class FrontController $mdl->deconnection(); $this->home(); } - public function quiz(){ - $ctrl = new StudentController(); - $ctrl->quiz(); - } - } \ No newline at end of file diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index 5569511..9e47f65 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -36,16 +36,7 @@ class StudentController echo $twig->render('manageVocabView.html', ['vocabularies' => $vocab]); } - public function quiz(): void - { - global $twig; - $vocabId = $_GET['vocabID']; - $mdl = new TranslationGateway(); - $allTranslation = $mdl->findByIdVoc($vocabId); - $shuffle = $allTranslation; - shuffle($shuffle); - echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']); - } + /* public function flashcard(VocabularyList $v) { $idVoc = $v->getId(); 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 %} From 58aefe864e0668c00ac72da10f5525dfd337e283 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Sun, 19 Nov 2023 18:07:48 +0100 Subject: [PATCH 2/2] le quiz marche avec l'autoloader maintenant --- Project/php/controller/AbsController.php | 4 ++-- Project/php/controller/FrontController.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php index 73630dc..1ab18d3 100755 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -92,10 +92,10 @@ abstract class AbsController throw new Exception("Erreur"); } } - public 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; diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index bfa626b..7da60d3 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -56,7 +56,7 @@ class FrontController $this->disconnect(); break; case 'quiz': - AbsController::quiz(); + AbsController::quiz($match); break; default :