diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index f814afa7..ccb67a5a 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -1,4 +1,5 @@ con->executeQuery($query, array( - "idPartie" => array($idPartie, SQLITE3_INTEGER) + "idPartie" => array($idPartie, SQLITE3_INTEGER), + "index" => array($index, SQLITE3_INTEGER) ) ); $results = $this->con->getResults(); - $lesEnigmes = array(); - foreach ($results as $row){ - $lesEnigmes[] = $row['enigme']; - } - return $lesEnigmes; + $row = $results[0]; + return $row['enigme']; + } public function getIndex(int $idPartie, int $idEnigme){ $query = "SELECT * FROM Contenir WHERE partie = :idPartie AND enigme = :idEnigme"; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 718e489e..ab1abce0 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -190,14 +190,14 @@ class UserController $lesJoueurs = $model->getLesJoueurs($idPartie); if($etat == 1){ // header("Location: index.php?action=launchGame"); - $this->goToGame($idPartie); + $this->goToGame($idPartie,1); } else{ while ($etat == 0){ sleep(5); $etat = $model->getEtatPartie($idPartie); } - $this->goToGame($idPartie); + $this->goToGame($idPartie,1); } } catch (Exception $e) { $error = $e->getMessage(); @@ -205,12 +205,12 @@ class UserController } } - public function goToGame($idPartie){ + public function goToGame(int $idPartie, int $index){ try { global $rep, $vues, $error; $model = new UserModel(); $utilisateur = $_SESSION['utilisateur']; - $enigme = $model->getEnigmebyPartieId($idPartie)[0]; + $enigme = $model->getEnigmebyPartieIdAndIndex($idPartie, $index); $model->resoudreEnigmeMulti($utilisateur, $enigme->getIdEnigme(), $idPartie,); $code = $model->getCode($utilisateur->getEmail(), $enigme->getIdEnigme()); require($rep . $vues['partie']); diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 08424ae1..c96e0da4 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -127,12 +127,12 @@ class UserModel return $lesJoueurs; } - public function getEnigmebyPartieId($idPartie){ - $lesIdEnigmes = $this->partie_gateway->findAllEnigmeIdInPartie($idPartie); - $lesEnigmes = array(); - foreach ($lesIdEnigmes as $id){ - $lesEnigmes[] = $this->enigme_gateway->findById($id)[0]; - } - return $lesEnigmes; + public function getEnigmebyPartieIdAndIndex($idPartie, $index) : Enigme{ + $idEnigme = $this->partie_gateway->findEnigmeIdInPartieWithIndex($idPartie, $index); + return $this->enigme_gateway->findById($idEnigme)[0]; + } + + public function getIndex($mailUtilisateur, $idPartie){ + return $this->partie_gateway->getIndex($idPartie, $mailUtilisateur); } } \ No newline at end of file diff --git a/WEB/View/src/JS/baseMulti.js b/WEB/View/src/JS/baseMulti.js index 2e371ce5..06dea3e2 100644 --- a/WEB/View/src/JS/baseMulti.js +++ b/WEB/View/src/JS/baseMulti.js @@ -129,19 +129,19 @@ function run() { } } -// function saveCode() { -// var xhr = new XMLHttpRequest(); -// // xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCode', true); -// xhr.open('POST', 'http://82.165.180.114/Scripted/WEB/index.php?action=saveCode', true); -// xhr.responseType = 'text'; -// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); -// xhr.onload = function () { -// // console.log('saveCode'+xhr.responseText); -// }; -// var searchParams = new URLSearchParams(window.location.search); -// var ordre = searchParams.get('ordre'); -// xhr.send("code=" + editor.getValue() + "&ordre=" + ordre); -// } + function saveCode() { + var xhr = new XMLHttpRequest(); + // xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCode', true); + xhr.open('POST', 'http://82.165.180.114/Scripted/WEB/index.php?action=saveCode', true); + xhr.responseType = 'text'; + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.onload = function () { + // console.log('saveCode'+xhr.responseText); + }; + var searchParams = new URLSearchParams(window.location.search); + var ordre = searchParams.get('ordre'); + xhr.send("code=" + editor.getValue() + "&ordre=" + ordre); + } -// document.getElementById ('editor').addEventListener('input', saveCode); + document.getElementById ('editor').addEventListener('input', saveCode); \ No newline at end of file diff --git a/WEB/View/src/pages/Multijoueur/Partie.php b/WEB/View/src/pages/Multijoueur/Partie.php index 6b5668a3..505569f1 100644 --- a/WEB/View/src/pages/Multijoueur/Partie.php +++ b/WEB/View/src/pages/Multijoueur/Partie.php @@ -66,7 +66,7 @@