From 1ee2ccd147d58cf0cea708326f7672423341d856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 16:49:44 +0100 Subject: [PATCH] =?UTF-8?q?Changement=20d'affichage=20+=20Passage=20en=20s?= =?UTF-8?q?econde=20+=20Ajout=20du=20temps=20qu'a=20mis=20l'utilisateur=20?= =?UTF-8?q?pour=20r=C3=A9soudre=20l'=C3=A9nigme=20dans=20a=20bd=20+=20Calc?= =?UTF-8?q?ule=20du=20classement=20en=20bd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/ResoudreGateway.php | 43 +++++++++++++++++++++- WEB/Controller/UserController.php | 2 +- WEB/Model/UserModel.php | 16 +++++++- WEB/View/src/pages/Multijoueur/GameEnd.php | 4 +- 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index addce10f..6b350325 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -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']; + } } \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index f61d6912..ded2d137 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -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) { diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 09d2f6e5..5a0ca9f1 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -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 ){ diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php index a3974740..aa7cc6f8 100644 --- a/WEB/View/src/pages/Multijoueur/GameEnd.php +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -21,7 +21,7 @@

Vous avez terminer toute les énimges.

Temps restant avant la fin de la partie :

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";