From d402bddb81c2864ded8628dc586109b8a58afd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 17:06:04 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9l=C3=A9guations=20du=20calcul=20du=20tem?= =?UTF-8?q?ps=20max=20par=20partie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/PartieGateway.php | 17 ++++++++++++++--- WEB/Model/UserModel.php | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 35d6f795..b927e860 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -161,7 +161,6 @@ class PartieGateway ) ); $partie = $this->findLastPartie(); - $tpsMaxPartie = 0; $query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,1)"; foreach ($lesEnigmes as $enigme) { $this->con->executeQuery($query, array( @@ -169,9 +168,7 @@ class PartieGateway "idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER) ) ); - $tpsMaxPartie += $enigme->getTempsDeResolution(); } - $_SESSION['tpsMaxPartie'] = $tpsMaxPartie; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $this->con->executeQuery($query, array( "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), @@ -320,6 +317,20 @@ class PartieGateway $row = $results[0]; 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{ $query = "SELECT dateDebut FROM Partie WHERE id = :idPartie"; $this->con->executeQuery($query, array( diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 5a0ca9f1..7ac9870f 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -33,18 +33,28 @@ class UserModel $this->partie_gateway->createPartieMulti($lesEnigmes, $mailUtilisateur); $idPartie=$this->partie_gateway->findPartieInQueue(); $etat=$this->partie_gateway->getEtat($idPartie); - return array($idPartie, $etat); } else{ $this->partie_gateway->addToPartie($mailUtilisateur, $idPartie); $etat=$this->partie_gateway->getEtat($idPartie); - return array($idPartie, $etat); } + $tpsMaxPartie = $this->calculTpsMaXPartie($idPartie); + $_SESSION['tpsMaxPartie'] = $tpsMaxPartie; + return array($idPartie, $etat); } - public function findUserGroup() : int { - return $this->partie_gateway->findPartieInQueue(); + public function calculTpsMaXPartie( int $idPartie) : int { + $lesIdEnigmes = $this->partie_gateway->findAllEnigmeIdInPartie($idPartie); + foreach ($lesIdEnigmes as $idEnigme){ + $enigme = $this->enigme_gateway->findById($idEnigme->getIdEnigme())[0]; + $tpsMaxPartie += $enigme->getTempsMax(); } + return $tpsMaxPartie; + } + + public function findUserGroup() : int { + return $this->partie_gateway->findPartieInQueue(); + } public function launchGame() {