From 2b618ded5222310e5151702e5c9986713bbd187b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Tue, 10 Jan 2023 07:26:07 +0100 Subject: [PATCH] Test saveCodeMulti --- WEB/Controller/ResoudreGateway.php | 14 ++++++++++++++ WEB/Controller/UserController.php | 21 +++++++++++++++++++++ WEB/Model/UserModel.php | 8 ++++++++ WEB/View/src/JS/baseMulti.js | 9 +++------ WEB/View/src/pages/Multijoueur/Partie.php | 8 ++++++-- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/WEB/Controller/ResoudreGateway.php b/WEB/Controller/ResoudreGateway.php index f13cc216..db351748 100644 --- a/WEB/Controller/ResoudreGateway.php +++ b/WEB/Controller/ResoudreGateway.php @@ -179,6 +179,20 @@ class ResoudreGateway "enigme" => array($enigmeId, SQLITE3_INTEGER), "code" => array($code, SQLITE3_TEXT))); } + public function saveCodeMulti(string $mailUtilisateur, int $enigmeId, int $idPartie, int $index,string $code){ + $query="UPDATE Resoudre + SET code=:code + WHERE utilisateur=:utilisateur + AND enigme=:enigme + AND partie=:partie + AND indexEnigme=:index"; + $this->con->executeQuery($query, array( + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT), + "enigme" => array($enigmeId, SQLITE3_INTEGER), + "partie" => array($idPartie, SQLITE3_INTEGER), + "index" => array($index, SQLITE3_INTEGER), + "code" => array($code, SQLITE3_TEXT))); + } public function getCode(string $mailUtilisateur, int $enigmeId) : string{ $query="SELECT * FROM Resoudre WHERE utilisateur=:utilisateur diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index ab1abce0..562ed042 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -46,6 +46,9 @@ class UserController case "saveCode": $this->saveCode(); break; + case "saveCodeMulti": + $this->saveCodeMulti(); + break; case "saveCodeInCookie": $this->saveCodeInCookie(); break; @@ -187,6 +190,7 @@ class UserController $reponse = $model->addToQueue($utilisateur->getEmail()); $etat = $reponse[1]; $idPartie = $reponse[0]; + $_SESSION['idPartie'] = $idPartie; $lesJoueurs = $model->getLesJoueurs($idPartie); if($etat == 1){ // header("Location: index.php?action=launchGame"); @@ -254,6 +258,23 @@ class UserController require($rep . $vues['erreur']); } } + public function saveCodeMulti(){ + try { + global $rep, $vues, $error; + $model = new UserModel(); + $code = $_POST['code']; + $index = $_POST['index']; + $idEnigme = $_POST['idEnigme']; + $utilisateur=$_SESSION['utilisateur']; + $idPartie = $_SESSION['idPartie']; + $model->saveCodeMulti($utilisateur->getEmail(),$idEnigme, $idPartie, $index,$code); + echo $code; + } + catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } public function saveCodeInCookie(){ try { global $rep, $vues, $error; diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index c96e0da4..4a1215e9 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -1,4 +1,5 @@ resoudre_gateway->saveCode($mailUtilisateur, $enigmeId, $code); } + public function saveCodeMulti(string $mailUtilisateur, int $enigmeId, int $idPartie, int $index,string $code ){ + $this->resoudre_gateway->saveCodeMulti($mailUtilisateur, $enigmeId, $idPartie , $index, $code); + } public function getCode(string $mailUtilisateur, int $enigmeId){ return $this->resoudre_gateway->getCode($mailUtilisateur, $enigmeId); @@ -135,4 +139,8 @@ class UserModel public function getIndex($mailUtilisateur, $idPartie){ return $this->partie_gateway->getIndex($idPartie, $mailUtilisateur); } + + public function findEnigmeById(int $enigmeId) : Engine{ + return $this->enigme_gateway->findById($enigmeId)[0]; + } } \ No newline at end of file diff --git a/WEB/View/src/JS/baseMulti.js b/WEB/View/src/JS/baseMulti.js index 06dea3e2..677e7025 100644 --- a/WEB/View/src/JS/baseMulti.js +++ b/WEB/View/src/JS/baseMulti.js @@ -129,19 +129,16 @@ function run() { } } - function saveCode() { + function saveCode(index, enigmeId) { 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.open('POST', 'http://82.165.180.114/Scripted/WEB/index.php?action=saveCodeMulti', 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); + xhr.send("code=" + editor.getValue() + "&index=" + index, "&enigmeId=" + enigmeId); } - - 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 505569f1..ea17a2e8 100644 --- a/WEB/View/src/pages/Multijoueur/Partie.php +++ b/WEB/View/src/pages/Multijoueur/Partie.php @@ -66,7 +66,7 @@

getNom(); ?>

@@ -166,7 +166,11 @@ charset="utf-8"> - + getNom() . '.js">'; ?>