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 ='';
// BD
$dsn = './scripted.db';
// $dsn = 'C:\\wamp64\\www\\scripted.db';
// $dsn = './scripted.db';
$dsn = 'C:\\wamp64\\www\\scripted.db';
//Sel de hashage
$sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong";

@ -124,6 +124,7 @@ class AdminController extends UserController
$exemple = $_POST['exemple'];
$test = $_POST['test'];
$solution = $_POST['solution'];
$prompt = $_POST['prompt'];
if (empty($nom) || empty($enonce) || empty($test) || empty($solution)) {
throw new Exception("Les champs nom, enigme, test et solution doivent être remplis");
}
@ -136,7 +137,7 @@ class AdminController extends UserController
if (empty($exemple)) {
$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']);
} catch (Exception $e) {
$error = $e->getMessage();

@ -35,7 +35,7 @@ class EnigmeGateway
*/
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(
':nom' => array($enigme->getNom(), SQLITE3_TEXT),
':enonce' => array($enigme->getEnonce(), SQLITE3_TEXT),
@ -44,8 +44,10 @@ class EnigmeGateway
':exemple' => array($enigme->getExemple(), SQLITE3_TEXT),
':solution' => array($enigme->getSolution(), SQLITE3_TEXT),
':test' => array($enigme->getTest(), SQLITE3_TEXT),
':ordre' => array($enigme->getOrdre(), 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);
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
{
$query = "SELECT * FROM Enigme";

@ -101,7 +101,10 @@ class UserController
{
try {
global $rep, $vues;
require($rep . $vues['enigme']);
$model = new UserModel();
$ordre = $_REQUEST['ordre'];
$enigme = $model->getEnigmeByOrdre($ordre);
require($rep . $vues['enigmePage']);
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);

@ -5,7 +5,8 @@ class EnigmeFactory{
$tabEnigme=array();
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;
}

@ -10,8 +10,10 @@ class Enigme
private string $exemple;
private string $solution;
private string $test;
private int $ordre;
private int $tempsDeResolution;
private int $points;
private string $prompt;
/**
* @param int $idEnigme
@ -22,10 +24,14 @@ class Enigme
* @param string $exemple
* @param string $solution
* @param string $test
* @param int $ordre
* @param int $tempsDeResolution
* @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->nom = $nom;
@ -35,8 +41,10 @@ class Enigme
$this->exemple = $exemple;
$this->solution = $solution;
$this->test = $test;
$this->ordre = $ordre;
$this->tempsDeResolution = $tempsDeResolution;
$this->points = $points;
$this->prompt = $prompt;
}
/**
* @return int
@ -165,6 +173,14 @@ class Enigme
{
$this->test = $test;
}
public function getOrdre(): int
{
return $this->ordre;
}
public function setOrdre(int $ordre): void
{
$this->ordre = $ordre;
}
/**
* @return int
@ -189,4 +205,13 @@ class Enigme
{
$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();
}
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);
var_dump($enigme);
$tabEnigme = $this->enigme_gateway->findLastEnigma();
$js = fopen("View/src/JS/$nom.js", "w");
if (is_resource($js)) {

@ -65,4 +65,13 @@ class UserModel
$_SESSION['role'] = 'visitor';
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];
}
}

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

@ -63,6 +63,13 @@
<!-- <div class="ace rounded" id="editor" name="test"></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">
Submit
</button>

@ -79,7 +79,8 @@
<!-- Second Column -->
<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>
<!-- End Second Column -->
@ -123,7 +124,13 @@
<h5 id="result" style="color: black"></h5>
</div>
<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>
</a>
</div>

@ -197,7 +197,7 @@
<h5 id="result" style="color: black"></h5>
</div>
<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>
</a>
</div>

@ -38,7 +38,7 @@
</h5>
</div>
<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 class="nav-link">
<a class="navbar-brand" href="index.php?action=goToTest">Next</a>

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

Loading…
Cancel
Save