diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 181bab2..ab5e737 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -139,6 +139,7 @@ class ControllerUser $_SESSION["Score"] = 0; $difficulty = $_POST['difficulty']; $chapter = $_POST['chapter']; + $_SESSION['id_chapter'] = $_POST['chapter']; $difficultyIsOk = TRUE; $chapterIsOk = TRUE; @@ -228,9 +229,13 @@ class ControllerUser $Final[$c]["PlayerAnswer"] = $answer; $c = $c + 1; } + // $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' => $numScore, ]); } } diff --git a/Website/gateways/GatewayJouer.php b/Website/gateways/GatewayJouer.php new file mode 100644 index 0000000..151be1d --- /dev/null +++ b/Website/gateways/GatewayJouer.php @@ -0,0 +1,71 @@ +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 358b6c4..d579b04 100644 --- a/Website/models/ModelPlayer.php +++ b/Website/models/ModelPlayer.php @@ -3,15 +3,18 @@ namespace models; use gateways\GatewayPlayer; +use gateways\GatewayJouer; use classes\Player; class ModelPlayer { private $gwPlayer; + private $gwJouer; public function __construct() { $this->gwPlayer = new GatewayPlayer(); + $this->gwJouer = new GatewayJouer(); } public function addPlayer($player) @@ -40,4 +43,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/home.twig b/Website/templates/home.twig index 545af64..057f068 100644 --- a/Website/templates/home.twig +++ b/Website/templates/home.twig @@ -1,6 +1,5 @@ -