feat : Question No [Score/EndScreen/Random] 🔥
continuous-integration/drone/push Build is failing Details

tests
BelsethUwU 2 years ago
parent a0ac56ff4a
commit d9b71cbd37

@ -85,7 +85,7 @@ class ControllerUser
header("Location:/login");
}
}
function verifySingleplayer()
{
$difficulty = $_POST['difficulty'];
@ -93,7 +93,6 @@ class ControllerUser
$difficultyIsOk = TRUE;
$chapterIsOk = TRUE;
if (!($difficulty == 0 or $difficulty == 1 or $difficulty == 2)) {
$_SESSION["error"] = "Valeur de difficulté invalide";
$difficultyIsOk = FALSE;
@ -104,15 +103,44 @@ class ControllerUser
$chapterIsOk = FALSE;
}
if ($difficultyIsOk and $chapterIsOk) {
$questions = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter,$difficulty);
var_dump($questions);
$questions = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
foreach ($questions as &$question) {
$answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']);
$question['answers'] = $answers;
}
echo $this->twig->render($this->vues["singleplayer"], [
'questions' => $questions,
'numQuestion' => 0,
]);
'jsonQuestions' => json_encode($questions),
]);
} else {
$_SESSION["error"] = "Valeur de choix de thème invalide";
header("Location:/themeChoice");
}
}
function verifQuestion()
//Only Handdle solo game
{
$answerNumber = $_POST["answer"];
$numQuestion = $_POST["numQuestion"] + 1;
$questions = json_decode($_POST["questions"], true);
if ($numQuestion > 10) {
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),
]);
}
}
}

@ -17,7 +17,7 @@ class GatewayAnswer
$query,
array(
':content' => array($answer['content'], PDO::PARAM_STR),
':idquestion' => array($answer['idquestion'], PDO::PARAM_INT),
':idquestion' => array($answer['idquestion'], PDO::PARAM_INT),
)
);
$answerId = $this->con->lastInsertId();
@ -29,16 +29,16 @@ class GatewayAnswer
$query = "SELECT answers.content,answers.id FROM answers, questions WHERE questions.id = :idquestions AND answers.idquestion = questions.id ;";
$this->con->executeQuery(
$query,
array(
array(
':idquestions' => array($idQuestions, PDO::PARAM_INT)
)
);
$results = $this->con->getResults();
return $results;
}
public function updateAnswer($id,$answer)
public function updateAnswer($id, $answer)
{
$query = "UPDATE answers SET content = :content WHERE id = :id;";
$this->con->executeQuery(
@ -55,4 +55,5 @@ class GatewayAnswer
$query = "DELETE FROM answers WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
}
}

@ -10,7 +10,7 @@ class GatewayQuestion
$this->con = new Connection($dns, $user, $pass);
}
public function addQuestion($question)
public function addQuestion($question)
{
$query = "insert into questions(content,idchapter,difficulty,nbfails) values (:content,:idchapter,:difficulty,:nbfails);";
$this->con->executeQuery(
@ -40,11 +40,11 @@ class GatewayQuestion
$query = "SELECT * FROM questions";
$this->con->executeQuery($query);
$results = $this->con->getResults();
return $results;
}
public function updateQuestion($id,$question)
public function updateQuestion($id, $question)
{
$query = "UPDATE questions SET content = :content, idchapter = :idchapter, idanswergood = :idanswergood WHERE id = :id;";
$this->con->executeQuery(
@ -63,19 +63,19 @@ class GatewayQuestion
$query = "DELETE FROM questions WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
}
public function getQuestionsByChapterAndDifficulty($idChapter,$difficulty)
public function getQuestionsByChapterAndDifficulty($idChapter, $difficulty)
{
var_dump($idChapter,$difficulty);
$query = "SELECT * FROM questions WHERE idchapter = :idChapter AND difficulty = :difficulty;";
$this->con->executeQuery($query,
$this->con->executeQuery(
$query,
array(
':idChapter' => array($idChapter, PDO::PARAM_INT),
':difficulty' => array($difficulty, PDO::PARAM_INT),
':idChapter' => array($idChapter, PDO::PARAM_INT),
':difficulty' => array($difficulty, PDO::PARAM_INT),
)
);
$results = $this->con->getResults();
return $results[0];
return $results;
}
}

@ -15,14 +15,14 @@ class ModelAnswer
return $answersId;
}
function getAnswersByIDQuestions($id)
function getAnswersByIDQuestions($id)
{
$answers = $this->gwAnswer->getAnswersByIDQuestions($id);
return $answers;
}
function updateAnswer($answersId,$answer)
function updateAnswer($answersId, $answer)
{
$this->gwAnswer->updateAnswer($answersId,$answer);
$this->gwAnswer->updateAnswer($answersId, $answer);
}
}

