From ee57c9bb57ba7920a0f203427628e54dfd6196fe Mon Sep 17 00:00:00 2001 From: "anthony.richard" Date: Sun, 19 Nov 2023 22:14:52 +0100 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20quiz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/php/controller/AbsController.php | 29 ++++- Project/php/templates/quizzView.html | 139 ++++------------------- 2 files changed, 47 insertions(+), 121 deletions(-) diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php index 0897f54..bb3ee99 100644 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -8,6 +8,7 @@ use gateway\TranslationGateway; use gateway\VocabularyListGateway; use model\MdlStudent; use model\VocabularyList; +use model\Translation; class AbsController { @@ -100,7 +101,33 @@ class AbsController $allTranslation = $mdl->findByIdVoc($vocabId); $shuffle = $allTranslation; shuffle($shuffle); - echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations' => $shuffle]); + + $questions = array(); + $goodAnswers = array(); + $allEnglishWords = array(); + + foreach ($allTranslation as $translation) { + $questions[] = $translation->getWord1(); + $allEnglishWords[] = $translation->getWord2(); + $goodAnswers[] = $translation->getWord2(); + } + + $answers = array(); + + for($i=0 ; $i< count($questions) ; $i++) { + $correctAnswer = $allTranslation[$i]->getWord2(); + array_splice($allEnglishWords, array_search($correctAnswer, $allEnglishWords), 1); + + $tab = array_rand(array_flip($allEnglishWords), 3); + + array_push($allEnglishWords, $correctAnswer); + + $tab[] = $correctAnswer; + shuffle($tab); + $answers[] = $tab; + } + + echo $twig->render('quizzView.html', ['questions' => $questions, 'answers' => $answers, 'goodAnswers' => $goodAnswers]); } public function login(): void { diff --git a/Project/php/templates/quizzView.html b/Project/php/templates/quizzView.html index f2d75fc..003b035 100755 --- a/Project/php/templates/quizzView.html +++ b/Project/php/templates/quizzView.html @@ -1,135 +1,34 @@ - - Manage groups + + Quiz +
-

Quiz

+

Quiz

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

{{ translation.word1 }}

- {% 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 %} + {% if questions is defined %} + {% for i in 0..questions|length %}
-
- {{ correctAnswer }}
+
+

{{ questions[i] }}

+
+ {% for answer in answers[i] %} + {% if answer == goodAnswers[i] %} + {{ answer }}
+ {% else %} + {{ answer }}
+ {% endif %} + {% endfor %}
- {% for otherTranslation in otherTranslations %} - {{ otherTranslation }}
- - {% endfor %} - - +
+ -
- - {% endif %} {% endfor %} {% endif %} - - {% if submitted %} - {% if isCorrect %} -

Correct answer!

- {% else %} -

Wrong answer!

- {% endif %} - {% endif %} -
- -

Translator

-
- {% if translations is defined %} - {% for translation in translations %} - - - - - {% endfor %} - {% endif %} -
+ - \ No newline at end of file