From e224c6109f02d2837240145743fa1521537d2763 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Mon, 27 Nov 2023 17:20:00 +0100 Subject: [PATCH] modification de l'affichage des resultats (et du code php derriere) --- Project/php/controller/VisitorController.php | 18 ++++++++++--- Project/php/js/memory.js | 2 +- Project/php/js/quiz.js | 28 +++++++++++++------- Project/php/templates/resultatsJeux.html | 4 ++- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Project/php/controller/VisitorController.php b/Project/php/controller/VisitorController.php index b6c646a..8d5da49 100755 --- a/Project/php/controller/VisitorController.php +++ b/Project/php/controller/VisitorController.php @@ -149,11 +149,21 @@ class VisitorController UserController::home(); } - public function resultatsJeux($match): void{ + public function resultatsQuiz(): void{ global $twig; global $user; - $score = $_POST['score']; - if(isset($user)) echo $twig->render('resultatsJeux.html', ['userID' => $user->getId(), 'userRole' => $user->getRoles(), 'points' => $score]); - else echo $twig->render('resultatsJeux.html', ['points'=>$score]); + $score = Validation::filter_int(intval($_POST['score'] ?? null)); + $len = Validation::filter_int(intval($_POST['total']??null)); + $res = $score . '/'. $len; + if(isset($user)) echo $twig->render('resultatsJeux.html', ['userID' => $user->getId(),'res' => $res, 'userRole' => $user->getRoles()]); + else echo $twig->render('resultatsJeux.html', ['res' => $res]); + } + + public function resultatsMemory(): void{ + global $twig; + global $user; + $score = Validation::filter_int(intval($_POST['score'] ?? null)); + if(isset($user)) echo $twig->render('resultatsJeux.html', ['userID' => $user->getId(),'res' => $score, 'userRole' => $user->getRoles()]); + else echo $twig->render('resultatsJeux.html', ['res' => $score]); } } \ No newline at end of file diff --git a/Project/php/js/memory.js b/Project/php/js/memory.js index aa7e0e6..969375e 100755 --- a/Project/php/js/memory.js +++ b/Project/php/js/memory.js @@ -80,7 +80,7 @@ document.addEventListener('DOMContentLoaded', function () { window.location.href = 'resultatsJeux'; var form = document.createElement('form'); form.method = 'post'; - form.action = 'resultatsJeux'; + form.action = 'resultatsMemory'; var input = document.createElement('input'); input.type = 'hidden'; diff --git a/Project/php/js/quiz.js b/Project/php/js/quiz.js index fff42a1..68df957 100755 --- a/Project/php/js/quiz.js +++ b/Project/php/js/quiz.js @@ -1,8 +1,8 @@ var currentQuestion = 0; -var score = 0; +var currentScore = 0; function validateAndNext(correct) { - if (correct) score++; + if (correct) currentScore++; nextQuestion(); } @@ -18,17 +18,25 @@ function nextQuestion() { nextQuestionDiv.style.display = "block"; } else{ - window.location.href = 'resultatsJeux'; - var form = document.createElement('form'); + alert() + let form = document.createElement('form'); form.method = 'post'; - form.action = 'resultatsJeux'; + form.action = 'resultatsQuiz'; - var input = document.createElement('input'); - input.type = 'hidden'; - input.name = 'score'; - input.value = score + '/20'; + let score = document.createElement('input'); + score.type = 'hidden'; + score.name = 'score'; + score.value = currentScore; - form.appendChild(input); + let total = document.createElement('input'); + total.type = 'hidden'; + total.name = 'total'; + total.value = len; + + + + form.appendChild(score); + form.appendChild(total); document.body.appendChild(form); form.submit(); diff --git a/Project/php/templates/resultatsJeux.html b/Project/php/templates/resultatsJeux.html index e5907f6..3a41e5b 100755 --- a/Project/php/templates/resultatsJeux.html +++ b/Project/php/templates/resultatsJeux.html @@ -45,13 +45,15 @@ {% include 'navBar.twig' %} +{% if res is defined %}
- Votre score est de {{ points }}! + Votre score est de {{ res }} !
Célébration
+{% endif %}