@ -1,6 +1,5 @@
<!DOCTYPE html>
<html lang="fr">
<html>
<head>
<meta charset=utf-8>
@ -20,56 +19,64 @@
</div>
<div id="fond"></div>
</div>
<script src="js/scriptChrono.js"></script>
<div class="container text-center text-white">
<div class="container border border-white rounded mt-5">
<p class="fs-2">
{{ questions[nbQuestion]['content'] }}
{{ questions[numQuestion]['content'] }}
<br>
Question n° : {{ numQuestion }}/10
</p>
</div>
<form action="/verifQuestion" method="post">
{# Awfull Code but it's valided by the 6ème membre #}
<input type="hidden" name="numQuestion" value="{{ numQuestion }}">
<input type="hidden" name="questions" value="{{ jsonQuestions|e('html_attr') }}">
{# End of Awfull Code #}
<div class="row g-5">
<div class="col pt-5">
<input type="radio" class="btn-check" name="reponse" value="0" autocomplete="off">
<label class="btn fs-2 container text-white" for="reponse1" style="background-color:blue;">
Lorem, ipsum.
<input type="radio" class="btn-check" name="answer" value="0" id="answer1" autocomplete="off">
<label class="btn fs-2 container text-white" for="answer1" style="background-color:blue;">
{{ questions[numQuestion].answers[0].content }}
</label>
</div>
<div class="col pt-5">
<input type="radio" class="btn-check" name="reponse" value="1" autocomplete="off">
<label class="btn fs-2 container text-white" for="reponse2" style="background-color:green;">
Lorem, ipsum.
<input type="radio" class="btn-check" name="answer" value="1" id="answer2" autocomplete="off">
<label class="btn fs-2 container text-white" for="answer2" style="background-color:green;">
{{ questions[numQuestion]['answers'][1]['content'] }}
</label>
</div>
</div>
<div class="row g-5">
<div class="col pt-5">
<input type="radio" class="btn-check" name="reponse" value="2" autocomplete="off">
<label class="btn fs-2 container text-white" for="reponse3" style="background-color:red;">
Lorem, ipsum.
<input type="radio" class="btn-check" name="answer" value="2" id="answer3" autocomplete="off">
<label class="btn fs-2 container text-white" for="answer3" style="background-color:red;">
{{ questions[numQuestion]['answers'][2]['content'] }}
</label>
</div>
<div class="col pt-5">
<input type="radio" class="btn-check" name="reponse" value="3" autocomplete="off">
<label class="btn fs-2 container text-white" for="reponse4" style="background-color:orange;">
Lorem, ipsum.
<input type="radio" class="btn-check" name="answer" value="3" id="answer4" autocomplete="off">
<label class="btn fs-2 container text-white" for="answer4" style="background-color:orange;">
{{ questions[numQuestion]['answers'][3]['content'] }}
</label>
</div>
</div>
<div class="row justify-content-center">
<div class="col-1 pt-5">
<button type="button" class="fs-2 btn btn-danger btn-lg">
Passer
<button type="submit" class="fs-2 btn btn-danger btn-lg">
Passer
{# Si qql peut regarder pr que passer ne passe pas par la fonction verifQuestion mais par une autre #}
</button>
</div>
<div class="col-1 pt-5">
<button type="button" class="fs-2 btn btn-success btn-lg">
<button type="submit" class="fs-2 btn btn-success btn-lg">
Valider
</button>
</div>
</div>
</form>
</div>
</body>
<script type="module" src="js/scriptChrono.js"></script>
</body>
</html>
Loading…
Cancel
Save