temp : working

pull/37/head
Maxence GUITARD 1 year ago
parent 30e1e91471
commit 080e3202b9

@ -139,7 +139,7 @@ class ControllerUser
$_SESSION["Score"] = 0; $_SESSION["Score"] = 0;
$difficulty = $_POST['difficulty']; $difficulty = $_POST['difficulty'];
$chapter = $_POST['chapter']; $chapter = $_POST['chapter'];
$_SESSION['id_chapter'] = $_POST['chapter']; $_SESSION['idChapter'] = $_POST['chapter'];
$difficultyIsOk = TRUE; $difficultyIsOk = TRUE;
$chapterIsOk = TRUE; $chapterIsOk = TRUE;
@ -229,13 +229,30 @@ class ControllerUser
$Final[$c]["PlayerAnswer"] = $answer; $Final[$c]["PlayerAnswer"] = $answer;
$c = $c + 1; $c = $c + 1;
} }
// $idPlayer = $_SESSION["idPlayerConnected"];
// $idChapter = $_SESSION["chapter"]; $jouer = [
// $numScore = $this->mdPlayer->getJouerByPlayerAndChapter( $idPlayer, $idChapter); 'idchapter' => $_SESSION["idChapter"],
'idplayer' => $_SESSION["idPlayerConnected"],
'maxscore' => $_SESSION["Score"]
];
// var_dump($this->mdPlayer->verifyJouer($jouer));
// var_dump($jouer['idchapter']);
// var_dump($jouer['idplayer']);
// var_dump($this->mdPlayer->getMaxScoreByPlayerAndChapter($jouer));
var_dump($jouer);
var_dump($this->mdPlayer->verifyJouer($jouer));
if($this->mdPlayer->verifyJouer($jouer) == null){
$this->mdPlayer->addJouer($jouer);
}
else if($_SESSION["Score"] >= $this->mdPlayer->getMaxScoreByPlayerAndChapter($jouer))
{
$this->mdPlayer->updateJouer($jouer);
}
echo $this->twig->render($this->vues["viewScore"], [ echo $this->twig->render($this->vues["viewScore"], [
'score' => $_SESSION["Score"], 'score' => (int)$_SESSION["Score"],
'Final' => $Final, 'Final' => $Final,
// 'numScore' => $numScore,
]); ]);
} }
} }

@ -17,52 +17,55 @@ class GatewayJouer
public function addJouer($jouer) public function addJouer($jouer)
{ {
$query = "INSERT into jouer(idChapter,idPlayer,numScore) values (:idChapter,:idPlayer,:numScore);"; var_dump($jouer);
$query = "INSERT into jouer(idchapter,idplayer,maxscore) values (:idchapter,:idplayer,:maxscore);";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
array( array(
'idChapter' => array($jouer['idChapter'], PDO::PARAM_STR), 'idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
'idPlayer' => array($jouer['idPlayer'], PDO::PARAM_STR), 'idplayer' => array($jouer['idplayer'], PDO::PARAM_INT),
':numScore' => array($jouer['numScore'], PDO::PARAM_INT) 'maxscore' => array($jouer['maxscore'], PDO::PARAM_INT)
) )
); );
var_dump('toto1');
} }
public function getJouerByPlayerAndChapter(int $idPlayer, int $idChapter) public function getMaxScoreByPlayerAndChapter($jouer)
{ {
$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 ;"; $query = "SELECT jouer.maxscore FROM jouer WHERE jouer.idplayer = :idplayer AND jouer.idchapter = :idchapter";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
array( array(
':idChapter' => array($idChapter, PDO::PARAM_INT), ':idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
':idPlayer' => array($idPlayer, PDO::PARAM_INT) ':idplayer' => array($jouer['idplayer'], PDO::PARAM_INT)
) )
); );
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results[0]; return $results[0];
} }
public function updateJouer($idPlayer, $idChapter, $jouer) public function updateJouer($jouer)
{ {
$query = "UPDATE jouer SET numScore = :numScore WHERE idPlayer = :idPlayer AND idChapter = :idChapter;"; $query = "UPDATE jouer SET maxscore = :maxscore WHERE jouer.idplayer = :idplayer AND jouer.idchapter = :idchapter;";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
array( array(
':idChapter' => array($idChapter, PDO::PARAM_INT), ':idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
':idPlayer' => array($idPlayer, PDO::PARAM_INT), ':idplayer' => array($jouer['idplayer'], PDO::PARAM_INT),
':numScore' => array($jouer['numScore'], PDO::PARAM_INT) ':maxscore' => array($jouer['maxscore'], PDO::PARAM_INT)
) )
); );
} }
public function verifyJouer($idChapter, $idPlayer) public function verifyJouer($jouer)
{ {
$query = "SELECT jouer.idChapter, jouer.idPlayer FROM jouer WHERE idPlayer = :idPlayer AND idChapter = :idChapter"; $query = "SELECT jouer.idchapter, jouer.idplayer FROM jouer WHERE jouer.idplayer = :idplayer AND jouer.idchapter = :idchapter";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
array( array(
':idChapter' => array($idChapter, PDO::PARAM_STR), ':idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
':idPlayer' => array($idPlayer, PDO::PARAM_STR) ':idplayer' => array($jouer['idplayer'], PDO::PARAM_INT)
) )
); );
$results = $this->con->getResults(); $results = $this->con->getResults();

@ -49,14 +49,21 @@ class ModelPlayer
$this->gwJouer->addJouer($jouer); $this->gwJouer->addJouer($jouer);
} }
public function getJouerByPlayerAndChapter( $idPlayer, $idChapter) public function getMaxScoreByPlayerAndChapter($jouer)
{ {
$jouerDataArray = $this->gwJouer->getJouerByPlayerAndChapter($idPlayer,$idChapter); $jouerDataArray = $this->gwJouer->getMaxScoreByPlayerAndChapter($jouer);
return $jouerDataArray; return $jouerDataArray;
} }
public function updateJouer($idPlayer, $idChapter, $jouer) public function updateJouer($jouer)
{ {
$this->gwJouer->updateJouer($idPlayer, $idChapter, $jouer); $this->gwJouer->updateJouer($jouer);
} }
public function verifyJouer($jouer)
{
$tabidjouer = $this->gwJouer->verifyJouer($jouer);
return $tabidjouer;
}
} }

Loading…
Cancel
Save