Gestion de la table résoudre en multi
continuous-integration/drone/push Build is passing Details

ServeurDeTest
Noé GARNIER 2 years ago
parent adbe137e76
commit 9d0658013d

@ -316,6 +316,17 @@ class PartieGateway
} }
return $lesEnigmes; return $lesEnigmes;
} }
public function getIndex(int $idPartie, int $idEnigme){
$query = "SELECT * FROM Contenir WHERE partie = :idPartie AND enigme = :idEnigme";
$this->con->executeQuery($query, array(
"idPartie" => array($idPartie, SQLITE3_INTEGER),
"idEnigme" => array($idEnigme, SQLITE3_INTEGER)
)
);
$results = $this->con->getResults();
$row = $results[0];
return $row['index'];
}
public function showAll(): void public function showAll(): void
{ {
$query = "SELECT * FROM Partie"; $query = "SELECT * FROM Partie";

@ -78,6 +78,53 @@ class ResoudreGateway
"ended" => array($ended, SQLITE3_INTEGER))); "ended" => array($ended, SQLITE3_INTEGER)));
} }
} }
public function resoudreEnigmeMulti(Utilisateur $utilisateur, int $enigmeId, int $partieId, int $index){
$query="SELECT * FROM Resoudre
WHERE utilisateur=:utilisateur
AND enigme=:enigme";
$this->con->executeQuery($query, array(
"utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT),
"enigme" => array($enigmeId, SQLITE3_INTEGER)));
$results=$this->con->getResults();
if(empty($results))
{
$temps = 1;
$code = "";
$ended = false;
$query="INSERT INTO Resoudre VALUES (:utilisateur, :enigme,:partie,:classement,:index,:temps,:code,:ended,:enMulti)";
$this->con->executeQuery($query, array(
"utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT),
"enigme" => array($enigmeId, SQLITE3_INTEGER),
"partie" => array($partieId, SQLITE3_INTEGER),
"classement" => array(NULL, SQLITE3_NULL),
"index" => array($index, SQLITE3_NULL),
"temps" => array($temps, SQLITE3_FLOAT),
"code" => array($code, SQLITE3_TEXT),
"ended" => array($ended, SQLITE3_INTEGER),
"enMulti" => array(1, SQLITE3_INTEGER)));
}
else
{
$query = "SELECT * FROM Resoudre WHERE utilisateur=:utilisateur AND enigme=:enigme";
$this->con->executeQuery($query, array(
"utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT),
"enigme" => array($enigmeId, SQLITE3_INTEGER)));
$results = $this->con->getResults();
$temps = $results[0]['temps'];
$code = $results[0]['code'];
$ended = $results[0]['ended'];
$query="UPDATE Resoudre
SET temps=:temps, code=:code, ended=:ended
WHERE utilisateur=:utilisateur
AND enigme=:enigme";
$this->con->executeQuery($query, array(
"utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT),
"enigme" => array($enigmeId, SQLITE3_INTEGER),
"temps" => array($temps, SQLITE3_FLOAT),
"code" => array($code, SQLITE3_TEXT),
"ended" => array($ended, SQLITE3_INTEGER)));
}
}
public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId){ public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId){
$query="SELECT * FROM Resoudre $query="SELECT * FROM Resoudre
WHERE utilisateur=:utilisateur WHERE utilisateur=:utilisateur

@ -211,6 +211,8 @@ class UserController
$model = new UserModel(); $model = new UserModel();
$utilisateur = $_SESSION['utilisateur']; $utilisateur = $_SESSION['utilisateur'];
$enigme = $model->getEnigmebyPartieId($idPartie)[0]; $enigme = $model->getEnigmebyPartieId($idPartie)[0];
$model->resoudreEnigmeMulti($utilisateur, $enigme->getIdEnigme(), $idPartie,);
$code = $model->getCode($utilisateur->getEmail(), $enigme->getIdEnigme());
require($rep . $vues['partie']); require($rep . $vues['partie']);
} catch (Exception $e) { } catch (Exception $e) {
$error = $e->getMessage(); $error = $e->getMessage();

@ -86,6 +86,10 @@ class UserModel
} }
$this->resoudre_gateway->resoudreEnigmeSolo($utilisateur, $enigmeId, $partieId); $this->resoudre_gateway->resoudreEnigmeSolo($utilisateur, $enigmeId, $partieId);
} }
public function resoudreEnigmeMulti(Utilisateur $utilisateur, int $enigmeId, int $idPartie){
$index = $this->partie_gateway->getIndex($idPartie, $enigmeId);
$this->resoudre_gateway->resoudreEnigmeMulti($utilisateur, $enigmeId, $idPartie, $index);
}
public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId) : bool { public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId) : bool {
return $this->resoudre_gateway->checkEnigmeIsEnded($mailUtilisateur,$enigmeId); return $this->resoudre_gateway->checkEnigmeIsEnded($mailUtilisateur,$enigmeId);
} }

