Implementation des enigmes solo et

du mode histoire en générique
ServeurDeTest
Noé GARNIER 2 years ago
parent 200f263ed9
commit 586b6aa733

@ -3,8 +3,8 @@
$rep =''; $rep ='';
// BD // BD
$dsn = './scripted.db'; // $dsn = './scripted.db';
// $dsn = 'C:\\wamp64\\www\\scripted.db'; $dsn = 'C:\\wamp64\\www\\scripted.db';
//Sel de hashage //Sel de hashage
$sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong";

@ -124,19 +124,20 @@ class AdminController extends UserController
$exemple = $_POST['exemple']; $exemple = $_POST['exemple'];
$test = $_POST['test']; $test = $_POST['test'];
$solution = $_POST['solution']; $solution = $_POST['solution'];
$prompt = $_POST['prompt'];
if (empty($nom) || empty($enonce) || empty($test) || empty($solution)) { if (empty($nom) || empty($enonce) || empty($test) || empty($solution)) {
throw new Exception("Les champs nom, enigme, test et solution doivent être remplis"); throw new Exception("Les champs nom, enigme, test et solution doivent être remplis");
} }
if (empty($aide)){ if (empty($aide)) {
$aide = "Il n'y a pas d'aide pour cette énigme"; $aide = "Il n'y a pas d'aide pour cette énigme";
} }
if (empty($rappel)){ if (empty($rappel)) {
$rappel = "Il n'y a pas de rappel pour cette énigme"; $rappel = "Il n'y a pas de rappel pour cette énigme";
} }
if (empty($exemple)){ if (empty($exemple)) {
$exemple = "Il n'y a pas d'exemple pour cette énigme"; $exemple = "Il n'y a pas d'exemple pour cette énigme";
} }
$enigme = $model->addNewEnigmeSolo($nom, $enonce, $aide, $rappel, $exemple, $test, $solution); $enigme = $model->addNewEnigmeSolo($nom, $enonce, $aide, $rappel, $exemple, $test, $solution, $prompt);
require($rep . $vues['enigmePage']); require($rep . $vues['enigmePage']);
} catch (Exception $e) { } catch (Exception $e) {
$error = $e->getMessage(); $error = $e->getMessage();

@ -35,7 +35,7 @@ class EnigmeGateway
*/ */
public function insert(Enigme $enigme) public function insert(Enigme $enigme)
{ {
$query = "INSERT INTO Enigme VALUES (NULL,:nom,:enonce,:aide,:rappel,:exemple,:solution,:test,:tempsDeResolution,:points)"; $query = "INSERT INTO Enigme VALUES (NULL,:nom,:enonce,:aide,:rappel,:exemple,:solution,:test, :ordre,:tempsDeResolution,:points, :prompt)";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':nom' => array($enigme->getNom(), SQLITE3_TEXT), ':nom' => array($enigme->getNom(), SQLITE3_TEXT),
':enonce' => array($enigme->getEnonce(), SQLITE3_TEXT), ':enonce' => array($enigme->getEnonce(), SQLITE3_TEXT),
@ -44,8 +44,10 @@ class EnigmeGateway
':exemple' => array($enigme->getExemple(), SQLITE3_TEXT), ':exemple' => array($enigme->getExemple(), SQLITE3_TEXT),
':solution' => array($enigme->getSolution(), SQLITE3_TEXT), ':solution' => array($enigme->getSolution(), SQLITE3_TEXT),
':test' => array($enigme->getTest(), SQLITE3_TEXT), ':test' => array($enigme->getTest(), SQLITE3_TEXT),
':ordre' => array($enigme->getOrdre(), SQLITE3_INTEGER),
':tempsDeResolution' => array($enigme->getTempsDeResolution(), SQLITE3_INTEGER), ':tempsDeResolution' => array($enigme->getTempsDeResolution(), SQLITE3_INTEGER),
':points' => array($enigme->getPoints(), SQLITE3_INTEGER) ':points' => array($enigme->getPoints(), SQLITE3_INTEGER),
':prompt' => array($enigme->getPrompt(), SQLITE3_TEXT)
)); ));
} }
@ -129,6 +131,16 @@ class EnigmeGateway
$tabEnigme=EnigmeFactory::create($results); $tabEnigme=EnigmeFactory::create($results);
return $tabEnigme; return $tabEnigme;
} }
public function findByOrdre(int $ordre) : array
{
$query = "SELECT * FROM Enigme WHERE ordre = :ordre";
$this->con->executequery($query,array(
':ordre' => array($ordre,SQLITE3_INTEGER)
));
$results = $this->con->getResults();
$tabEnigme=EnigmeFactory::create($results);
return $tabEnigme;
}
public function showAll(): void public function showAll(): void
{ {
$query = "SELECT * FROM Enigme"; $query = "SELECT * FROM Enigme";

@ -35,7 +35,7 @@ class FrontController
$_REQUEST['action'] = $action; $_REQUEST['action'] = $action;
new AdminController(); new AdminController();
} else if (method_exists('AdminController', $action) == false) { } else if (method_exists('AdminController', $action) == false) {
$error = "Action non valide " . $action; $error = "Action non valide" . $action;
require($rep . $view['erreur']); require($rep . $view['erreur']);
} else { } else {
//echo "action admin valide"; //echo "action admin valide";

@ -24,7 +24,7 @@ class UserController
case "goToTest": case "goToTest":
$this->goToTest(); $this->goToTest();
break; break;
case "goToChouette" : case "goToChouette":
$this->goToChouette(); $this->goToChouette();
break; break;
case "goToCesarEncrypt": case "goToCesarEncrypt":
@ -33,10 +33,10 @@ class UserController
case "goToCesarDecrypt": case "goToCesarDecrypt":
$this->goToCesarDecrypt(); $this->goToCesarDecrypt();
break; break;
case "goToChuckNorris" : case "goToChuckNorris":
$this->goToChuckNorris(); $this->goToChuckNorris();
break; break;
case "goToHanoi" : case "goToHanoi":
$this->goToHanoi(); $this->goToHanoi();
break; break;
case "goToTrianglePascal": case "goToTrianglePascal":
@ -96,12 +96,15 @@ class UserController
$error = $e->getMessage(); $error = $e->getMessage();
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
public function goToEnigme() public function goToEnigme()
{ {
try { try {
global $rep, $vues; global $rep, $vues;
require($rep . $vues['enigme']); $model = new UserModel();
$ordre = $_REQUEST['ordre'];
$enigme = $model->getEnigmeByOrdre($ordre);
require($rep . $vues['enigmePage']);
} catch (Exception $e) { } catch (Exception $e) {
$error = $e->getMessage(); $error = $e->getMessage();
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
@ -167,7 +170,7 @@ class UserController
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
public function goToDoubleElement() public function goToDoubleElement()
{ {
try { try {
global $rep, $vues; global $rep, $vues;
@ -183,7 +186,7 @@ class UserController
global $rep, $vues, $error; global $rep, $vues, $error;
$nettoyage = new Nettoyage(); $nettoyage = new Nettoyage();
$num = $nettoyage->cleanInt($_REQUEST['num']); $num = $nettoyage->cleanInt($_REQUEST['num']);
require($rep . $vues['next'].$num.".html"); require($rep . $vues['next'] . $num . ".html");
} catch (Exception $e) { } catch (Exception $e) {
$error = "Erreur Inconnue"; $error = "Erreur Inconnue";
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
@ -191,7 +194,7 @@ class UserController
} }
public function goToQueue() public function goToQueue()
{ {
try { try {
global $rep, $vues, $error; global $rep, $vues, $error;
//require($rep . $vues['Queue']); //require($rep . $vues['Queue']);
$model = new UserModel(); $model = new UserModel();

@ -5,7 +5,8 @@ class EnigmeFactory{
$tabEnigme=array(); $tabEnigme=array();
foreach($results as $row) foreach($results as $row)
{ {
$tabEnigme[]= new Enigme($row['id'],$row['nom'],$row['enonce'],$row['aide'],$row['rappel'],$row['exemple'],$row['solution'],$row['test'],$row['tempsDeResolution'],$row['points']); $tabEnigme[]= new Enigme($row['id'],$row['nom'],$row['enonce'],$row['aide'],$row['rappel'],
$row['exemple'],$row['solution'],$row['test'],$row['ordre'],$row['tempsDeResolution'],$row['points'], $row['prompt']);
} }
return $tabEnigme; return $tabEnigme;
} }

@ -10,8 +10,10 @@ class Enigme
private string $exemple; private string $exemple;
private string $solution; private string $solution;
private string $test; private string $test;
private int $ordre;
private int $tempsDeResolution; private int $tempsDeResolution;
private int $points; private int $points;
private string $prompt;
/** /**
* @param int $idEnigme * @param int $idEnigme
@ -22,10 +24,14 @@ class Enigme
* @param string $exemple * @param string $exemple
* @param string $solution * @param string $solution
* @param string $test * @param string $test
* @param int $ordre
* @param int $tempsDeResolution * @param int $tempsDeResolution
* @param int $points * @param int $points
* @param string $prompt
*/ */
public function __construct($idEnigme, $nom = "",$enonce = "", $aide = "", $rappel = "", $exemple = "",$solution = "", $test = "", $tempsDeResolution = 0, $points = 0) public function __construct($idEnigme, $nom = "",$enonce = "", $aide = "", $rappel = "",
$exemple = "",$solution = "", $test = "", $ordre = -1, $tempsDeResolution = 0, $points = 0,
$prompt = "")
{ {
$this->idEnigme = $idEnigme; $this->idEnigme = $idEnigme;
$this->nom = $nom; $this->nom = $nom;
@ -35,8 +41,10 @@ class Enigme
$this->exemple = $exemple; $this->exemple = $exemple;
$this->solution = $solution; $this->solution = $solution;
$this->test = $test; $this->test = $test;
$this->ordre = $ordre;
$this->tempsDeResolution = $tempsDeResolution; $this->tempsDeResolution = $tempsDeResolution;
$this->points = $points; $this->points = $points;
$this->prompt = $prompt;
} }
/** /**
* @return int * @return int
@ -165,6 +173,14 @@ class Enigme
{ {
$this->test = $test; $this->test = $test;
} }
public function getOrdre(): int
{
return $this->ordre;
}
public function setOrdre(int $ordre): void
{
$this->ordre = $ordre;
}
/** /**
* @return int * @return int
@ -189,4 +205,13 @@ class Enigme
{ {
$this->points = $points; $this->points = $points;
} }
public function getPrompt(): string
{
return $this->prompt;
}
public function setPrompt(string $prompt): void
{
$this->prompt = $prompt;
}
} }

@ -14,10 +14,17 @@ class AdminModel
$this->validation = new Validation(); $this->validation = new Validation();
} }
public function addNewEnigmeSolo(string $nom,string $enonce,string $aide,string $rappel,string $exemple,string $test,string $solution) : Enigme public function addNewEnigmeSolo(string $nom,string $enonce,string $aide,string $rappel,string $exemple,string $test,string $solution, string $prompt) : Enigme
{ {
$enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test); $last = $this->enigme_gateway->findLastEnigma();
if ($last !== null){
$ordre = $last[0]->getOrdre() + 1;
} else {
$ordre = 1;
}
$enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, 0, 0, $prompt);
$this->enigme_gateway->insert($enigme); $this->enigme_gateway->insert($enigme);
var_dump($enigme);
$tabEnigme = $this->enigme_gateway->findLastEnigma(); $tabEnigme = $this->enigme_gateway->findLastEnigma();
$js = fopen("View/src/JS/$nom.js", "w"); $js = fopen("View/src/JS/$nom.js", "w");
if (is_resource($js)) { if (is_resource($js)) {

@ -65,4 +65,13 @@ class UserModel
$_SESSION['role'] = 'visitor'; $_SESSION['role'] = 'visitor';
header('Location: index.php'); header('Location: index.php');
} }
public function getEnigmeByOrdre(int $num) : Enigme
{
$tabEnigme = $this->enigme_gateway->findByOrdre($num);
if ($tabEnigme == null) {
throw new Exception("Enigme non trouvée");
}
return $tabEnigme[0];
}
} }

@ -10,8 +10,8 @@ def chouetteVerif(valeur):
for k in range(j, 7): for k in range(j, 7):
if (i+j+k) == valeur: if (i+j+k) == valeur:
res.append([i, j, k]) res.append([i, j, k])
return res return res
def test_chouette(n): def test_chouette(n):
chouette(1) chouette(1)
listTest=[] listTest=[]

@ -2,13 +2,13 @@
async function submit(){ async function submit(){
var test = editor.getValue()+`\n var test = editor.getValue()+`\n
import random as r
def estPalindromeVerif(var): def estPalindromeVerif(var):
if(var == var[::-1]): if(var == var[::-1]):
return True return True
else: else:
return False return False
import random as r
def testPalindrome(x): def testPalindrome(x):
l=[1,2,3,2,1] l=[1,2,3,2,1]
if(estPalindrome(l)==False): if(estPalindrome(l)==False):

@ -63,6 +63,13 @@
<!-- <div class="ace rounded" id="editor" name="test"></div> --> <!-- <div class="ace rounded" id="editor" name="test"></div> -->
</div> </div>
</div> </div>
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Prompt</label>
<textarea class="form-control" name="prompt" id="prompt" rows="3" required></textarea>
<!-- <div class="ace rounded" id="editor" name="test"></div> -->
</div>
</div>
<button class="left" type="submit"> <button class="left" type="submit">
Submit Submit
</button> </button>

@ -79,7 +79,8 @@
<!-- Second Column --> <!-- Second Column -->
<div class="col-5 pr-0"> <div class="col-5 pr-0">
<div class="ace rounded" id="editor"></div> <div class="ace rounded" id="editor"><?php echo $enigme->getPrompt() . "
";?></div>
</div> </div>
<!-- End Second Column --> <!-- End Second Column -->
@ -123,7 +124,13 @@
<h5 id="result" style="color: black"></h5> <h5 id="result" style="color: black"></h5>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<a href="index.php?action=goToChouette" class="btn" style="display: none" id="next"> <a
<?php
$ordre = $enigme->getOrdre() + 1;
echo 'href="index.php?action=goToEnigme&ordre=' . $ordre .'"';
?>
class="btn" style="display: none" id="next"
>
<span>NEXT</span> <span>NEXT</span>
</a> </a>
</div> </div>

@ -197,7 +197,7 @@
<h5 id="result" style="color: black"></h5> <h5 id="result" style="color: black"></h5>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<a href="index.php?action=goToEnigme" class="btn" style="display: none" id="next"> <a href="index.php?action=goToEnigme&ordre=1" class="btn" style="display: none" id="next">
<span>NEXT</span> <span>NEXT</span>
</a> </a>
</div> </div>

@ -38,7 +38,7 @@
</h5> </h5>
</div> </div>
<div class="nav-link"> <div class="nav-link">
<a class="navbar-brand" href="index.php?action=goToEnigme">Skip</a> <a class="navbar-brand" href="index.php?action=goToEnigme&ordre=1">Skip</a>
</div> </div>
<div class="nav-link"> <div class="nav-link">
<a class="navbar-brand" href="index.php?action=goToTest">Next</a> <a class="navbar-brand" href="index.php?action=goToTest">Next</a>

@ -26,8 +26,10 @@ rappel varchar(250),
exemple varchar(250), exemple varchar(250),
solution varchar(250) NOT NULL, solution varchar(250) NOT NULL,
test varchar(250) NOT NULL, test varchar(250) NOT NULL,
ordre integer CHECK (ordre >=-1),
tempsDeResolution numeric CHECK (tempsDeResolution >=0), tempsDeResolution numeric CHECK (tempsDeResolution >=0),
points numeric CHECK (points >=0) points numeric CHECK (points >=0),
prompt varchar(250)
); );
CREATE TABLE Partie( CREATE TABLE Partie(

Loading…
Cancel
Save