From 9b4e48298ae34e785e976fcfc2389c36d6c256c8 Mon Sep 17 00:00:00 2001 From: "maxence.guitard" Date: Tue, 21 Nov 2023 15:01:41 +0100 Subject: [PATCH 1/4] feat : gatewayJouer --- Website/controllers/ControllerUser.php | 8 +++- Website/gateways/GatewayJouer.php | 66 ++++++++++++++++++++++++++ Website/models/ModelPlayer.php | 18 +++++++ Website/templates/viewScore.twig | 1 + 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 Website/gateways/GatewayJouer.php diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 46cf806..2f84b4e 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -98,7 +98,8 @@ class ControllerUser { $_SESSION["Score"] = 0; $difficulty = $_POST['difficulty']; - $chapter = $_POST['chapter']; + $_SESSION['chapter'] = $_POST['chapter']; + $difficultyIsOk = TRUE; $chapterIsOk = TRUE; @@ -112,7 +113,7 @@ class ControllerUser if ($difficultyIsOk and $chapterIsOk) { $_SESSION["PrevTime"] = new DateTime('now'); - $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); + $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($_SESSION['chapter'], $difficulty); $_SESSION["Answers"] = array(); foreach ($_SESSION["Questions"] as $question) { $answers = $this->mdAnswer->getAnswersByIDQuestions($question->getId()); @@ -188,9 +189,12 @@ class ControllerUser $Final[$c]["PlayerAnswer"] = $answer; $c = $c + 1; } + $idPlayer = $_SESSION["idPlayerConnected"]; + $idChapter = $_SESSION["chapter"]; echo $this->twig->render($this->vues["viewScore"], [ 'score' => $_SESSION["Score"], 'Final' => $Final, + 'numScore' => $this->mdPlayer->getJouerByPlayerAndChapter( $idPlayer, $idChapter), ]); } } diff --git a/Website/gateways/GatewayJouer.php b/Website/gateways/GatewayJouer.php new file mode 100644 index 0000000..7465cf1 --- /dev/null +++ b/Website/gateways/GatewayJouer.php @@ -0,0 +1,66 @@ +con = new Connection($dns, $user, $pass); + } + + public function addJouer($jouer) + { + $query = "INSERT into jouer(idChapter,idPlayer,numScore) values (:idChapter,:idPlayer,:numScore);"; + $this->con->executeQuery( + $query, + array( + 'idChapter' => array($jouer['idChapter'], PDO::PARAM_STR), + 'idPlayer' => array($jouer['idPlayer'], PDO::PARAM_STR), + ':numScore' => array($jouer['numScore'], PDO::PARAM_INT) + ) + ); + } + + public function getJouerByPlayerAndChapter(int $idPlayer, int $idChapter) + { + $query = "SELECT jouer.numScore FROM jouer,player WHERE jouer.idPlayer = :idPlayer AND jouer.idPlayer = player.id AND jouer.idChapter = :idChapter AND jouer.idChapter = chapter.id ;"; + $this->con->executeQuery( + $query, + array( + ':idChapter' => array($idChapter, PDO::PARAM_INT), + ':idPlayer' => array($idPlayer, PDO::PARAM_INT) + ) + ); + $results = $this->con->getResults(); + return $results[0]; + } + + public function updateJouer($idPlayer, $idChapter, $jouer) + { + $query = "UPDATE jouer SET numScore = :numScore WHERE idPlayer = :idPlayer AND idChapter = :idChapter;"; + $this->con->executeQuery( + $query, + array( + ':idChapter' => array($idChapter, PDO::PARAM_INT), + ':idPlayer' => array($idPlayer, PDO::PARAM_INT), + ':numScore' => array($jouer['numScore'], PDO::PARAM_INT) + ) + ); + } + + public function verifyJouer($idChapter, $idPlayer) + { + $query = "SELECT jouer.idChapter, jouer.idPlayer FROM jouer WHERE idPlayer = :idPlayer AND idChapter = :idChapter"; + $this->con->executeQuery( + $query, + array( + ':idChapter' => array($idChapter, PDO::PARAM_STR), + ':idPlayer' => array($idPlayer, PDO::PARAM_STR) + ) + ); + $results = $this->con->getResults(); + return $results[0]; + } +} \ No newline at end of file diff --git a/Website/models/ModelPlayer.php b/Website/models/ModelPlayer.php index fe9effe..0915e01 100644 --- a/Website/models/ModelPlayer.php +++ b/Website/models/ModelPlayer.php @@ -3,10 +3,12 @@ class ModelPlayer { private $gwPlayer; + private $gwJouer; public function __construct() { $this->gwPlayer = new GatewayPlayer(); + $this->gwJouer = new GatewayJouer(); } public function addPlayer($player) @@ -29,4 +31,20 @@ class ModelPlayer { $this->gwPlayer->deletePlayerByID($id); } + + public function addJouer($jouer) + { + $this->gwJouer->addJouer($jouer); + } + + public function getJouerByPlayerAndChapter( $idPlayer, $idChapter) + { + $jouerDataArray = $this->gwJouer->getJouerByPlayerAndChapter($idPlayer,$idChapter); + return $jouerDataArray; + } + + public function updateJouer($idPlayer, $idChapter, $jouer) + { + $this->gwJouer->updateJouer($idPlayer, $idChapter, $jouer); + } } diff --git a/Website/templates/viewScore.twig b/Website/templates/viewScore.twig index d40e730..b31cab0 100644 --- a/Website/templates/viewScore.twig +++ b/Website/templates/viewScore.twig @@ -13,6 +13,7 @@

