modification de l'affichage des resultats (et du code php derriere)

php
Patrick BRUGIERE 1 year ago
parent 8fe07e0328
commit e224c6109f

@ -149,11 +149,21 @@ class VisitorController
UserController::home(); UserController::home();
} }
public function resultatsJeux($match): void{ public function resultatsQuiz(): void{
global $twig; global $twig;
global $user; global $user;
$score = $_POST['score']; $score = Validation::filter_int(intval($_POST['score'] ?? null));
if(isset($user)) echo $twig->render('resultatsJeux.html', ['userID' => $user->getId(), 'userRole' => $user->getRoles(), 'points' => $score]); $len = Validation::filter_int(intval($_POST['total']??null));
else echo $twig->render('resultatsJeux.html', ['points'=>$score]); $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]);
} }
} }

@ -80,7 +80,7 @@ document.addEventListener('DOMContentLoaded', function () {
window.location.href = 'resultatsJeux'; window.location.href = 'resultatsJeux';
var form = document.createElement('form'); var form = document.createElement('form');
form.method = 'post'; form.method = 'post';
form.action = 'resultatsJeux'; form.action = 'resultatsMemory';
var input = document.createElement('input'); var input = document.createElement('input');
input.type = 'hidden'; input.type = 'hidden';

@ -1,8 +1,8 @@
var currentQuestion = 0; var currentQuestion = 0;
var score = 0; var currentScore = 0;
function validateAndNext(correct) { function validateAndNext(correct) {
if (correct) score++; if (correct) currentScore++;
nextQuestion(); nextQuestion();
} }
@ -18,17 +18,25 @@ function nextQuestion() {
nextQuestionDiv.style.display = "block"; nextQuestionDiv.style.display = "block";
} }
else{ else{
window.location.href = 'resultatsJeux'; alert()
var form = document.createElement('form'); let form = document.createElement('form');
form.method = 'post'; form.method = 'post';
form.action = 'resultatsJeux'; form.action = 'resultatsQuiz';
var input = document.createElement('input'); let score = document.createElement('input');
input.type = 'hidden'; score.type = 'hidden';
input.name = 'score'; score.name = 'score';
input.value = score + '/20'; 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); document.body.appendChild(form);
form.submit(); form.submit();

@ -45,13 +45,15 @@
</head> </head>
<body> <body>
{% include 'navBar.twig' %} {% include 'navBar.twig' %}
{% if res is defined %}
<div class="content"> <div class="content">
<div class="container"> <div class="container">
<div class="message"> <div class="message">
Votre score est de {{ points }}! Votre score est de {{ res }} !
</div> </div>
<img class="celebration-image" src="{{ base }}/assets/img/celeb.png" alt="Célébration"> <img class="celebration-image" src="{{ base }}/assets/img/celeb.png" alt="Célébration">
</div> </div>
</div> </div>
{% endif %}
</body> </body>
</html> </html>

Loading…
Cancel
Save