From 61929cfd659d11151a38e485a480ed70fb93428c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Fri, 13 Jan 2023 13:30:12 +0100 Subject: [PATCH] Annualtion de changement --- WEB/Config/Config.php | 2 +- WEB/Controller/ResoudreGateway.php | 11 ++++------ WEB/Model/UserModel.php | 34 ++++-------------------------- 3 files changed, 9 insertions(+), 38 deletions(-) diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 1bc9f965..fce1d390 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -53,6 +53,6 @@ $error = ""; // Server $serverAdress = "82.165.180.114"; $playerNumberPerGame = 2; -$nbEnigmePerGame = 1; +$nbEnigmePerGame = 2; diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index c0a54661..beedb8a7 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -291,22 +291,19 @@ class ResoudreGateway } return $results[0]['max(indexEnigme)']; } - public function getClassement($enigmeId, $idPartie) : array{ + public function getMaxClassement($enigmeId, $idPartie) : int{ $query="SELECT classement FROM Resoudre WHERE enigme=:enigme AND partie=:partie - ORDER BY classement"; + 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 array(0); - } - foreach ($results as $row){ - $classment[] = $row['classement']; + return 0; } - return $classment; + return $results[0]['classement']; } public function getAllByPartieAndUtilisateur(string $mailUtilisateur, int $idPartie) : array{ diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 8ef8598b..7b679d5f 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -118,44 +118,18 @@ class UserModel public function enigmeEnded(string $mailUtilisateur, int $enigmeId){ $this->resoudre_gateway->enigmeEnded($mailUtilisateur,$enigmeId); } - - public function largest_consecutive_number($list) { - sort($list); - $largest = 0; - $missing = 0; - for ($i = 0; $i < count($list) - 1; $i++) { - if ($list[$i] + 1 != $list[$i + 1]) { - if ($list[$i] > $largest) { - $largest = $list[$i]; - } - if ($missing == 0) { - $missing = $list[$i] + 1; - } - } else { - if ($list[$i] > $largest) { - $largest = $list[$i]; - } - } - } - if ($missing != 0) { - return $missing; - } else { - return $largest + 1; - } - } - public function enigmeMultiEnded(string $mailUtilisateur, int $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; - $leClassement = $this->resoudre_gateway->getClassement($enigmeId, $idPartie); - if ($leClassement[0] == 0){ - $classement = 3; + $result = $this->resoudre_gateway->getMaxClassement($enigmeId, $idPartie); + if ($result == 0){ + $classement = 1; } else{ - $classement = 2; + $classement = $result + 1; } $this->resoudre_gateway->enigmeMultiEnded($mailUtilisateur,$enigmeId, $tempDeResolution, $classement); }