feat : question hors Json

tests
Jade VAN BRABANDT 1 year ago
parent bbcc80e5ef
commit add9b34d05

@ -103,15 +103,14 @@ class ControllerUser
$chapterIsOk = FALSE; $chapterIsOk = FALSE;
} }
if ($difficultyIsOk and $chapterIsOk) { if ($difficultyIsOk and $chapterIsOk) {
$questions = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
foreach ($questions as &$question) { foreach ($_SESSION["Questions"] as &$question) {
$answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']); $answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']);
$question['answers'] = $answers; $question['answers'] = $answers;
} }
echo $this->twig->render($this->vues["singleplayer"], [ echo $this->twig->render($this->vues["singleplayer"], [
'questions' => $questions, 'questions' => $_SESSION["Questions"],
'numQuestion' => 0, 'numQuestion' => 0,
'jsonQuestions' => json_encode($questions),
]); ]);
} else { } else {
$_SESSION["error"] = "Valeur de choix de thème invalide"; $_SESSION["error"] = "Valeur de choix de thème invalide";
@ -124,23 +123,43 @@ class ControllerUser
{ {
$answerNumber = $_POST["answer"]; $answerNumber = $_POST["answer"];
$numQuestion = $_POST["numQuestion"] + 1; $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) { if ($numQuestion > 9) {
echo $this->twig->render($this->vues["home"]); 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) //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 //Si faut paser un param score de page en page dittes le moi je le ferais dw
} else { } else {
if ($_SESSION["Questions"][$numQuestion - 1]['idanswergood'] == $_SESSION["Questions"][$numQuestion - 1]['answers'][$answerNumber]['id']) {
if ($questions[$numQuestion - 1]['idanswergood'] == $questions[$numQuestion - 1]['answers'][$answerNumber]['id']) {
// Player won // Player won
} else { } else {
//Player lost //Player lost
} }
echo $this->twig->render($this->vues["singleplayer"], [ echo $this->twig->render($this->vues["singleplayer"], [
'questions' => $questions, 'questions' => $_SESSION["Questions"],
'numQuestion' => $numQuestion, 'numQuestion' => $numQuestion,
'jsonQuestions' => json_encode($questions),
]); ]);
} }
} }
} }
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 {
var_dump($_SESSION["Temps"]);
// echo $this->twig->render($this->vues["singleplayer"], [
// 'questions' => $_SESSION["Questions"],
// 'numQuestion' => $numQuestion,
// ]);
}
}
}

@ -0,0 +1,5 @@
document.querySelector('#passerButton').addEventListener('click', passerAction);
function passerAction() {
document.getElementById("FormQuestion").action = "/passer";
document.getElementById("FormQuestion").submit();
}

@ -25,10 +25,6 @@ const dureeQuiz = 30; // Durée du quiz en secondes
if (tempsEcoule < animationDuration) { if (tempsEcoule < animationDuration) {
requestAnimationFrame(mettreAJourAiguille); 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); requestAnimationFrame(mettreAJourAiguille);

@ -3,6 +3,7 @@
class ModelQuestion class ModelQuestion
{ {
private $gwQuestion; private $gwQuestion;
public $questions;
public function __construct() public function __construct()
{ {
@ -39,7 +40,7 @@ class ModelQuestion
function getQuestionsByChapterAndDifficulty($chapter, $difficulty) function getQuestionsByChapterAndDifficulty($chapter, $difficulty)
{ {
$questions = $this->gwQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); $this->questions = $this->gwQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
return $questions; return $this->questions;
} }
} }

@ -28,14 +28,13 @@
Question n° : {{ numQuestion+1 }}/10 Question n° : {{ numQuestion+1 }}/10
</p> </p>
</div> </div>
<form action="/verifQuestion" method="post"> <form id="FormQuestion" action="/verifQuestion" method="post">
{# Awfull Code but it's valided by the 6ème membre #} {# Awfull Code but it's valided by the 6ème membre #}
<input type="hidden" name="numQuestion" value="{{ numQuestion }}"> <input type="hidden" name="numQuestion" value="{{ numQuestion }}">
<input type="hidden" name="questions" value="{{ jsonQuestions|e('html_attr') }}">
{# End of Awfull Code #} {# End of Awfull Code #}
<div class="row g-5"> <div class="row g-5">
<div class="col pt-5"> <div class="col pt-5">
<input type="radio" class="btn-check" name="answer" value="0" id="answer1" autocomplete="off"> <input type="radio" class="btn-check" name="answer" value="0" id="answer1" autocomplete="off" required>
<label class="btn fs-2 container text-white" for="answer1" style="background-color:blue;"> <label class="btn fs-2 container text-white" for="answer1" style="background-color:blue;">
{{ questions[numQuestion].answers[0].content }} {{ questions[numQuestion].answers[0].content }}
</label> </label>
@ -64,9 +63,8 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-1 pt-5"> <div class="col-1 pt-5">
<button type="submit" class="fs-2 btn btn-danger btn-lg"> <button type="button" id="passerButton" class="fs-2 btn btn-danger btn-lg">
Passer Passer
{# Si qql peut regarder pr que passer ne passe pas par la fonction verifQuestion mais par une autre #}
</button> </button>
</div> </div>
<div class="col-1 pt-5"> <div class="col-1 pt-5">
@ -78,5 +76,6 @@
</form> </form>
</div> </div>
<script type="module" src="js/scriptChrono.js"></script> <script type="module" src="js/scriptChrono.js"></script>
<script type="module" src="js/passer.js"></script>
</body> </body>
</html> </html>
Loading…
Cancel
Save