Merge branch 'master' of https://codefirst.iut.uca.fr/git/jade.van_brabandt/3.01-QCM_MuscuMaths
continuous-integration/drone/push Build is passing Details

pull/37/head
Yvan CALATAYUD 1 year ago
commit b078e62b3c

@ -109,7 +109,7 @@ class ControllerUser
$this->mdPlayer = new ModelPlayer();
$player = $this->mdPlayer->getPlayerByID($_SESSION["idPlayerConnected"]);
$maxscores = $this->mdPlayer->getMaxScoresWithChapter($player);
foreach ($maxscores as $maxscore) {
foreach ($maxscores as &$maxscore) {
$maxscore["chapter"]=$this->mdChapter->getChapterByID($maxscore["idchapter"])->getName();
}
echo $this->twig->render($this->vues["userStatus"],
@ -168,7 +168,7 @@ class ControllerUser
$_SESSION["Score"] = 0;
$difficulty = $_POST['difficulty'];
$chapter = $_POST['chapter'];
$_SESSION['id_chapter'] = $_POST['chapter'];
$_SESSION['idChapter'] = $_POST['chapter'];
$difficultyIsOk = TRUE;
$chapterIsOk = TRUE;
@ -268,13 +268,30 @@ class ControllerUser
$Final[$c]["PlayerAnswer"] = $answer;
$c = $c + 1;
}
// $idPlayer = $_SESSION["idPlayerConnected"];
// $idChapter = $_SESSION["chapter"];
// $numScore = $this->mdPlayer->getJouerByPlayerAndChapter( $idPlayer, $idChapter);
$jouer = [
'idchapter' => $_SESSION["idChapter"],
'idplayer' => $_SESSION["idPlayerConnected"],
'maxscore' => $_SESSION["Score"]
];
// var_dump($jouer);
// var_dump($this->mdPlayer->verifyJouer($jouer));
// var_dump($this->mdPlayer->getMaxScoreByPlayerAndChapter($jouer));
// var_dump($jouer['maxscore']);
// var_dump($jouer['maxscore'] <= $this->mdPlayer->getMaxScoreByPlayerAndChapter($jouer));
// var_dump($jouer['maxscore'] >= $this->mdPlayer->getMaxScoreByPlayerAndChapter($jouer));
if($this->mdPlayer->verifyJouer($jouer) == null){
$this->mdPlayer->addJouer($jouer);
}
else if($jouer['maxscore'] <= $this->mdPlayer->getMaxScoreByPlayerAndChapter($jouer))
{
$this->mdPlayer->updateJouer($jouer);
}
echo $this->twig->render($this->vues["viewScore"], [
'score' => $_SESSION["Score"],
'score' => (int)$_SESSION["Score"],
'Final' => $Final,
// 'numScore' => $numScore,
]);
}
}
@ -314,6 +331,21 @@ class ControllerUser
$c = $c + 1;
}
$_SESSION["Score"] = (int)$_SESSION["Score"];
$jouer = [
'idchapter' => $_SESSION["idChapter"],
'idplayer' => $_SESSION["idPlayerConnected"],
'maxscore' => $_SESSION["Score"]
];
if($this->mdPlayer->verifyJouer($jouer) == null){
$this->mdPlayer->addJouer($jouer);
}
else if($jouer['maxscore'] <= $this->mdPlayer->getMaxScoreByPlayerAndChapter($jouer))
{
$this->mdPlayer->updateJouer($jouer);
}
echo $this->twig->render($this->vues["viewScore"], [
'score' => $_SESSION["Score"],
'Final' => $Final,

@ -60,7 +60,7 @@ class ControllerUserPlayers
$player = $this->mdPlayer->getPlayerByID($param["id"]);
echo $this->twig->render($this->vues["adminAdministratorsModal"], [
'administrator' => $administrator,
'player' => $player,
]);
}

@ -17,52 +17,53 @@ class GatewayJouer
public function addJouer($jouer)
{
$query = "INSERT into jouer(idChapter,idPlayer,numScore) values (:idChapter,:idPlayer,:numScore);";
$query = "INSERT into jouer(idchapter,idplayer,maxscore) values (:idchapter,:idplayer,:maxscore);";
$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)
'idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
'idplayer' => array($jouer['idplayer'], PDO::PARAM_INT),
'maxscore' => array($jouer['maxscore'], PDO::PARAM_INT)
)
);
}
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(
$query,
array(
':idChapter' => array($idChapter, PDO::PARAM_INT),
':idPlayer' => array($idPlayer, PDO::PARAM_INT)
':idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
':idplayer' => array($jouer['idplayer'], PDO::PARAM_INT)
)
);
$results = $this->con->getResults();
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 jouer.maxscore = :maxscore WHERE jouer.idplayer = :idplayer AND jouer.idchapter = :idchapter AND jouer.maxscore <= :maxscore;";
$this->con->executeQuery(
$query,
array(
':idChapter' => array($idChapter, PDO::PARAM_INT),
':idPlayer' => array($idPlayer, PDO::PARAM_INT),
':numScore' => array($jouer['numScore'], PDO::PARAM_INT)
':idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
':idplayer' => array($jouer['idplayer'], 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(
$query,
array(
':idChapter' => array($idChapter, PDO::PARAM_STR),
':idPlayer' => array($idPlayer, PDO::PARAM_STR)
':idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
':idplayer' => array($jouer['idplayer'], PDO::PARAM_INT)
)
);
$results = $this->con->getResults();

@ -50,15 +50,15 @@ class ModelPlayer
$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;
}
public function updateJouer($idPlayer, $idChapter, $jouer)
public function updateJouer($jouer)
{
$this->gwJouer->updateJouer($idPlayer, $idChapter, $jouer);
$this->gwJouer->updateJouer($jouer);
}
public function getMaxScoresWithChapter($player)
@ -66,4 +66,11 @@ class ModelPlayer
$maxScores = $this->gwJouer->getMaxScoresWithChapter($player);
return $maxScores;
}
public function verifyJouer($jouer)
{
$tabidjouer = $this->gwJouer->verifyJouer($jouer);
return $tabidjouer;
}
}

Loading…
Cancel
Save