diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d977ec5..449c40f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,12 +5,8 @@
-
-
-
-
@@ -71,27 +67,30 @@
"associatedIndex": 4
}
+
+
+
- {
- "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"
+
+}]]>
diff --git a/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php b/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php
new file mode 100644
index 0000000..d4d5fd6
--- /dev/null
+++ b/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php
@@ -0,0 +1,95 @@
+
+ */
+ private array $macros = [];
+
+ public function __construct(Environment $env)
+ {
+ parent::__construct($env);
+
+ $this->source = $this->getSourceContext();
+
+ $this->parent = false;
+
+ $this->blocks = [
+ ];
+ }
+
+ protected function doDisplay(array $context, array $blocks = []): iterable
+ {
+ $macros = $this->macros;
+ // line 1
+ yield "
+
+
+
+
+ Wiki Fantasy : Quiz
+
+
+
+
+
+
+
+ ";
+ // line 14
+ yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["score"] ?? null), "html", null, true);
+ yield "
+
+
+
+
+";
+ yield from [];
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function getTemplateName(): string
+ {
+ return "endQuiz.html.twig";
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function isTraitable(): bool
+ {
+ return false;
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function getDebugInfo(): array
+ {
+ return array ( 57 => 14, 42 => 1,);
+ }
+
+ public function getSourceContext(): Source
+ {
+ return new Source("", "endQuiz.html.twig", "/Users/kiem/Documents/WikiFantasy/WF-Website/vue/templates/endQuiz.html.twig");
+ }
+}
diff --git a/src/Controleur/QuizController.php b/src/Controleur/QuizController.php
index 65fe758..e0dcee7 100644
--- a/src/Controleur/QuizController.php
+++ b/src/Controleur/QuizController.php
@@ -1,6 +1,4 @@
co = $co;
- $this -> gw = new QuestionGateway($this->co);
- $this -> mdl = new QuestionModel($this->gw);
+ $this -> gw = new QuestionGateway($this -> co);
+ $this -> mdl = new QuestionModel($this -> gw);
global $num;
global $loader;
$action = $_REQUEST['action'] ?? null;
$id = (int) explode('/', $_SERVER['REQUEST_URI'])[2] ?? null;
+ $nb_questions = $this->getNumberOfQuestion($id);
switch ($action) {
case 'canswer':
if ($this->CorrectAnswer())
- echo "Bonne réponse";
- else echo "Mauvaise réponse";
- $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1;
-
- header("Location: http://localhost:8000/quiz/$id");
+ $_SESSION['score'] = isset($_SESSION['score']) ? ($_SESSION['score'] + 1) : 1;
+ $this->continueQuiz($id, $nb_questions);
break;
default:
switch($id)
@@ -62,6 +56,7 @@ class QuizController
// page erreur
break;
default:
+ $_SESSION['score'] = $_SESSION['score'] ?? 0;
$this->showQuestion($id, $_SESSION['no_question'] ?? 0);
break;
}
@@ -69,6 +64,40 @@ class QuizController
}
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function continueQuiz(int $id_quiz, int $total_questions) : void
+ {
+ $score = $_SESSION['score'];
+ $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1;
+ if ($_SESSION['no_question'] >= $total_questions) {
+ session_destroy();
+ $this->endQuiz($id_quiz, $score);
+ }
+ else header("Location: http://localhost:8000/quiz/$id_quiz");
+
+ }
+
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function endQuiz(int $id_quiz, int $score) : void
+ {
+ global $twig;
+
+ $gw = new QuizGateway($this->co);
+ $mdl = new QuizModel($gw);
+
+ if ($mdl->getQuiz($id_quiz + 1))
+ echo $twig->render('endQuiz.html.twig', ['score' => $score, 'nextquiz' => $id_quiz + 1]);
+ echo $twig->render('endQuiz.html.twig', ['score' => $score]);
+ }
+
public function CorrectAnswer() : bool
{
$answera = $_POST['answera'] ?? null;
@@ -104,11 +133,6 @@ class QuizController
return $mdl->getAllQuestionByQuiz($id, $this->co);
}
- public function RunQuiz(int $idQuiz)
- {
-
- }
-
/**
* @throws RuntimeError
* @throws SyntaxError
@@ -118,14 +142,11 @@ class QuizController
{
global $twig;
echo $num;
+ echo " : ", $_SESSION['score'];
$q = $this->GetQuestion($id);
- $question = $q[$num];
+ $question = $q[$num] ?? $q[0];
$idquestion = $question->getIdQuestion();
echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]);
-
- //else
- //page resultat
-
}
diff --git a/vue/templates/endQuiz.html.twig b/vue/templates/endQuiz.html.twig
new file mode 100644
index 0000000..b34f4ea
--- /dev/null
+++ b/vue/templates/endQuiz.html.twig
@@ -0,0 +1,19 @@
+
+
+
+
+
+ Wiki Fantasy : Quiz
+
+
+
+
+
+
+
+ {{ score }}
+ {{ nextquiz }}
+
+zeze
+
+