From a0ac56ff4a43a4ff58c9cfd805dbb836f4da467e Mon Sep 17 00:00:00 2001 From: "jade.van_brabandt" Date: Fri, 10 Nov 2023 17:32:39 +0100 Subject: [PATCH] feat : Poggers code :fire: --- Website/controllers/ControllerUser.php | 60 +++++++++++++++---- Website/controllers/FrontController.php | 29 +-------- Website/gateways/GatewayChapter.php | 18 +++++- Website/gateways/GatewayQuestion.php | 16 ++++- Website/models/ModelChapter.php | 9 ++- Website/models/ModelQuestion.php | 16 +++-- Website/templates/choixThemeSolo.twig | 44 -------------- Website/templates/home.twig | 2 +- Website/templates/singleplayer.twig | 80 +++++++++++++------------ Website/templates/themeChoice.twig | 41 +++++++++++++ Website/usages/Config.php | 2 +- 11 files changed, 181 insertions(+), 136 deletions(-) delete mode 100644 Website/templates/choixThemeSolo.twig create mode 100644 Website/templates/themeChoice.twig diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 25f0bcb..7c5c7f5 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -7,7 +7,7 @@ class ControllerUser private $mdAnswer; private $mdPlayer; private $mdLobby; - private $mdAdministrator; + private $mdAdministrator; private $twig; private $vues; @@ -18,7 +18,7 @@ class ControllerUser session_start(); try { - $this->twig =$twig; + $this->twig = $twig; $this->vues = $vues; $this->mdQuestion = new ModelQuestion(); @@ -27,7 +27,6 @@ class ControllerUser $this->mdPlayer = new ModelPlayer(); $this->mdLobby = new ModelLobby(); $this->mdAdministrator = new ModelAdministrator(); - } catch (PDOException $e) { // $dataVueEreur[] = "Erreur inattendue!!! "; // require(__DIR__.'/../vues/erreur.php'); @@ -41,7 +40,13 @@ class ControllerUser { echo $this->twig->render($this->vues["home"]); } - + function themeChoice() + { + $chapters = $this->mdChapter->getChapters(); + echo $this->twig->render($this->vues["themeChoice"], [ + 'chapters' => $chapters, + ]); + } function singleplayer() { echo $this->twig->render($this->vues["singleplayer"]); @@ -58,10 +63,11 @@ class ControllerUser 'error' => $_SESSION["error"], ]); - $_SESSION["error"]=""; + $_SESSION["error"] = ""; } - function verifyAdmin(){ + function verifyAdmin() + { $username = $_POST['username']; $password = $_POST['password']; @@ -69,16 +75,44 @@ class ControllerUser 'username' => $username, 'password' => $password, ]; - + $AdministratorIsOk = $this->mdAdministrator->verifyAdministrator($Administrator); - var_dump($AdministratorIsOk); - if($AdministratorIsOk != null) { - $_SESSION["idAdminConnected"]=$AdministratorIsOk; + if ($AdministratorIsOk != null) { + $_SESSION["idAdminConnected"] = $AdministratorIsOk; header("Location:/admin/administrators"); - } - else { - $_SESSION["error"]="utilisateur introuvable."; + } else { + $_SESSION["error"] = "utilisateur introuvable."; header("Location:/login"); } } + + function verifySingleplayer() + { + $difficulty = $_POST['difficulty']; + $chapter = $_POST['chapter']; + $difficultyIsOk = TRUE; + $chapterIsOk = TRUE; + + + if (!($difficulty == 0 or $difficulty == 1 or $difficulty == 2)) { + $_SESSION["error"] = "Valeur de difficulté invalide"; + $difficultyIsOk = FALSE; + } + + if ($this->mdChapter->verifyChapter($chapter) == NULL) { + $_SESSION["error"] = "Valeur de chapitre invalide"; + $chapterIsOk = FALSE; + } + if ($difficultyIsOk and $chapterIsOk) { + $questions = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter,$difficulty); + var_dump($questions); + echo $this->twig->render($this->vues["singleplayer"], [ + 'questions' => $questions, + 'numQuestion' => 0, + ]); + } else { + $_SESSION["error"] = "Valeur de choix de thème invalide"; + header("Location:/themeChoice"); + } + } } diff --git a/Website/controllers/FrontController.php b/Website/controllers/FrontController.php index 46e6140..cc20a13 100755 --- a/Website/controllers/FrontController.php +++ b/Website/controllers/FrontController.php @@ -1,30 +1,4 @@ map('GET', '/', 'ControllerUser#home'); // Route pour la page d'accueil - $router->map('GET', '/[a:action]', 'ControllerUser'); + $router->map('GET|POST', '/[a:action]', 'ControllerUser'); //$router->map('GET', '/admin', 'ControllerAdminAdministrators'); $router->map('POST', '/login/[a:action]', 'ControllerUser'); $router->map('GET', '/admin/chapters', 'ControllerAdminChapters'); @@ -52,7 +26,6 @@ class FrontController $router->map('POST', '/admin/questions/[a:action]', 'ControllerAdminQuestions'); $router->map('GET', '/admin/questions/[a:action]/[i:id]', 'ControllerAdminQuestions'); - // Match the current request $match = $router->match(); diff --git a/Website/gateways/GatewayChapter.php b/Website/gateways/GatewayChapter.php index ffc3e7a..1f08039 100755 --- a/Website/gateways/GatewayChapter.php +++ b/Website/gateways/GatewayChapter.php @@ -26,7 +26,7 @@ class GatewayChapter $query = "SELECT * FROM chapters"; $this->con->executeQuery($query); $results = $this->con->getResults(); - + return $results; } @@ -39,7 +39,7 @@ class GatewayChapter return $results[0]; } - public function updateChapter($id,$chapter) + public function updateChapter($id, $chapter) { $query = "UPDATE chapters SET name = :name WHERE id = :id;"; $this->con->executeQuery( @@ -56,4 +56,18 @@ class GatewayChapter $query = "DELETE FROM chapters WHERE id = :id;"; $this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); } + + public function verifyChapter($idChapter) + { + $query = "SELECT chapters.id FROM chapters WHERE id = :id"; + $this->con->executeQuery( + $query, + array( + ':id' => array($idChapter, PDO::PARAM_STR), + ) + ); + $results = $this->con->getResults(); + + return $results[0]; + } } diff --git a/Website/gateways/GatewayQuestion.php b/Website/gateways/GatewayQuestion.php index 4754373..01bfbe6 100755 --- a/Website/gateways/GatewayQuestion.php +++ b/Website/gateways/GatewayQuestion.php @@ -12,7 +12,6 @@ class GatewayQuestion public function addQuestion($question) { - var_dump($question); $query = "insert into questions(content,idchapter,difficulty,nbfails) values (:content,:idchapter,:difficulty,:nbfails);"; $this->con->executeQuery( $query, @@ -64,4 +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) + { + var_dump($idChapter,$difficulty); + $query = "SELECT * FROM questions WHERE idchapter = :idChapter AND difficulty = :difficulty;"; + $this->con->executeQuery($query, + array( + ':idChapter' => array($idChapter, PDO::PARAM_INT), + ':difficulty' => array($difficulty, PDO::PARAM_INT), + ) + ); + $results = $this->con->getResults(); + + return $results[0]; + } } diff --git a/Website/models/ModelChapter.php b/Website/models/ModelChapter.php index 24697af..08c44c8 100644 --- a/Website/models/ModelChapter.php +++ b/Website/models/ModelChapter.php @@ -31,8 +31,13 @@ class ModelChapter return $chapter; } - function updateChapter($id,$Chapter) + function updateChapter($id,$chapter) { - $this->gwChapter->updateChapter($id,$Chapter); + $this->gwChapter->updateChapter($id,$chapter); + } + public function verifyChapter($chapter) + { + $id = $this->gwChapter->verifyChapter($chapter); + return $id; } } diff --git a/Website/models/ModelQuestion.php b/Website/models/ModelQuestion.php index ae1cff3..51497c3 100644 --- a/Website/models/ModelQuestion.php +++ b/Website/models/ModelQuestion.php @@ -15,25 +15,31 @@ class ModelQuestion return $questions; } - function deleteQuestionByID($id) + function deleteQuestionByID($id) { $this->gwQuestion->deleteQuestionByID($id); } - function addQuestion($Question) + function addQuestion($Question) { $questionId = $this->gwQuestion->addQuestion($Question); return $questionId; } - function getQuestionByID($id) { - + function getQuestionByID($id) + { $question = $this->gwQuestion->getQuestionByID($id); return $question; } - function updateQuestion($id, $Question) + function updateQuestion($id, $Question) { $this->gwQuestion->updateQuestion($id, $Question); } + + function getQuestionsByChapterAndDifficulty($chapter, $difficulty) + { + $questions = $this->gwQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); + return $questions; + } } diff --git a/Website/templates/choixThemeSolo.twig b/Website/templates/choixThemeSolo.twig deleted file mode 100644 index 59f6ad7..0000000 --- a/Website/templates/choixThemeSolo.twig +++ /dev/null @@ -1,44 +0,0 @@ - - - - Maths Educ - - - - - - - - - -
-

Difficulte :

- - - - - - - - - -
- - - - -
- -
- - - \ No newline at end of file diff --git a/Website/templates/home.twig b/Website/templates/home.twig index e54b067..2fe9194 100644 --- a/Website/templates/home.twig +++ b/Website/templates/home.twig @@ -12,7 +12,7 @@
- +

SOLO diff --git a/Website/templates/singleplayer.twig b/Website/templates/singleplayer.twig index 8e1b2d6..0c0a2ed 100644 --- a/Website/templates/singleplayer.twig +++ b/Website/templates/singleplayer.twig @@ -25,49 +25,51 @@

- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Provident fuga cum soluta iure libero! Ullam, expedita excepturi! Odio distinctio quos quasi commodi libero ratione corrupti, unde iste explicabo suscipit consequatur ipsum! Id beatae corrupti ipsa totam deserunt, vel tenetur, iusto quaerat asperiores veritatis quidem! Vel dolorem recusandae necessitatibus ullam laborum! + {{ questions[nbQuestion]['content'] }}

-
-
- - +
+
+
+ + +
+
+ + +
-
- - +
+
+ + +
+
+ + +
-
-
-
- - -
-
- - -
-
- -
-
- -
-
- + +
+
+ +
+
+ +
-
+
\ No newline at end of file diff --git a/Website/templates/themeChoice.twig b/Website/templates/themeChoice.twig new file mode 100644 index 0000000..9287774 --- /dev/null +++ b/Website/templates/themeChoice.twig @@ -0,0 +1,41 @@ + + + + Maths Educ + + + + + + + + + +
+
+

Difficulte :

+ + + + + + + + + +
+ + + + +
+ +
+
+ + \ No newline at end of file diff --git a/Website/usages/Config.php b/Website/usages/Config.php index 29a696f..e0d8db9 100755 --- a/Website/usages/Config.php +++ b/Website/usages/Config.php @@ -12,7 +12,7 @@ $vues["singleplayer"]="singleplayer.twig"; $vues["multiplayer"]="multiplayer.twig"; $vues["home"]="home.twig"; $vues["connexion"]="connexion.twig"; -$vues["choixSolo"]="choixThemeSolo.twig"; +$vues["themeChoice"]="themeChoice.twig"; $vues["loginAdmin"]="loginAdmin.twig"; $vues["adminAdministrators"]="adminAdministrators.twig"; $vues["adminAdministratorsModal"]="adminAdministratorsModal.twig";