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 @@
- -