diff --git a/Website/class/Administrator.php b/Website/class/Administrator.php index f5fc48f..cd6afb9 100644 --- a/Website/class/Administrator.php +++ b/Website/class/Administrator.php @@ -5,16 +5,22 @@ class Administrator private int $id; private string $username; private string $hashedPassword; - - public function __construct(string $username, string $password) + + public function __construct(int $id,string $username, string $password) { + $this->id = $id; $this->username = $username; try { - $this->hashedPassword = $hashedPassword = md5($password); + $this->hashedPassword = md5($password); } catch (Exception $e) { echo $e->getMessage(); } } + + public function getId(): int + { + return $this->id; + } public function getUsername() { diff --git a/Website/class/Chapter.php b/Website/class/Chapter.php index ac2dec0..5f3a426 100644 --- a/Website/class/Chapter.php +++ b/Website/class/Chapter.php @@ -5,11 +5,17 @@ class Chapter private int $id; private string $name; - public function __construct(string $name) + public function __construct(int $id,string $name) { + $this->id = $id; $this->name = $name; } + public function getId() + { + return $this->id; + } + public function getName() { return $this->name; diff --git a/Website/class/Lobby.php b/Website/class/Lobby.php index 61fea67..99c60a0 100644 --- a/Website/class/Lobby.php +++ b/Website/class/Lobby.php @@ -15,6 +15,11 @@ class Lobby $this->nbPlayer = $nbPlayer; } + public function getId(): int + { + return $this->id; + } + public function getName() { return $this->name; diff --git a/Website/class/Player.php b/Website/class/Player.php index 06d5d71..7b440ef 100644 --- a/Website/class/Player.php +++ b/Website/class/Player.php @@ -17,6 +17,11 @@ class Player } } + public function getId(): int + { + return $this->id; + } + public function getNickname() { return $this->nickname; diff --git a/Website/class/Question.php b/Website/class/Question.php index aa19632..c6e4fa9 100644 --- a/Website/class/Question.php +++ b/Website/class/Question.php @@ -45,6 +45,11 @@ class Question return $this->idAnswerGood; } + public function getDifficulty(): int + { + return $this->difficulty; + } + public function setContent(string $content): void { $this->content = $content; @@ -55,11 +60,6 @@ class Question $this->idAnswerGood = $idAnswerGood; } - public function getDifficulty(): int - { - return $this->difficulty; - } - public function setDifficulty(int $difficulty): void { $this->difficulty = $difficulty; diff --git a/Website/controllers/ControllerAdminQuestions.php b/Website/controllers/ControllerAdminQuestions.php index a86ac1f..ed4c1a3 100644 --- a/Website/controllers/ControllerAdminQuestions.php +++ b/Website/controllers/ControllerAdminQuestions.php @@ -21,7 +21,7 @@ class ControllerAdminQuestions $this->mdQuestion = new ModelQuestion(); $this->mdAnswer = new ModelAnswer(); $this->mdChapter = new ModelChapter(); - + $questions = array(); $questions = $this->mdQuestion->getQuestions(); $chapters = $this->mdChapter->getChapters(); @@ -96,34 +96,23 @@ class ControllerAdminQuestions { $question = $this->mdQuestion->getQuestionByID($param["id"]); - $answersIDArray = $this->mdAnswer->getAnswersByIDQuestions($param["id"]); + $answers = $this->mdAnswer->getAnswersByIDQuestions($param["id"]); $chapters = $this->mdChapter->getChapters(); - $answers = array(); - $i = 0; - foreach ($answersIDArray as $answerIDArray) { - $answers["{$i}"] = $answerIDArray; - $i++; - } - echo $this->twig->render($this->vues["adminQuestionsModal"], [ 'question' => $question, 'chapters' => $chapters, - 'answerZero' => $answers[0], - 'answerOne' => $answers[1], - 'answerTwo' => $answers[2], - 'answerThree' => $answers[3], + 'answers' => $answers, ]); } function update($param) { - $id = $_POST['id']; + $id = intval($_POST['id']); $content = $_POST['content']; $idChapter = intval($_POST['idChapter']); - var_dump($idChapter); $correctAnswer = intval($_POST['correctAnswer']); $answersId = array(); @@ -137,8 +126,7 @@ class ControllerAdminQuestions $answers[1] = $_POST['answer2']; $answers[2] = $_POST['answer3']; $answers[3] = $_POST['answer4']; - - + $questionDataArray = [ 'content' => $content, @@ -154,7 +142,7 @@ class ControllerAdminQuestions 'id' => $id, ]; } - var_dump($answersId, $answersDataArray); + for ($i = 0; $i <= 3; $i++) { $this->mdAnswer->updateAnswer($answersId[$i], $answersDataArray[$i]); } diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 1f76947..9ff0d0e 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -17,7 +17,6 @@ class ControllerUser global $vues, $twig; session_start(); try { - $this->twig = $twig; $this->vues = $vues; @@ -91,6 +90,7 @@ class ControllerUser $_SESSION["Score"] = 0; $difficulty = $_POST['difficulty']; $chapter = $_POST['chapter']; + $difficultyIsOk = TRUE; $chapterIsOk = TRUE; if (!($difficulty == 0 or $difficulty == 1 or $difficulty == 2)) { @@ -102,19 +102,21 @@ class ControllerUser $_SESSION["error"] = "Valeur de chapitre invalide"; $chapterIsOk = FALSE; } + if ($difficultyIsOk and $chapterIsOk) { $_SESSION["PrevTime"] = new DateTime('now'); $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); - $answerss = array(); + $_SESSION["Answers"] = array(); foreach ($_SESSION["Questions"] as $question) { - $answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']); - $answerss[] = $answers; - var_dump("t"); + $answers = $this->mdAnswer->getAnswersByIDQuestions($question->getId()); + $_SESSION["Answers"][] = $answers; } - // echo $this->twig->render($this->vues["singleplayer"], [ - // 'questions' => $_SESSION["Questions"], - // 'numQuestion' => 0, - // ]); + var_dump($_SESSION["Questions"]); + echo $this->twig->render($this->vues["singleplayer"], [ + 'questions' => $_SESSION["Questions"], + 'numQuestion' => 0, + 'answerss' => $_SESSION["Answers"], + ]); } else { $_SESSION["error"] = "Valeur de choix de thème invalide"; header("Location:/themeChoice"); @@ -132,12 +134,13 @@ class ControllerUser echo $this->twig->render($this->vues["singleplayer"], [ 'questions' => $_SESSION["Questions"], 'numQuestion' => $numQuestion, + 'answerss' => $_SESSION["Answers"], ]); } else { - $answerContent = $_SESSION["Questions"][$numQuestion]['answers'][$answerNumber]['content']; - $_SESSION["Questions"][$numQuestion]['playerAnswersContent'] = $answerContent; - if ($_SESSION["Questions"][$numQuestion]['idanswergood'] == $_SESSION["Questions"][$numQuestion]['answers'][$answerNumber]['id']) { + $answerContent = $_SESSION["Answers"][$numQuestion][$answerNumber]->getContent(); + $_SESSION["playerAnswersContent"][$numQuestion] = $answerContent; + if ($_SESSION["Questions"][$numQuestion]->getIdAnswerGood() == $_SESSION["Answers"][$numQuestion][$answerNumber]->getId()) { $time = $_SESSION["PrevTime"]->diff($_SESSION["CurrTime"]); $_SESSION["Score"] = $_SESSION["Score"] + 80 + 40 * ((30 - $time->s) / 100 * 10 / 3); } @@ -147,15 +150,19 @@ class ControllerUser echo $this->twig->render($this->vues["singleplayer"], [ 'questions' => $_SESSION["Questions"], 'numQuestion' => $numQuestion + 1, + 'answerss' => $_SESSION["Answers"], ]); } else { + $goodAnswer = array(); foreach ($_SESSION["Questions"] as &$question) { - $answer = $this->mdAnswer->getAnswerByID($question['idanswergood']); - $question['goodAnswersContent'] = $answer['content']; + $answer = $this->mdAnswer->getAnswerByID($question->getIdAnswerGood()); + $goodAnswer[] = $answer->getContent(); } echo $this->twig->render($this->vues["viewScore"], [ 'score' => $_SESSION["Score"], 'questions' => $_SESSION["Questions"], + 'answerss' => $_SESSION["Answers"], + 'goodAnswer' => $goodAnswer, ]); } } @@ -168,15 +175,18 @@ class ControllerUser echo $this->twig->render($this->vues["singleplayer"], [ 'questions' => $_SESSION["Questions"], 'numQuestion' => $numQuestion + 1, + 'answerss' => $_SESSION["Answers"], ]); } else { + $goodAnswer = array(); foreach ($_SESSION["Questions"] as &$question) { - $answer = $this->mdAnswer->getAnswerByID($question['idAnswerGood']); - $question['GoodAnswersContent'] = $answer['content']; + $answer = $this->mdAnswer->getAnswerByID($question['idanswergood']); + $goodAnswer[] = $answer->getContent(); } echo $this->twig->render($this->vues["viewScore"], [ 'score' => $_SESSION["Score"], 'questions' => $_SESSION["Questions"], + 'answerss' => $_SESSION["Answers"], ]); } } diff --git a/Website/gateways/GatewayChapter.php b/Website/gateways/GatewayChapter.php index 1b0079a..c9f8ba4 100755 --- a/Website/gateways/GatewayChapter.php +++ b/Website/gateways/GatewayChapter.php @@ -57,13 +57,13 @@ class GatewayChapter $this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); } - public function verifyChapter($name) + public function verifyChapter($id) { - $query = "SELECT chapters.name FROM chapters WHERE name = :name"; + $query = "SELECT chapters.id FROM chapters WHERE id = :id;"; $this->con->executeQuery( $query, array( - ':name' => array($name, PDO::PARAM_STR), + ':id' => array($id, PDO::PARAM_STR), ) ); $results = $this->con->getResults(); diff --git a/Website/models/ModelAdministrator.php b/Website/models/ModelAdministrator.php index 5e7796a..cde7618 100644 --- a/Website/models/ModelAdministrator.php +++ b/Website/models/ModelAdministrator.php @@ -17,7 +17,7 @@ class ModelAdministrator public function getAdministratorByID($id) { $administratorDataArray = $this->gwAdministrator->getAdministratorByID($id); - $administrator = new Administrator($administratorDataArray["username"], $administratorDataArray["password"]); + $administrator = new Administrator($administratorDataArray["id"],$administratorDataArray["username"], $administratorDataArray["password"]); return $administrator; } @@ -26,8 +26,8 @@ class ModelAdministrator $administratorsDataArray = $this->gwAdministrator->getAdministrators(); $administrators = array(); foreach ($administratorsDataArray as $administratorDataArray) { - $administrator = new Administrator($administratorDataArray["username"], $administratorDataArray["password"]); - $administrators[$administratorDataArray['id']] = $administrator; + $administrator = new Administrator($administratorDataArray["id"],$administratorDataArray["username"], $administratorDataArray["password"]); + $administrators[] = $administrator; } return $administrators; } diff --git a/Website/models/ModelAnswer.php b/Website/models/ModelAnswer.php index 5aa9f6e..d4da1e6 100644 --- a/Website/models/ModelAnswer.php +++ b/Website/models/ModelAnswer.php @@ -28,7 +28,7 @@ class ModelAnswer $answers = array(); foreach ($answersDataArray as $answerDataArray) { $answer = new Answer($answerDataArray['id'], $answerDataArray['content'], $idQuestion); - $answers[$answerDataArray['id']] = $answer; + $answers[] = $answer; } return $answers; } diff --git a/Website/models/ModelChapter.php b/Website/models/ModelChapter.php index af2da98..5c5d553 100644 --- a/Website/models/ModelChapter.php +++ b/Website/models/ModelChapter.php @@ -14,8 +14,8 @@ class ModelChapter $chaptersDataArray = $this->gwChapter->getChapters(); $chapters = array(); foreach ($chaptersDataArray as $chapterDataArray) { - $chapter = new Chapter($chapterDataArray["name"]); - $chapters[$chapterDataArray['id']] = $chapter; + $chapter = new Chapter($chapterDataArray['id'],$chapterDataArray["name"]); + $chapters[] = $chapter; } return $chapters; } @@ -33,7 +33,7 @@ class ModelChapter function getChapterByID($id) { $chapterDataArray = $this->gwChapter->getChapterByID($id); - $chapter = new Chapter($chapterDataArray['name']); + $chapter = new Chapter($chapterDataArray['id'],$chapterDataArray['name']); return $chapter; } diff --git a/Website/models/ModelLobby.php b/Website/models/ModelLobby.php index e01a16b..811f4ca 100644 --- a/Website/models/ModelLobby.php +++ b/Website/models/ModelLobby.php @@ -25,7 +25,7 @@ class ModelLobby $lobbyDataArray['password'], intval($lobbyDataArray['nbPlayer']) ); - $lobbies[$lobbyDataArray] = $lobby; + $lobbies[] = $lobby; return $lobbies; } } diff --git a/Website/models/ModelQuestion.php b/Website/models/ModelQuestion.php index a24074f..a0492ed 100644 --- a/Website/models/ModelQuestion.php +++ b/Website/models/ModelQuestion.php @@ -10,7 +10,7 @@ class ModelQuestion $this->gwQuestion = new GatewayQuestion(); } - function getQuestions() + function getQuestions() : array { $questionsDataArray = $this->gwQuestion->getQuestions(); $questions = array(); @@ -23,7 +23,7 @@ class ModelQuestion intval($questionDataArray['difficulty']), intval($questionDataArray['nbfails']) ); - $questions[$questionDataArray['id']] = $question; + $questions[] = $question; } return $questions; } @@ -74,8 +74,9 @@ class ModelQuestion intval($questionDataArray['difficulty']), intval($questionDataArray['nbfails']) ); - $questions[$questionDataArray['id']] = $question; + $this->questions[] = $question; } + return $this->questions; } } diff --git a/Website/templates/adminAdministratorsModal.twig b/Website/templates/adminAdministratorsModal.twig index 0f59a34..bc8013e 100644 --- a/Website/templates/adminAdministratorsModal.twig +++ b/Website/templates/adminAdministratorsModal.twig @@ -54,7 +54,7 @@ id.value = "{{ administrator.id }}"; username.value = "{{ administrator.username }}"; - password.value = "{{ administrator.password }}"; + password.value = "{{ administrator.hashedPassword }}"; modal.show(); } diff --git a/Website/templates/adminQuestionsModal.twig b/Website/templates/adminQuestionsModal.twig index edbb329..f62e650 100644 --- a/Website/templates/adminQuestionsModal.twig +++ b/Website/templates/adminQuestionsModal.twig @@ -37,25 +37,25 @@ - Correct + Correct
- Correct + Correct
- Correct + Correct
- Correct + Correct