Changement d'affichage +

Passage en seconde +
Ajout du temps qu'a mis l'utilisateur pour résoudre l'énigme dans a bd +
Calcule du classement en bd
ServeurDeTest
Noé GARNIER 2 years ago
parent fb503a7c1d
commit 1ee2ccd147

@ -168,6 +168,34 @@ class ResoudreGateway
"enigme" => array($enigmeId, 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){
$query="UPDATE Resoudre
@ -216,7 +244,6 @@ class ResoudreGateway
WHERE utilisateur=:utilisateur
AND ended=:ended
ORDER BY ended DESC LIMIT 1";
// $query = "SELECT * FROM Partie ORDER BY id DESC LIMIT 1";
$this->con->executeQuery($query, array(
"utilisateur" => array($mailUtilisateur, SQLITE3_TEXT),
"ended" => array(1, SQLITE3_INTEGER)));
@ -241,4 +268,18 @@ class ResoudreGateway
}
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'];
}
}

@ -190,7 +190,7 @@ class UserController
$index = $_REQUEST['index'];
$enigme = $model->getEnigmebyPartieIdAndIndex($_SESSION['idPartie'],$index);
$utilisateur=$_SESSION['utilisateur'];
$model->enigmeEnded($utilisateur->getEmail(),$enigme->getIdEnigme());
$model->enigmeMultiEnded($utilisateur->getEmail(),$enigme->getIdEnigme());
$index = $index + 1;
header("Location: index.php?action=goToGame&idPartie=" . $_SESSION['idPartie'] . "&index=". $index);
} catch (Exception $e) {

@ -95,8 +95,20 @@ class UserModel
return $this->resoudre_gateway->checkEnigmeIsEnded($mailUtilisateur,$enigmeId);
}
public function enigmeEnded(string $mailUtilisateur, int $enigmeId){
$this->resoudre_gateway->enigmeEnded($mailUtilisateur,$enigmeId);
public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId){
$end_time = $_SESSION['tpsMaxPartie'];
$now = new DateTime();
$interval = $now->diff($end_time);
$tempDeResolution = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s;
$idPartie = $_SESSION['idPartie'];
$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 ){

@ -21,7 +21,7 @@
<p>Vous avez terminer toute les énimges.</p>
<p>Temps restant avant la fin de la partie :</p>
<?php
$end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'minutes');
$end_time = $dateDebut->modify('+'. $_SESSION['tpsMaxPartie'] .'seconds');
$now = new DateTime();
$interval = $now->diff($end_time);
$remaining_seconds = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s;
@ -42,7 +42,7 @@
if (remainingSeconds < 10) {
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) {
clearInterval(countdown);
document.getElementById('countdown').innerHTML = "Expired";

Loading…
Cancel
Save