Merge branch 'master' of https://codefirst.iut.uca.fr/git/nathan.boileau/Scripted
continuous-integration/drone/push Build is passing Details

ServeurDeTest
nathan boileau 2 years ago
commit fbf6c8d6dd

@ -161,7 +161,6 @@ class PartieGateway
) )
); );
$partie = $this->findLastPartie(); $partie = $this->findLastPartie();
$tpsMaxPartie = 0;
$query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,1)"; $query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,1)";
foreach ($lesEnigmes as $enigme) { foreach ($lesEnigmes as $enigme) {
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
@ -169,9 +168,7 @@ class PartieGateway
"idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER) "idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER)
) )
); );
$tpsMaxPartie += $enigme->getTempsDeResolution();
} }
$_SESSION['tpsMaxPartie'] = $tpsMaxPartie;
$query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
@ -320,6 +317,20 @@ class PartieGateway
$row = $results[0]; $row = $results[0];
return $row['enigme']; return $row['enigme'];
} }
public function findAllEnigmeIdInPartie ($idPartie) : array{
$query = "SELECT * FROM Contenir WHERE partie = :idPartie";
$this->con->executeQuery($query, array(
"idPartie" => array($idPartie, SQLITE3_INTEGER)
)
);
$results = $this->con->getResults();
$lesEnigmes = array();
foreach ($results as $row){
$lesEnigmes[] = $row['enigme'];
}
return $lesEnigmes;
}
public function getDateDebut($idPartie) : DateTime{ public function getDateDebut($idPartie) : DateTime{
$query = "SELECT dateDebut FROM Partie WHERE id = :idPartie"; $query = "SELECT dateDebut FROM Partie WHERE id = :idPartie";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(

@ -168,6 +168,34 @@ class ResoudreGateway
"enigme" => array($enigmeId, SQLITE3_INTEGER), "enigme" => array($enigmeId, SQLITE3_INTEGER),
"ended" => array(1, SQLITE3_INTEGER))); "ended" => array(1, SQLITE3_INTEGER)));
} }
public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId, int $tempDeResolution, $classement){
$query="UPDATE Resoudre
SET ended=:ended
WHERE utilisateur=:utilisateur
AND enigme=:enigme";
$this->con->executeQuery($query, array(
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT),
"enigme" => array($enigmeId, SQLITE3_INTEGER),
"ended" => array(1, SQLITE3_INTEGER)));
$query="UPDATE Resoudre
SET temps=:temps
WHERE utilisateur=:utilisateur
AND enigme=:enigme";
$this->con->executeQuery($query, array(
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT),
"enigme" => array($enigmeId, SQLITE3_INTEGER),
"temps" => array($tempDeResolution, SQLITE3_INTEGER)));
$query="UPDATE Resoudre
SET classement=:classement
WHERE utilisateur=:utilisateur
AND enigme=:enigme";
$this->con->executeQuery($query, array(
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT),
"enigme" => array($enigmeId, SQLITE3_INTEGER),
"classement" => array($classement, SQLITE3_INTEGER)));
}
public function saveCode(string $mailUtilisateur, int $enigmeId, string $code){ public function saveCode(string $mailUtilisateur, int $enigmeId, string $code){
$query="UPDATE Resoudre $query="UPDATE Resoudre
@ -216,7 +244,6 @@ class ResoudreGateway
WHERE utilisateur=:utilisateur WHERE utilisateur=:utilisateur
AND ended=:ended AND ended=:ended
ORDER BY ended DESC LIMIT 1"; ORDER BY ended DESC LIMIT 1";
// $query = "SELECT * FROM Partie ORDER BY id DESC LIMIT 1";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT),
"ended" => array(1, SQLITE3_INTEGER))); "ended" => array(1, SQLITE3_INTEGER)));
@ -241,4 +268,29 @@ class ResoudreGateway
} }
return $results[0]['max(indexEnigme)']; return $results[0]['max(indexEnigme)'];
} }
public function getMaxClassement($enigmeId, $idPartie) : int{
$query="SELECT classement FROM Resoudre
WHERE enigme=:enigme
AND partie=:partie
ORDER BY classement DESC LIMIT 1";
$this->con->executeQuery($query, array(
"enigme" => array($enigmeId, SQLITE3_INTEGER),
"partie" => array($idPartie, SQLITE3_INTEGER)));
$results=$this->con->getResults();
if (empty($results) || $results[0]['classement'] == null) {
return 0;
}
return $results[0]['classement'];
}
public function getAllByPartieAndUtilisateur(string $mailUtilisateur, int $idPartie) : array{
$query = "SELECT * FROM Resoudre
WHERE utilisateur=:utilisateur
AND partie=:partie";
$this->con->executeQuery($query, array(
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT),
"partie" => array($idPartie, SQLITE3_INTEGER)));
$results=$this->con->getResults();
return $results;
}
} }

