From 9b4e48298ae34e785e976fcfc2389c36d6c256c8 Mon Sep 17 00:00:00 2001 From: "maxence.guitard" Date: Tue, 21 Nov 2023 15:01:41 +0100 Subject: [PATCH] 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 }}