Add Session

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

@ -3,7 +3,9 @@
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<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>
</option>
</component>

@ -5,19 +5,12 @@
</component>
<component name="ChangeListManager">
<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$/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/Gateway/Connection.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Gateway/Connection.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$/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" />
<change beforePath="$PROJECT_DIR$/src/Model/QuizModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Model/QuizModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/vue/templates/quiz.html.twig" beforeDir="false" afterPath="$PROJECT_DIR$/vue/templates/quiz.html.twig" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -82,23 +75,23 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
},
"keyToStringList": {
"DatabaseDriversLRU": [
"postgresql"
&quot;keyToStringList&quot;: {
&quot;DatabaseDriversLRU&quot;: [
&quot;postgresql&quot;
]
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/vue/templates" />
@ -121,7 +114,7 @@
<option name="presentableId" value="Default" />
<updated>1730794293135</updated>
<workItem from="1730794294713" duration="2741000" />
<workItem from="1730797544484" duration="27887000" />
<workItem from="1730797544484" duration="43165000" />
</task>
<servers />
</component>

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

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

@ -9,7 +9,7 @@
<script defer src="../../public/script/theme-toggle.js"></script>
<script>
// Timer pour 5 minutes
var timeLeft = 300;
var timeLeft = 10;
function countdown() {
var timerDisplay = document.getElementById("timer");
if (timeLeft <= 0) {
@ -24,25 +24,12 @@
</script>
</head>
<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>
<div class="quiz">
<h2> {{ question.question }} </h2>
<a id="timer"> 300 seconds left .. </a>
<a id="timer"> 10 seconds left .. </a>
<form id="quizForm" method="POST">
<div class="answers">
@ -59,7 +46,7 @@
{{ question.answerd }}
</button>
</div>
<input type="hidden" name="action" value="canswer">
<input type="hidden" name="action" value="">
</form>
</div>
</body>

Loading…
Cancel
Save