From add9b34d054821c342dbe3f700ab384b7491d817 Mon Sep 17 00:00:00 2001
From: "jade.van_brabandt"
Date: Tue, 14 Nov 2023 10:56:54 +0100
Subject: [PATCH] feat : question hors Json
---
Website/controllers/ControllerUser.php | 51 ++++++++++++++++++--------
Website/js/passer.js | 5 +++
Website/js/scriptChrono.js | 4 --
Website/models/ModelQuestion.php | 5 ++-
Website/templates/singleplayer.twig | 11 +++---
5 files changed, 48 insertions(+), 28 deletions(-)
create mode 100644 Website/js/passer.js
diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php
index 088b3a6..a43d8da 100644
--- a/Website/controllers/ControllerUser.php
+++ b/Website/controllers/ControllerUser.php
@@ -103,15 +103,14 @@ class ControllerUser
$chapterIsOk = FALSE;
}
if ($difficultyIsOk and $chapterIsOk) {
- $questions = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
- foreach ($questions as &$question) {
+ $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
+ foreach ($_SESSION["Questions"] as &$question) {
$answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']);
$question['answers'] = $answers;
}
echo $this->twig->render($this->vues["singleplayer"], [
- 'questions' => $questions,
+ 'questions' => $_SESSION["Questions"],
'numQuestion' => 0,
- 'jsonQuestions' => json_encode($questions),
]);
} else {
$_SESSION["error"] = "Valeur de choix de thème invalide";
@@ -124,23 +123,43 @@ class ControllerUser
{
$answerNumber = $_POST["answer"];
$numQuestion = $_POST["numQuestion"] + 1;
- $questions = json_decode($_POST["questions"], true);
+ if ($answerNumber != 1 or $answerNumber != 2 or $answerNumber != 3 or $answerNumber != 4) {
+ $_SESSION["error"] = "Valeur de choix de réponse invalide";
+ echo $this->twig->render($this->vues["singleplayer"], [
+ 'questions' => $_SESSION["Questions"],
+ 'numQuestion' => $numQuestion,
+ ]);
+ } else {
+ if ($numQuestion > 9) {
+ echo $this->twig->render($this->vues["home"]);
+ //EN GROS IL FAUT AFFICHER LE SCORE (C'est copilot qui a fait ça, la fin du commentaire j'veux dire)
+ //Si faut paser un param score de page en page dittes le moi je le ferais dw
+ } else {
+ if ($_SESSION["Questions"][$numQuestion - 1]['idanswergood'] == $_SESSION["Questions"][$numQuestion - 1]['answers'][$answerNumber]['id']) {
+ // Player won
+ } else {
+ //Player lost
+ }
+ echo $this->twig->render($this->vues["singleplayer"], [
+ 'questions' => $_SESSION["Questions"],
+ 'numQuestion' => $numQuestion,
+ ]);
+ }
+ }
+ }
+ function passer()
+ {
+ $numQuestion = $_POST["numQuestion"] + 1;
if ($numQuestion > 9) {
echo $this->twig->render($this->vues["home"]);
//EN GROS IL FAUT AFFICHER LE SCORE (C'est copilot qui a fait ça, la fin du commentaire j'veux dire)
//Si faut paser un param score de page en page dittes le moi je le ferais dw
} else {
-
- if ($questions[$numQuestion - 1]['idanswergood'] == $questions[$numQuestion - 1]['answers'][$answerNumber]['id']) {
- // Player won
- } else {
- //Player lost
- }
- echo $this->twig->render($this->vues["singleplayer"], [
- 'questions' => $questions,
- 'numQuestion' => $numQuestion,
- 'jsonQuestions' => json_encode($questions),
- ]);
+ var_dump($_SESSION["Temps"]);
+ // echo $this->twig->render($this->vues["singleplayer"], [
+ // 'questions' => $_SESSION["Questions"],
+ // 'numQuestion' => $numQuestion,
+ // ]);
}
}
}
diff --git a/Website/js/passer.js b/Website/js/passer.js
new file mode 100644
index 0000000..ef7f160
--- /dev/null
+++ b/Website/js/passer.js
@@ -0,0 +1,5 @@
+document.querySelector('#passerButton').addEventListener('click', passerAction);
+function passerAction() {
+ document.getElementById("FormQuestion").action = "/passer";
+ document.getElementById("FormQuestion").submit();
+}
\ No newline at end of file
diff --git a/Website/js/scriptChrono.js b/Website/js/scriptChrono.js
index 1ed9402..11d25c2 100644
--- a/Website/js/scriptChrono.js
+++ b/Website/js/scriptChrono.js
@@ -25,10 +25,6 @@ const dureeQuiz = 30; // Durée du quiz en secondes
if (tempsEcoule < animationDuration) {
requestAnimationFrame(mettreAJourAiguille);
- } else {
- // Le temps est écoulé, affichez un message
- console.log("Le timer est à zéro !");
- // action à foutre à la fin du timer
}
}
requestAnimationFrame(mettreAJourAiguille);
diff --git a/Website/models/ModelQuestion.php b/Website/models/ModelQuestion.php
index 51497c3..16fa822 100644
--- a/Website/models/ModelQuestion.php
+++ b/Website/models/ModelQuestion.php
@@ -3,6 +3,7 @@
class ModelQuestion
{
private $gwQuestion;
+ public $questions;
public function __construct()
{
@@ -39,7 +40,7 @@ class ModelQuestion
function getQuestionsByChapterAndDifficulty($chapter, $difficulty)
{
- $questions = $this->gwQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
- return $questions;
+ $this->questions = $this->gwQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
+ return $this->questions;
}
}
diff --git a/Website/templates/singleplayer.twig b/Website/templates/singleplayer.twig
index dccb11c..aad43ff 100644
--- a/Website/templates/singleplayer.twig
+++ b/Website/templates/singleplayer.twig
@@ -28,14 +28,13 @@
Question n° : {{ numQuestion+1 }}/10
-