From c116fb230f2aa1849b6fbd7291f2b4044c9337af Mon Sep 17 00:00:00 2001 From: Jeremy DUCOURTHIAL Date: Mon, 20 Nov 2023 14:16:33 +0100 Subject: [PATCH] =?UTF-8?q?feat=20:=20random=20question=20+=20loginPlayer?= =?UTF-8?q?=20(d=C3=A9but)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Website/controllers/ControllerUser.php | 11 ++- Website/controllers/ControllerUserPlayers.php | 76 +++++++++++++++++++ Website/controllers/FrontController.php | 2 + Website/gateways/GatewayQuestion.php | 2 +- Website/templates/home.twig | 5 +- Website/templates/loginPlayer.twig | 35 +++++++++ Website/templates/viewScore.twig | 2 +- 7 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 Website/controllers/ControllerUserPlayers.php create mode 100644 Website/templates/loginPlayer.twig diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 8a2edde..6c809b6 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -56,7 +56,16 @@ class ControllerUser echo $this->twig->render($this->vues["multiplayer"]); } - function login() + function loginAdmin() + { + echo $this->twig->render($this->vues["loginAdmin"], [ + 'error' => $_SESSION["error"], + ]); + + $_SESSION["error"] = ""; + } + + function loginPlayer() { echo $this->twig->render($this->vues["loginAdmin"], [ 'error' => $_SESSION["error"], diff --git a/Website/controllers/ControllerUserPlayers.php b/Website/controllers/ControllerUserPlayers.php new file mode 100644 index 0000000..14434cb --- /dev/null +++ b/Website/controllers/ControllerUserPlayers.php @@ -0,0 +1,76 @@ +twig =$twig; + $this->vues = $vues; + + $this->mdPlayer = new ModelPlayer(); + } + else { + header("Location:/login"); + } + } catch (PDOException $e) { + // Gérez les erreurs PDO ici + } catch (Exception $e2) { + // Gérez d'autres erreurs ici + } + } + + function delete($param) { + $this->mdPlayer->deleteAdministratorByID($param["id"]); + header("Location:/admin/administrators"); + } + + function add($param) { + + $username = $_POST['username']; + $password = $_POST['password']; + + $Player = [ + 'username' => $username, + 'password' => $password, + ]; + + $this->mdPlayer->addAdministrator($Player); + + header("Location:/loginPlayer"); + } + + function updatemodal($param) { + + $administrator = $this->mdPlayer->getAdministratorByID($param["id"]); + + echo $this->twig->render($this->vues["adminAdministratorsModal"], [ + 'administrator' => $administrator, + ]); + } + + function update($param) { + + $id = $_POST['id']; + $username = $_POST['username']; + $password = $_POST['password']; + + $Admin = [ + 'username' => $username, + 'password' => $password, + ]; + + $this->mdPlayer->updateAdministrator($id,$Admin); + + header("Location:/admin/administrators"); + } +} \ No newline at end of file diff --git a/Website/controllers/FrontController.php b/Website/controllers/FrontController.php index cc20a13..29e9166 100755 --- a/Website/controllers/FrontController.php +++ b/Website/controllers/FrontController.php @@ -25,6 +25,8 @@ class FrontController $router->map('GET', '/admin/questions', 'ControllerAdminQuestions'); $router->map('POST', '/admin/questions/[a:action]', 'ControllerAdminQuestions'); $router->map('GET', '/admin/questions/[a:action]/[i:id]', 'ControllerAdminQuestions'); + $router->map('POST', '/user/players/[a:action]', 'ControllerAdminQuestions'); + $router->map('GET', '/user/players/[a:action]/[i:id]', 'ControllerAdminQuestions'); // Match the current request $match = $router->match(); diff --git a/Website/gateways/GatewayQuestion.php b/Website/gateways/GatewayQuestion.php index 39b709d..6ee3749 100755 --- a/Website/gateways/GatewayQuestion.php +++ b/Website/gateways/GatewayQuestion.php @@ -65,7 +65,7 @@ class GatewayQuestion public function getQuestionsByChapterAndDifficulty($idChapter, $difficulty) { - $query = "SELECT * FROM questions WHERE idchapter = :idChapter AND difficulty = :difficulty;"; + $query = "SELECT * FROM questions WHERE idchapter = :idChapter AND difficulty = :difficulty ORDER BY RAND() LIMIT 10;"; $this->con->executeQuery( $query, array( diff --git a/Website/templates/home.twig b/Website/templates/home.twig index 2fe9194..eb61a11 100644 --- a/Website/templates/home.twig +++ b/Website/templates/home.twig @@ -10,6 +10,9 @@ +
+ CONNEXION +
@@ -26,7 +29,7 @@
- +

ADMINISTRATION diff --git a/Website/templates/loginPlayer.twig b/Website/templates/loginPlayer.twig new file mode 100644 index 0000000..b20d194 --- /dev/null +++ b/Website/templates/loginPlayer.twig @@ -0,0 +1,35 @@ + + + + + Math'Educ - Connexion + + + + + + + diff --git a/Website/templates/viewScore.twig b/Website/templates/viewScore.twig index ddbdc26..d40e730 100644 --- a/Website/templates/viewScore.twig +++ b/Website/templates/viewScore.twig @@ -11,7 +11,7 @@ -
+

🏆 Score : 🏆

{{ score }}