Add Session

pull/19/head
tomivt 6 months ago
parent ba32f10976
commit 51d2ee5728

@ -3,7 +3,9 @@
<component name="MaterialThemeProjectNewConfig"> <component name="MaterialThemeProjectNewConfig">
<option name="metadata"> <option name="metadata">
<MTProjectMetadataState> <MTProjectMetadataState>
<option name="userId" value="5c5a39c9:192fb929d1e:-7ffa" /> <option name="migrated" value="true" />
<option name="pristineConfig" value="false" />
<option name="userId" value="-1562669c:19061473cbf:-7ffe" />
</MTProjectMetadataState> </MTProjectMetadataState>
</option> </option>
</component> </component>

@ -5,19 +5,12 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="afa12d51-331f-4dbc-a297-7289ad4e396d" name="Changes" comment=""> <list default="true" id="afa12d51-331f-4dbc-a297-7289ad4e396d" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/composer.json" beforeDir="false" afterPath="$PROJECT_DIR$/composer.json" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/index.php" beforeDir="false" afterPath="$PROJECT_DIR$/index.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/index.php" beforeDir="false" afterPath="$PROJECT_DIR$/index.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Controleur/FrontControler.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/FrontControler.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Controleur/QuizController.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/QuizController.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Controleur/QuizController.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Controleur/QuizController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Gateway/Connection.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Gateway/Connection.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Model/QuizModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Model/QuizModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Gateway/QuestionGateway.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Gateway/QuestionGateway.php" afterDir="false" /> <change beforePath="$PROJECT_DIR$/vue/templates/quiz.html.twig" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/quiz.html.twig" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Gateway/QuizGateway.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Gateway/QuizGateway.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Model/QuestionModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Model/QuestionModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Model/QuizQuestionModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Model/QuizQuestionModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vendor/composer/autoload_psr4.php" beforeDir="false" afterPath="$PROJECT_DIR$/vendor/composer/autoload_psr4.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vendor/composer/autoload_static.php" beforeDir="false" afterPath="$PROJECT_DIR$/vendor/composer/autoload_static.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/accueil.php" beforeDir="false" afterPath="$PROJECT_DIR$/vue/accueil.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/quiz.php" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/quiz.html.twig" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -82,23 +75,23 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"git-widget-placeholder": "master", &quot;git-widget-placeholder&quot;: &quot;master&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}, },
"keyToStringList": { &quot;keyToStringList&quot;: {
"DatabaseDriversLRU": [ &quot;DatabaseDriversLRU&quot;: [
"postgresql" &quot;postgresql&quot;
] ]
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/vue/templates" /> <recent name="$PROJECT_DIR$/vue/templates" />
@ -121,7 +114,7 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1730794293135</updated> <updated>1730794293135</updated>
<workItem from="1730794294713" duration="2741000" /> <workItem from="1730794294713" duration="2741000" />
<workItem from="1730797544484" duration="27887000" /> <workItem from="1730797544484" duration="43165000" />
</task> </task>
<servers /> <servers />
</component> </component>

@ -19,11 +19,10 @@ $twig = new \Twig\Environment($loader, [
'cache' => 'cache', 'cache' => 'cache',
]); ]);
$num = 0;
$cont = new Controleur\FrontControler($co); $cont = new Controleur\FrontControler($co);
session_unset();
session_destroy();
$_SESSION = array();
?> ?>

