feat : gatewayJouer

pull/37/head
Maxence GUITARD 1 year ago
parent a6cbdb0315
commit 9b4e48298a

@ -98,7 +98,8 @@ class ControllerUser
{ {
$_SESSION["Score"] = 0; $_SESSION["Score"] = 0;
$difficulty = $_POST['difficulty']; $difficulty = $_POST['difficulty'];
$chapter = $_POST['chapter']; $_SESSION['chapter'] = $_POST['chapter'];
$difficultyIsOk = TRUE; $difficultyIsOk = TRUE;
$chapterIsOk = TRUE; $chapterIsOk = TRUE;
@ -112,7 +113,7 @@ class ControllerUser
if ($difficultyIsOk and $chapterIsOk) { if ($difficultyIsOk and $chapterIsOk) {
$_SESSION["PrevTime"] = new DateTime('now'); $_SESSION["PrevTime"] = new DateTime('now');
$_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($_SESSION['chapter'], $difficulty);
$_SESSION["Answers"] = array(); $_SESSION["Answers"] = array();
foreach ($_SESSION["Questions"] as $question) { foreach ($_SESSION["Questions"] as $question) {
$answers = $this->mdAnswer->getAnswersByIDQuestions($question->getId()); $answers = $this->mdAnswer->getAnswersByIDQuestions($question->getId());
@ -188,9 +189,12 @@ class ControllerUser
$Final[$c]["PlayerAnswer"] = $answer; $Final[$c]["PlayerAnswer"] = $answer;
$c = $c + 1; $c = $c + 1;
} }
$idPlayer = $_SESSION["idPlayerConnected"];
$idChapter = $_SESSION["chapter"];
echo $this->twig->render($this->vues["viewScore"], [ echo $this->twig->render($this->vues["viewScore"], [
'score' => $_SESSION["Score"], 'score' => $_SESSION["Score"],
'Final' => $Final, 'Final' => $Final,
'numScore' => $this->mdPlayer->getJouerByPlayerAndChapter( $idPlayer, $idChapter),
]); ]);
} }
} }

@ -0,0 +1,66 @@
<?php
class GatewayJouer
{
private $con;
public function __construct()
{
global $dns, $user, $pass;
$this->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];
}
}

@ -3,10 +3,12 @@
class ModelPlayer class ModelPlayer
{ {
private $gwPlayer; private $gwPlayer;
private $gwJouer;
public function __construct() public function __construct()
{ {
$this->gwPlayer = new GatewayPlayer(); $this->gwPlayer = new GatewayPlayer();
$this->gwJouer = new GatewayJouer();
} }
public function addPlayer($player) public function addPlayer($player)
@ -29,4 +31,20 @@ class ModelPlayer
{ {
$this->gwPlayer->deletePlayerByID($id); $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);
}
} }

@ -13,6 +13,7 @@
<body id="bodyStyle"> <body id="bodyStyle">
<div class="mt-5 border border-1 border-black p-3 bg-success text-white d-flex flex-column align-items-center fs-5"> <div class="mt-5 border border-1 border-black p-3 bg-success text-white d-flex flex-column align-items-center fs-5">
<p>🏆 Score : 🏆</p> <p>🏆 Score : 🏆</p>
<p> {{ numScore }} </p>
<p>{{ score }}</p> <p>{{ score }}</p>
</div> </div>

Loading…
Cancel
Save