🏆 Score : 🏆

+

{{ numScore }}

{{ score }}

From 30e1e9147119c9f2785543f7d1de53ba72fd0265 Mon Sep 17 00:00:00 2001 From: "maxence.guitard" Date: Tue, 21 Nov 2023 15:36:25 +0100 Subject: [PATCH 2/4] fix : probleme page blanche --- Website/controllers/ControllerUser.php | 13 +++++++------ Website/gateways/GatewayJouer.php | 5 +++++ Website/models/ModelPlayer.php | 1 + Website/templates/home.twig | 1 - Website/templates/viewScore.twig | 5 ----- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 37d397f..ab5e737 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -138,8 +138,8 @@ class ControllerUser { $_SESSION["Score"] = 0; $difficulty = $_POST['difficulty']; - $_SESSION['chapter'] = $_POST['chapter']; - + $chapter = $_POST['chapter']; + $_SESSION['id_chapter'] = $_POST['chapter']; $difficultyIsOk = TRUE; $chapterIsOk = TRUE; @@ -153,7 +153,7 @@ class ControllerUser if ($difficultyIsOk and $chapterIsOk) { $_SESSION["PrevTime"] = new DateTime('now'); - $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($_SESSION['chapter'], $difficulty); + $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); $_SESSION["Answers"] = array(); foreach ($_SESSION["Questions"] as $question) { $answers = $this->mdAnswer->getAnswersByIDQuestions($question->getId()); @@ -229,12 +229,13 @@ class ControllerUser $Final[$c]["PlayerAnswer"] = $answer; $c = $c + 1; } - $idPlayer = $_SESSION["idPlayerConnected"]; - $idChapter = $_SESSION["chapter"]; + // $idPlayer = $_SESSION["idPlayerConnected"]; + // $idChapter = $_SESSION["chapter"]; + // $numScore = $this->mdPlayer->getJouerByPlayerAndChapter( $idPlayer, $idChapter); echo $this->twig->render($this->vues["viewScore"], [ 'score' => $_SESSION["Score"], 'Final' => $Final, - 'numScore' => $this->mdPlayer->getJouerByPlayerAndChapter( $idPlayer, $idChapter), + // 'numScore' => $numScore, ]); } } diff --git a/Website/gateways/GatewayJouer.php b/Website/gateways/GatewayJouer.php index 7465cf1..151be1d 100644 --- a/Website/gateways/GatewayJouer.php +++ b/Website/gateways/GatewayJouer.php @@ -1,5 +1,10 @@ - diff --git a/Website/templates/viewScore.twig b/Website/templates/viewScore.twig index edea8ce..61d0a27 100644 --- a/Website/templates/viewScore.twig +++ b/Website/templates/viewScore.twig @@ -12,11 +12,6 @@ -
-

🏆 Score : 🏆

-

{{ numScore }}

-

{{ score }}

-
From a3f5331abbc77694dbfbce62b80542bb1f07da84 Mon Sep 17 00:00:00 2001 From: "jade.van_brabandt" Date: Tue, 21 Nov 2023 15:46:06 +0100 Subject: [PATCH 3/4] feat : little verification --- .../ControllerAdminAdministrators.php | 67 ++++++++++++------- Website/gateways/GatewayAdministrator.php | 13 ++++ Website/models/ModelAdministrator.php | 5 ++ 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/Website/controllers/ControllerAdminAdministrators.php b/Website/controllers/ControllerAdminAdministrators.php index cc7bcf0..5f61fe3 100644 --- a/Website/controllers/ControllerAdminAdministrators.php +++ b/Website/controllers/ControllerAdminAdministrators.php @@ -19,19 +19,20 @@ class ControllerAdminAdministrators session_start(); try { - if($_SESSION["idAdminConnected"] != null){ - $this->twig =$twig; + if ($_SESSION["idAdminConnected"] != null) { + $this->twig = $twig; $this->vues = $vues; - + $this->mdAdministrator = new ModelAdministrator(); - + $administrators = $this->mdAdministrator->getAdministrators(); - + echo $twig->render($vues["adminAdministrators"], [ 'administrators' => $administrators, + 'error' => $_SESSION["error"], ]); - } - else { + $_SESSION["error"] = null; + } else { header("Location:/loginAdmin"); } } catch (PDOException $e) { @@ -41,27 +42,42 @@ class ControllerAdminAdministrators } } - function delete($param) { + function delete($param) + { $this->mdAdministrator->deleteAdministratorByID($param["id"]); header("Location:/admin/administrators"); } - function add($param) { - - $username = $_POST['username']; - $password = $_POST['password']; - - $Admin = [ - 'username' => $username, - 'password' => $password, - ]; - - $this->mdAdministrator->addAdministrator($Admin); - - header("Location:/admin/administrators"); + function add($param) + { + var_dump($_SERVER['REQUEST_METHOD'] !== 'POST'); + if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + $_SESSION["error"]="Méthode non autorisée."; + } else { + $username = $_POST['username']; + $password = $_POST['password']; + $username = trim($_POST['username']); + $password = trim($_POST['password']); + var_dump(!isset($_POST['username']) || !isset($_POST['password']) || empty($username) || empty($password)); + if (!isset($username) || !isset($password) || empty($username) || empty($password)) { + $_SESSION["error"]="Veuillez remplir tous les champs."; + } else { + $Admin = [ + 'username' => $username, + 'password' => $password, + ]; + if ($this->mdAdministrator->verifyAdministratorByName($Admin) != null) { + $_SESSION["error"]="Cet admin existe déjà."; + } else { + $this->mdAdministrator->addAdministrator($Admin); + header("Location:/admin/administrators"); + } + } + } } - function updatemodal($param) { + function updatemodal($param) + { $administrator = $this->mdAdministrator->getAdministratorByID($param["id"]); @@ -70,7 +86,8 @@ class ControllerAdminAdministrators ]); } - function update($param) { + function update($param) + { $id = $_POST['id']; $username = $_POST['username']; @@ -81,8 +98,8 @@ class ControllerAdminAdministrators 'password' => $password, ]; - $this->mdAdministrator->updateAdministrator($id,$Admin); + $this->mdAdministrator->updateAdministrator($id, $Admin); header("Location:/admin/administrators"); } -} \ No newline at end of file +} diff --git a/Website/gateways/GatewayAdministrator.php b/Website/gateways/GatewayAdministrator.php index aa40056..ebc749f 100755 --- a/Website/gateways/GatewayAdministrator.php +++ b/Website/gateways/GatewayAdministrator.php @@ -87,6 +87,19 @@ class GatewayAdministrator ); $results = $this->con->getResults(); + return $results[0]; + } + public function verifyAdministratorByName($administrator) + { + $query = "SELECT administrators.id FROM administrators WHERE username = :username"; + $this->con->executeQuery( + $query, + array( + ':username' => array($administrator['username'], PDO::PARAM_STR), + ) + ); + $results = $this->con->getResults(); + return $results[0]; } } diff --git a/Website/models/ModelAdministrator.php b/Website/models/ModelAdministrator.php index 9d0b823..b0e2051 100644 --- a/Website/models/ModelAdministrator.php +++ b/Website/models/ModelAdministrator.php @@ -52,4 +52,9 @@ class ModelAdministrator $administratorsId = $this->gwAdministrator->verifyAdministrator($Administrator); return $administratorsId; } + public function verifyAdministratorByName($Administrator) + { + $administratorsId = $this->gwAdministrator->verifyAdministratorByName($Administrator); + return $administratorsId; + } } From c6f091387f6b8d60e87c0eed52fb25b213ec65d5 Mon Sep 17 00:00:00 2001 From: Jeremy DUCOURTHIAL Date: Tue, 21 Nov 2023 15:48:10 +0100 Subject: [PATCH 4/4] feat : base player --- Website/controllers/ControllerUser.php | 5 ++--- Website/templates/userStatus.twig | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 181bab2..a2a6ccc 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -239,12 +239,11 @@ class ControllerUser function userStatus(){ if($_SESSION["idPlayerConnected"] != null){ - //$this->mdAdministrator = new ModelAdministrator(); + //$this->mdPlayer = new ModelPlayer(); - //$administrators = $this->mdAdministrator->getAdministrators(); + //$player = $this->mdPlayer->getPlayerByID($_SESSION["idAdminConnected"]); echo $this->twig->render($this->vues["userStatus"]); - } else { header("Location:/loginPlayer"); diff --git a/Website/templates/userStatus.twig b/Website/templates/userStatus.twig index 199b039..911d11d 100644 --- a/Website/templates/userStatus.twig +++ b/Website/templates/userStatus.twig @@ -11,6 +11,7 @@

test

+
\ No newline at end of file