@ -1,5 +1,6 @@
<?php <?php
namespace Controleur; namespace Controleur;
use Entity\QuestionEntity; use Entity\QuestionEntity;
@ -16,9 +17,10 @@ use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError; use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader; use Twig\Loader\FilesystemLoader;
class QuizController class QuizController
{ {
private int $no_question = 0;
private Connection $co; private Connection $co;
@ -37,8 +39,8 @@ class QuizController
$this -> co = $co; $this -> co = $co;
$this -> gw = new QuestionGateway($this->co); $this -> gw = new QuestionGateway($this->co);
$this -> mdl = new QuestionModel($this->gw); $this -> mdl = new QuestionModel($this->gw);
global $num;
$loader = new FilesystemLoader('vue/templates'); global $loader;
$action = $_REQUEST['action'] ?? null; $action = $_REQUEST['action'] ?? null;
@ -46,13 +48,12 @@ class QuizController
switch ($action) { switch ($action) {
case 'canswer': case 'canswer':
if ($this->CorrectAnswer()) if ($this->CorrectAnswer())
echo "Bonne réponse"; echo "Bonne réponse";
else echo "Mauvaise réponse"; else echo "Mauvaise réponse";
$this->no_question ++; $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1;
echo $this->no_question;
$this->showQuestion($id, $this->no_question); header("Location: http://localhost:8000/quiz/$id");
break; break;
default: default:
switch($id) switch($id)
@ -61,7 +62,7 @@ class QuizController
// page erreur // page erreur
break; break;
default: default:
$this->showQuestion($id, $this->no_question); $this->showQuestion($id, $_SESSION['no_question'] ?? 0);
break; break;
} }
} }
@ -103,42 +104,36 @@ class QuizController
return $mdl->getAllQuestionByQuiz($id, $this->co); return $mdl->getAllQuestionByQuiz($id, $this->co);
} }
public function RunQuiz(int $idQuiz)
{
}
/** /**
* @throws RuntimeError * @throws RuntimeError
* @throws SyntaxError * @throws SyntaxError
* @throws LoaderError * @throws LoaderError
*/ */
public function showQuestion(int $id, int $no) : void public function showQuestion(int $id, int $num) : void
{ {
global $twig; global $twig;
echo $num;
$q = $this->GetQuestion($id); $q = $this->GetQuestion($id);
$question = $q[$no]; $question = $q[$num];
$idquestion = $question->getIdQuestion(); $idquestion = $question->getIdQuestion();
echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]); echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]);
//else
//page resultat
} }
public function getNumberOfQuestion() : int
public function getNumberOfQuestion(int $id) : int
{ {
$gw = new QuizGateway($this->co); $gw = new QuizGateway($this->co);
$mdl = new QuizModel($gw); $mdl = new QuizModel($gw);
return 0; return $mdl->getQuiz($id)->getNbQuestions();
} }
} }
/*
<php
foreach ($news as $new)
{
<h2 href=<?= $new->getUrl() ?>> <?= $new->getTitle() ?> </h2>
}
?>
*/

@ -24,8 +24,8 @@ class QuizModel {
$q = $this -> gateway -> findQuizById($id_quiz); $q = $this -> gateway -> findQuizById($id_quiz);
if ($q) { if ($q) {
return new quizEntity( return new quizEntity(
$q['id_quiz'], $q[0]['id_quiz'],
$q['nb_questions'], $q[0]['nb_quest']
); );
} }
return null; return null;

@ -9,7 +9,7 @@
<script defer src="../../public/script/theme-toggle.js"></script> <script defer src="../../public/script/theme-toggle.js"></script>
<script> <script>
// Timer pour 5 minutes // Timer pour 5 minutes
var timeLeft = 300; var timeLeft = 10;
function countdown() { function countdown() {
var timerDisplay = document.getElementById("timer"); var timerDisplay = document.getElementById("timer");
if (timeLeft <= 0) { if (timeLeft <= 0) {
@ -24,25 +24,12 @@
</script> </script>
</head> </head>
<body> <body>
<div class="header">
<div class="nav">
<a href="../favorite.html"><img src="../../images/coeur.svg" alt="coeur" width="67px" height="67px" onmousedown="return false"></a>
<img id="theme-icon" src="../../images/light.svg" alt="toggle theme" width="72px" height="37px" onmousedown="return false" onclick="toggleTheme()">
<img src="../../images/quizz.svg" alt="quizz" width="51px" height="82px" onmousedown="return false">
</div>
<div class="logo">
<img src="../../images/WIKIFANTASY.png" alt="Logo" width="227px" height="106px" onmousedown="return false">
</div>
<div class="user">
<img src="../../images/user_dark.png" alt="user" width="70px" height="70px" onmousedown="return false">
</div>
</div>
{{ include "bandeau.html.twig" }}
<h1>▶ Quiz ◀</h1> <h1>▶ Quiz ◀</h1>
<div class="quiz"> <div class="quiz">
<h2> {{ question.question }} </h2> <h2> {{ question.question }} </h2>
<a id="timer"> 300 seconds left .. </a> <a id="timer"> 10 seconds left .. </a>
<form id="quizForm" method="POST"> <form id="quizForm" method="POST">
<div class="answers"> <div class="answers">
@ -59,7 +46,7 @@
{{ question.answerd }} {{ question.answerd }}
</button> </button>
</div> </div>
<input type="hidden" name="action" value="canswer"> <input type="hidden" name="action" value="">
</form> </form>
</div> </div>
</body> </body>

Loading…
Cancel
Save