From d31c2c90f355446f56d9eebdd4866a0df88cdb86 Mon Sep 17 00:00:00 2001 From: "jade.van_brabandt" Date: Tue, 21 Nov 2023 17:24:21 +0100 Subject: [PATCH] feat : page user --- .../ControllerAdminAdministrators.php | 2 -- Website/controllers/ControllerUser.php | 33 +++++++++++-------- Website/gateways/GatewayJouer.php | 12 +++++++ Website/gateways/GatewayPlayer.php | 3 +- Website/models/ModelPlayer.php | 7 ++++ Website/templates/userPlayerModal.twig | 1 - Website/templates/userStatus.twig | 19 +++++++---- 7 files changed, 52 insertions(+), 25 deletions(-) diff --git a/Website/controllers/ControllerAdminAdministrators.php b/Website/controllers/ControllerAdminAdministrators.php index 5f61fe3..6c0ed8b 100644 --- a/Website/controllers/ControllerAdminAdministrators.php +++ b/Website/controllers/ControllerAdminAdministrators.php @@ -50,7 +50,6 @@ class ControllerAdminAdministrators function add($param) { - var_dump($_SERVER['REQUEST_METHOD'] !== 'POST'); if ($_SERVER['REQUEST_METHOD'] !== 'POST') { $_SESSION["error"]="Méthode non autorisée."; } else { @@ -58,7 +57,6 @@ class ControllerAdminAdministrators $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 { diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index f48710b..c1f99f6 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -94,6 +94,25 @@ class ControllerUser $_SESSION["error"] = ""; } + function userStatus(){ + if($_SESSION["idPlayerConnected"] != null){ + $this->mdPlayer = new ModelPlayer(); + $player = $this->mdPlayer->getPlayerByID($_SESSION["idPlayerConnected"]); + $maxscores = $this->mdPlayer->getMaxScoresWithChapter($player); + foreach ($maxscores as $maxscore) { + $maxscore["chapter"]=$this->mdChapter->getChapterByID($maxscore["idchapter"])->getName(); + } + echo $this->twig->render($this->vues["userStatus"], + [ + 'player' => $player, + 'maxscores' => $maxscores, + ]); + } + else { + header("Location:/loginPlayer"); + } + } + function verifyAdmin() { $username = $_POST['username']; @@ -241,20 +260,6 @@ class ControllerUser } } - function userStatus(){ - if($_SESSION["idPlayerConnected"] != null){ - - //$this->mdPlayer = new ModelPlayer(); - - //$player = $this->mdPlayer->getPlayerByID($_SESSION["idAdminConnected"]); - - echo $this->twig->render($this->vues["userStatus"]); - } - else { - header("Location:/loginPlayer"); - } - } - function passer() { $numQuestion = $_POST["numQuestion"]; diff --git a/Website/gateways/GatewayJouer.php b/Website/gateways/GatewayJouer.php index 151be1d..ae4b411 100644 --- a/Website/gateways/GatewayJouer.php +++ b/Website/gateways/GatewayJouer.php @@ -68,4 +68,16 @@ class GatewayJouer $results = $this->con->getResults(); return $results[0]; } + public function getMaxScoresWithChapter($player) + { + $query = "SELECT maxscore,idchapter FROM jouer WHERE idplayer = :idplayer;"; + $this->con->executeQuery( + $query, + array( + ':idplayer' => array($player->getId(), PDO::PARAM_STR) + ) + ); + $results = $this->con->getResults(); + return $results; + } } \ No newline at end of file diff --git a/Website/gateways/GatewayPlayer.php b/Website/gateways/GatewayPlayer.php index 33d14b0..aa6615a 100755 --- a/Website/gateways/GatewayPlayer.php +++ b/Website/gateways/GatewayPlayer.php @@ -93,7 +93,6 @@ class GatewayPlayer ) ); $results = $this->con->getResults(); - - return $results[0]; + return $results[0][0]; } } diff --git a/Website/models/ModelPlayer.php b/Website/models/ModelPlayer.php index d579b04..6c92d43 100644 --- a/Website/models/ModelPlayer.php +++ b/Website/models/ModelPlayer.php @@ -32,6 +32,7 @@ class ModelPlayer { $playerDataArray = $this->gwPlayer->getPlayerByID($id); $player = new Player($playerDataArray["id"], $playerDataArray["nickname"], $playerDataArray["password"]); + return $player; } public function updatePlayer($id, $player) @@ -59,4 +60,10 @@ class ModelPlayer { $this->gwJouer->updateJouer($idPlayer, $idChapter, $jouer); } + + public function getMaxScoresWithChapter($player) + { + $maxScores = $this->gwJouer->getMaxScoresWithChapter($player); + return $maxScores; + } } diff --git a/Website/templates/userPlayerModal.twig b/Website/templates/userPlayerModal.twig index bc8013e..d2bfe8b 100644 --- a/Website/templates/userPlayerModal.twig +++ b/Website/templates/userPlayerModal.twig @@ -5,7 +5,6 @@ - diff --git a/Website/templates/userStatus.twig b/Website/templates/userStatus.twig index 911d11d..c89e1e9 100644 --- a/Website/templates/userStatus.twig +++ b/Website/templates/userStatus.twig @@ -1,17 +1,24 @@ - - Math'Educ + Maths Educ + + - +
-
-

test

- +
+

Player Nickname :

+

{{ player.nickname }}

+ {% for maxscore in maxscores %} +
+

Maxscore pour le chapitre {{ maxscore["chapter"] }} :

+

{{ maxscore["maxscore"] }}

+
+ {% endfor %} \ No newline at end of file