@ -0,0 +1,147 @@
function run() {
const terminal = document.getElementById("console");
const runner = new BrythonRunner({
stdout: {
write(content) {
terminal.innerHTML += content;
terminal.scrollTop = terminal.scrollHeight;
},
flush() {},
},
stderr: {
write(content) {
terminal.innerHTML += content;
terminal.scrollTop = terminal.scrollHeight;
},
flush() {},
},
stdin: {
async readline() {
terminal.innerHTML += "\n";
terminal.scrollTop = terminal.scrollHeight;
var userInput = prompt();
return userInput;
},
flush() {},
},
});
var code = editor.getValue();
runner.runCode(code);
setTimeout(() => {
runner.stopRunning();
}, 10 * 1000);
}
function run_init() {
if (document.getElementById("console") != "") {
document.getElementById("console").innerHTML = "";
}
run();
}
var editor = ace.edit("editor");
editor.container.style.opacity = 0.85;
editor.setTheme("ace/theme/vibrant_ink");
editor.getSession().setMode("ace/mode/python");
editor.setFontSize("16px");
editor.setOptions({
enableLiveAutocompletion: true,
copyWithEmptySelection: true,
showGutter: true,
useWrapMode: true, // wrap text to view
indentedSoftWrap: false,
});
//Function that execute given code and return the result in a given element by id
function exec(code, id) {
const terminal = document.getElementById("console");
terminal.innerHTML = "";
const runner = new BrythonRunner({
stdout: {
write(content) {
if (id == "code") {
retourCode = content;
}
if (id == "solution") {
retourSolution = content;
}
},
flush() {},
},
stderr: {
write(content) {
if (id == "solution") {
retourSolution = "ERROR";
}
terminal.innerHTML += content;
terminal.scrollTop = terminal.scrollHeight;
},
flush() {},
},
stdin: {
async readline() {
terminal.innerHTML += "\n";
terminal.scrollTop = terminal.scrollHeight;
var userInput = prompt();
return userInput;
},
flush() {},
},
});
runner.runCode(code);
setTimeout(() => {
runner.stopRunning();
}, 10 * 1000);
}
/**
* It checks if the code in the editor as the same result as the solution.
*/
function check() {
if (retourSolution == "ERROR") {
result.innerHTML = "Il semblerait qu'il y a une erreur dans ton code :/";
} else if (retourSolution == retourCode) {
result.innerHTML = "Bien joué";
document.getElementById("next").style.display = "flex";
} else {
result.innerHTML = "Mauvaise réponse";
}
}
/**
* If the help is displayed, hide it. Otherwise, display it.
*/
function displayHelp() {
var help = document.getElementsByClassName("help");
if (help[0].style.display == "block") {
for (var i = 0; i < help.length; i++) {
help[i].style.display = "none";
}
return;
}
for (var i = 0; i < help.length; i++) {
help[i].style.display = "block";
}
}
// 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);

@ -29,7 +29,7 @@
<a class="material-icons pl-0" id="home" href="index.php?action=goToHome" <a class="material-icons pl-0" id="home" href="index.php?action=goToHome"
style="font-size: 40px; color: white">home</a> style="font-size: 40px; color: white">home</a>
</div> </div>
<div class="col-1 d-flex align-items-center justify-content-end px-0"> <!-- <div class="col-1 d-flex align-items-center justify-content-end px-0">
<a class="material-icons pl-0" id="backArrow" <a class="material-icons pl-0" id="backArrow"
href="index.php?action=goToEnigme&ordre=<?php href="index.php?action=goToEnigme&ordre=<?php
if ($enigme->getOrdre() == 1) if ($enigme->getOrdre() == 1)
@ -46,7 +46,7 @@
<a class="material-icons pl-0" id="nextArrow" <a class="material-icons pl-0" id="nextArrow"
href="index.php?action=goToEnigme&ordre=<?php echo $enigme->getOrdre() + 1; ?>" href="index.php?action=goToEnigme&ordre=<?php echo $enigme->getOrdre() + 1; ?>"
style="font-size: 40px; color: white">&nbsp; ></a> style="font-size: 40px; color: white">&nbsp; ></a>
</div> </div> -->
<button style="background-color: transparent; border: none; outline: none;" onclick="displayHelp()" <button style="background-color: transparent; border: none; outline: none;" onclick="displayHelp()"
class="col-5 d-flex align-items-center"> class="col-5 d-flex align-items-center">
<div class="col-10 text-right px-3"> <div class="col-10 text-right px-3">
@ -166,7 +166,7 @@
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/base.js"></script> <script src="View/src/JS/baseMulti.js"></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