From ffefe0d0b9c1697d5b2536a63ef941ab1ebd04b8 Mon Sep 17 00:00:00 2001 From: "lucie.goigoux2" Date: Tue, 21 Nov 2023 16:32:07 +0100 Subject: [PATCH] Fix et ajout navBar sur le quiz --- Project/php/controller/VisitorController.php | 99 +++++++++++++------- Project/php/css/memory.css | 2 + Project/php/js/memory.js | 6 +- Project/php/templates/memory.html | 4 +- Project/php/templates/quizView.html | 2 +- Project/php/templates/vocabList.html | 2 +- 6 files changed, 75 insertions(+), 40 deletions(-) diff --git a/Project/php/controller/VisitorController.php b/Project/php/controller/VisitorController.php index 4df381a..8f155a3 100755 --- a/Project/php/controller/VisitorController.php +++ b/Project/php/controller/VisitorController.php @@ -12,6 +12,7 @@ class VisitorController { public function memory($match): void{ global $twig; + global $user; try{ $idVoc = Validation::filter_int($_POST['idVoc'] ?? 4); @@ -19,6 +20,7 @@ class VisitorController $name = ((new \gateway\VocabularyListGateway())->findById($idVoc))->getName(); $wordShuffle = array(); + shuffle($wordList); $pairs = []; $maxWords = 28; @@ -33,11 +35,22 @@ class VisitorController shuffle($wordShuffle); - echo $twig->render('memory.html', [ - 'wordShuffle' => $wordShuffle, - 'pairs' => json_encode($pairs), - 'name' => $name - ]); + if(isset($user)) { + echo $twig->render('memory.html', [ + 'wordShuffle' => $wordShuffle, + 'pairs' => json_encode($pairs), + 'name' => $name, + 'userID' => $user->getID(), + 'userRole' => $user->getRoles() + ]); + } + else{ + echo $twig->render('memory.html', [ + 'wordShuffle' => $wordShuffle, + 'pairs' => json_encode($pairs), + 'name' => $name + ]); + } } catch (Exception $e){ @@ -47,40 +60,60 @@ class VisitorController public function quiz($match): void { global $twig; - $vocabId = Validation::filter_int($_POST['idVoc'] ?? 4); - $vocabList = (new VocabularyListGateway())->findById($vocabId) ?? null; - if ($vocabList == null) throw new Exception("liste inconnue"); - $mdl = new TranslationGateway(); - $allTranslation = $mdl->findByIdVoc($vocabId); - $shuffle = $allTranslation; - shuffle($shuffle); - - $questions = array(); - $goodAnswers = array(); - $allEnglishWords = array(); - - foreach ($allTranslation as $translation) { - $questions[] = $translation->getWord1(); - $allEnglishWords[] = $translation->getWord2(); - $goodAnswers[] = $translation->getWord2(); - } + global $user; + try { + $vocabId = Validation::filter_int($_POST['idVoc'] ?? 4); + $vocabList = (new VocabularyListGateway())->findById($vocabId) ?? null; + if ($vocabList == null) throw new Exception("liste inconnue"); + $mdl = new TranslationGateway(); + $allTranslation = $mdl->findByIdVoc($vocabId); + $shuffle = $allTranslation; + shuffle($shuffle); + + $questions = array(); + $goodAnswers = array(); + $allEnglishWords = array(); + + foreach ($allTranslation as $translation) { + $questions[] = $translation->getWord1(); + $allEnglishWords[] = $translation->getWord2(); + $goodAnswers[] = $translation->getWord2(); + } - $answers = array(); + $answers = array(); - for($i=0 ; $i< count($questions) ; $i++) { - $correctAnswer = $allTranslation[$i]->getWord2(); - array_splice($allEnglishWords, array_search($correctAnswer, $allEnglishWords), 1); + 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); + $tab = array_rand(array_flip($allEnglishWords), 3); - array_push($allEnglishWords, $correctAnswer); + array_push($allEnglishWords, $correctAnswer); - $tab[] = $correctAnswer; - shuffle($tab); - $answers[] = $tab; - } + $tab[] = $correctAnswer; + shuffle($tab); + $answers[] = $tab; + } - echo $twig->render('quizView.html', ['questions' => $questions, 'answers' => $answers, 'goodAnswers' => $goodAnswers, 'listName' => $vocabList->getName()]); + if (isset($user)) { + echo $twig->render('quizView.html', [ + 'questions' => $questions, + 'answers' => $answers, + 'goodAnswers' => $goodAnswers, + 'listName' => $vocabList->getName(), + 'userID' => $user->getID(), + 'userRole' => $user->getRoles()]); + } else { + echo $twig->render('quizView.html', [ + 'questions' => $questions, + 'answers' => $answers, + 'goodAnswers' => $goodAnswers, + 'listName' => $vocabList->getName()]); + } + } + catch (Exception $e){ + throw new Exception("Erreur"); + } } public function login(): void { diff --git a/Project/php/css/memory.css b/Project/php/css/memory.css index 2fbef9a..927d502 100755 --- a/Project/php/css/memory.css +++ b/Project/php/css/memory.css @@ -21,6 +21,8 @@ h1{ gap: 10px; margin: auto; perspective: 1000px; + min-width: 70vw; + max-height: 70vh; } .card { diff --git a/Project/php/js/memory.js b/Project/php/js/memory.js index 7f5112d..aa7e0e6 100755 --- a/Project/php/js/memory.js +++ b/Project/php/js/memory.js @@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', function () { var word1; var word2; var clickEnabled = true; - var score = 25; + var score = 500; cards.forEach(function (card) { card.addEventListener('click', function () { @@ -12,7 +12,6 @@ document.addEventListener('DOMContentLoaded', function () { return; } card.classList.toggle('flipped'); - nbCard += 1; if (nbCard === 1) { word1 = card.dataset.word; @@ -67,12 +66,11 @@ document.addEventListener('DOMContentLoaded', function () { (pair[0] === word1 && pair[1] === word2) || (pair[0] === word2 && pair[1] === word1) ) { - score+=10; return true; } } if(score !== 0){ - score-=1; + score-=5; } return false; } diff --git a/Project/php/templates/memory.html b/Project/php/templates/memory.html index 91776c5..a221d68 100755 --- a/Project/php/templates/memory.html +++ b/Project/php/templates/memory.html @@ -4,11 +4,13 @@ Memory Game + -
+{% include 'navBar.twig' %} +

Memory Game: {{ name }}

{% for word in wordShuffle %} diff --git a/Project/php/templates/quizView.html b/Project/php/templates/quizView.html index d89ca7b..63e5f23 100755 --- a/Project/php/templates/quizView.html +++ b/Project/php/templates/quizView.html @@ -19,7 +19,7 @@ - +{% include 'navBar.twig' %}

{{listName}}

diff --git a/Project/php/templates/vocabList.html b/Project/php/templates/vocabList.html index 4466469..56df273 100755 --- a/Project/php/templates/vocabList.html +++ b/Project/php/templates/vocabList.html @@ -12,7 +12,7 @@ display: flex; align-items: center; justify-content: center; - height: 100vh; + height: auto; } .content {