Test saveCodeMulti
continuous-integration/drone/push Build is passing Details

ServeurDeTest
Noé GARNIER 2 years ago
parent 8ae934130a
commit 2b618ded52

@ -179,6 +179,20 @@ class ResoudreGateway
"enigme" => array($enigmeId, SQLITE3_INTEGER), "enigme" => array($enigmeId, SQLITE3_INTEGER),
"code" => array($code, SQLITE3_TEXT))); "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{ public function getCode(string $mailUtilisateur, int $enigmeId) : string{
$query="SELECT * FROM Resoudre $query="SELECT * FROM Resoudre
WHERE utilisateur=:utilisateur WHERE utilisateur=:utilisateur

@ -46,6 +46,9 @@ class UserController
case "saveCode": case "saveCode":
$this->saveCode(); $this->saveCode();
break; break;
case "saveCodeMulti":
$this->saveCodeMulti();
break;
case "saveCodeInCookie": case "saveCodeInCookie":
$this->saveCodeInCookie(); $this->saveCodeInCookie();
break; break;
@ -187,6 +190,7 @@ class UserController
$reponse = $model->addToQueue($utilisateur->getEmail()); $reponse = $model->addToQueue($utilisateur->getEmail());
$etat = $reponse[1]; $etat = $reponse[1];
$idPartie = $reponse[0]; $idPartie = $reponse[0];
$_SESSION['idPartie'] = $idPartie;
$lesJoueurs = $model->getLesJoueurs($idPartie); $lesJoueurs = $model->getLesJoueurs($idPartie);
if($etat == 1){ if($etat == 1){
// header("Location: index.php?action=launchGame"); // header("Location: index.php?action=launchGame");
@ -254,6 +258,23 @@ class UserController
require($rep . $vues['erreur']); 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(){ public function saveCodeInCookie(){
try { try {
global $rep, $vues, $error; global $rep, $vues, $error;

@ -1,4 +1,5 @@
<?php <?php
use Random\Engine;
class UserModel class UserModel
{ {
@ -101,6 +102,9 @@ class UserModel
public function saveCode(string $mailUtilisateur, int $enigmeId,string $code ){ public function saveCode(string $mailUtilisateur, int $enigmeId,string $code ){
$this->resoudre_gateway->saveCode($mailUtilisateur, $enigmeId, $code); $this->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){ public function getCode(string $mailUtilisateur, int $enigmeId){
return $this->resoudre_gateway->getCode($mailUtilisateur, $enigmeId); return $this->resoudre_gateway->getCode($mailUtilisateur, $enigmeId);
@ -135,4 +139,8 @@ class UserModel
public function getIndex($mailUtilisateur, $idPartie){ public function getIndex($mailUtilisateur, $idPartie){
return $this->partie_gateway->getIndex($idPartie, $mailUtilisateur); return $this->partie_gateway->getIndex($idPartie, $mailUtilisateur);
} }
public function findEnigmeById(int $enigmeId) : Engine{
return $this->enigme_gateway->findById($enigmeId)[0];
}
} }

@ -129,19 +129,16 @@ function run() {
} }
} }
function saveCode() { function saveCode(index, enigmeId) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
// xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCode', true); // 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.responseType = 'text';
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function () { xhr.onload = function () {
// console.log('saveCode'+xhr.responseText); // console.log('saveCode'+xhr.responseText);
}; };
var searchParams = new URLSearchParams(window.location.search); var searchParams = new URLSearchParams(window.location.search);
var ordre = searchParams.get('ordre'); xhr.send("code=" + editor.getValue() + "&index=" + index, "&enigmeId=" + enigmeId);
xhr.send("code=" + editor.getValue() + "&ordre=" + ordre);
} }
document.getElementById ('editor').addEventListener('input', saveCode);

@ -66,7 +66,7 @@
<div class="col-3 rounded p-3" style="background-color: #222831; min-height: 80vh; height: auto"> <div class="col-3 rounded p-3" style="background-color: #222831; min-height: 80vh; height: auto">
<h2 class="text-left py-3" style="color: #44fff6; font-weight: 500"> <h2 class="text-left py-3" style="color: #44fff6; font-weight: 500">
<?php <?php
echo $index; echo $enigme->getNom();
?> ?>
</h2> </h2>
<p> <p>
@ -166,7 +166,11 @@
charset="utf-8"></script> charset="utf-8"></script>
<script src="https://raw.githack.com/pythonpad/brython-runner/master/lib/brython-runner.bundle.js" <script src="https://raw.githack.com/pythonpad/brython-runner/master/lib/brython-runner.bundle.js"
type="text/javascript" charset="utf-8"></script> type="text/javascript" charset="utf-8"></script>
<script src="View/src/JS/baseMulti.js"></script> <script src="View/src/JS/baseMulti.js">
var index = '<?php echo $index; ?>';
var enigmeId = '<?php echo $enigme->getIdEnigme(); ?>';
document.getElementById ('editor').addEventListener('input', saveCode(index, enigmeId));
</script>
<?php <?php
echo '<script src="View/src/JS/' . $enigme->getNom() . '.js"></script>'; echo '<script src="View/src/JS/' . $enigme->getNom() . '.js"></script>';
?> ?>

Loading…
Cancel
Save