@ -190,7 +190,7 @@ class UserController
$index = $_REQUEST['index']; $index = $_REQUEST['index'];
$enigme = $model->getEnigmebyPartieIdAndIndex($_SESSION['idPartie'],$index); $enigme = $model->getEnigmebyPartieIdAndIndex($_SESSION['idPartie'],$index);
$utilisateur=$_SESSION['utilisateur']; $utilisateur=$_SESSION['utilisateur'];
$model->enigmeEnded($utilisateur->getEmail(),$enigme->getIdEnigme()); $model->enigmeMultiEnded($utilisateur->getEmail(),$enigme->getIdEnigme());
$index = $index + 1; $index = $index + 1;
header("Location: index.php?action=goToGame&idPartie=" . $_SESSION['idPartie'] . "&index=". $index); header("Location: index.php?action=goToGame&idPartie=" . $_SESSION['idPartie'] . "&index=". $index);
} catch (Exception $e) { } catch (Exception $e) {
@ -244,6 +244,7 @@ class UserController
$lastIndex = $model->getLastIndex($idPartie); $lastIndex = $model->getLastIndex($idPartie);
if($lastIndex != 0 && $index == $lastIndex + 1){ if($lastIndex != 0 && $index == $lastIndex + 1){
$dateDebut = $model->getDateDebut($idPartie); $dateDebut = $model->getDateDebut($idPartie);
$points = $model->getPointsAtTheEnd($utilisateur->getEmail(), $idPartie);
require($rep . $vues['gameEnd']); require($rep . $vues['gameEnd']);
} }
else{ else{

@ -33,13 +33,23 @@ class UserModel
$this->partie_gateway->createPartieMulti($lesEnigmes, $mailUtilisateur); $this->partie_gateway->createPartieMulti($lesEnigmes, $mailUtilisateur);
$idPartie=$this->partie_gateway->findPartieInQueue(); $idPartie=$this->partie_gateway->findPartieInQueue();
$etat=$this->partie_gateway->getEtat($idPartie); $etat=$this->partie_gateway->getEtat($idPartie);
return array($idPartie, $etat);
} }
else{ else{
$this->partie_gateway->addToPartie($mailUtilisateur, $idPartie); $this->partie_gateway->addToPartie($mailUtilisateur, $idPartie);
$etat=$this->partie_gateway->getEtat($idPartie); $etat=$this->partie_gateway->getEtat($idPartie);
}
$tpsMaxPartie = $this->calculTpsMaXPartie($idPartie);
$_SESSION['tpsMaxPartie'] = $tpsMaxPartie;
return array($idPartie, $etat); return array($idPartie, $etat);
} }
public function calculTpsMaXPartie( int $idPartie) : int {
$lesIdEnigmes = $this->partie_gateway->findAllEnigmeIdInPartie($idPartie);
foreach ($lesIdEnigmes as $idEnigme){
$enigme = $this->enigme_gateway->findById($idEnigme)[0];
$tpsMaxPartie += $enigme->getTempsDeResolution();
}
return $tpsMaxPartie;
} }
public function findUserGroup() : int { public function findUserGroup() : int {
@ -95,8 +105,20 @@ class UserModel
return $this->resoudre_gateway->checkEnigmeIsEnded($mailUtilisateur,$enigmeId); return $this->resoudre_gateway->checkEnigmeIsEnded($mailUtilisateur,$enigmeId);
} }
public function enigmeEnded(string $mailUtilisateur, int $enigmeId){ public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId){
$this->resoudre_gateway->enigmeEnded($mailUtilisateur,$enigmeId); $idPartie = $_SESSION['idPartie'];
$dateDebut = $this->partie_gateway->getDateDebut($idPartie);
$now = new DateTime();
$interval = $now->diff($dateDebut);
$tempDeResolution = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s;
$result = $this->resoudre_gateway->getMaxClassement($enigmeId, $idPartie);
if ($result == 0){
$classement = 1;
}
else{
$classement = $result + 1;
}
$this->resoudre_gateway->enigmeMultiEnded($mailUtilisateur,$enigmeId, $tempDeResolution, $classement);
} }
public function saveCode(string $mailUtilisateur, int $enigmeId,string $code ){ public function saveCode(string $mailUtilisateur, int $enigmeId,string $code ){
@ -151,4 +173,21 @@ class UserModel
public function getDateDebut($idPartie) : DateTime{ public function getDateDebut($idPartie) : DateTime{
return $this->partie_gateway->getDateDebut($idPartie); return $this->partie_gateway->getDateDebut($idPartie);
} }
public function getPointsAtTheEnd(string $mailUtilisateur, int $idPartie) : int{
$points = 0;
$result = $this->resoudre_gateway->getAllByPartieAndUtilisateur($mailUtilisateur, $idPartie);
foreach ($result as $row){
if ($row['classement'] == 1){
$points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints();
}
else if ($row['classement'] == 2){
$points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints() * 0.75;
}
else{
$points += $this->enigme_gateway->findById($row['enigme'])[0]->getPoints() * 0.5;
}
}
return $points;
}
} }

@ -19,9 +19,10 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<p>Vous avez terminer toute les énimges.</p> <p>Vous avez terminer toute les énimges.</p>
<p>Votre score est de : <?php echo $points ?> points.</p>
<p>Temps restant avant la fin de la partie :</p> <p>Temps restant avant la fin de la partie :</p>
<?php <?php
$end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'minutes'); $end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'seconds');
$now = new DateTime(); $now = new DateTime();
$interval = $now->diff($end_time); $interval = $now->diff($end_time);
$remaining_seconds = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s; $remaining_seconds = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s;
@ -42,7 +43,7 @@
if (remainingSeconds < 10) { if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds; remainingSeconds = "0" + remainingSeconds;
} }
document.getElementById('countdown').innerHTML = days + " jours " + hours + " heures " + minutes + " minutes " + remainingSeconds + " secondes"; document.getElementById('countdown').innerHTML = hours + " heures " + minutes + " minutes " + remainingSeconds + " secondes";
if (seconds == 0) { if (seconds == 0) {
clearInterval(countdown); clearInterval(countdown);
document.getElementById('countdown').innerHTML = "Expired"; document.getElementById('countdown').innerHTML = "Expired";

Loading…
Cancel
Save