diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml index 0d9afcc..b631df8 100644 --- a/.idea/material_theme_project_new.xml +++ b/.idea/material_theme_project_new.xml @@ -3,7 +3,9 @@ - + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 882bd96..449c40f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,19 +5,8 @@ - - - + - - - - - - - - - @@ -78,6 +67,9 @@ "associatedIndex": 4 } + + + @@ -85,7 +77,7 @@ 1730794293135 - + 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/index.php b/index.php index d76fc9d..9d1e1b3 100644 --- a/index.php +++ b/index.php @@ -19,12 +19,14 @@ $twig = new \Twig\Environment($loader, [ 'cache' => false, ]); +<<<<<<< HEAD $twig->addGlobal('racine','/~kemondejar/WF-Website'); +======= +$num = 0; + +>>>>>>> quizPart $cont = new Controleur\FrontControler($co); -session_unset(); -session_destroy(); -$_SESSION = array(); ?> diff --git a/src/Controleur/QuizControler.php b/src/Controleur/QuizControler.php index 0e72f6d..34f33d8 100644 --- a/src/Controleur/QuizControler.php +++ b/src/Controleur/QuizControler.php @@ -1,5 +1,4 @@ co = $co; - $this -> gw = new QuestionGateway($this->co); - $this -> mdl = new QuestionModel($this->gw); - - $loader = new FilesystemLoader('vue/templates'); + $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"; - $this->no_question ++; - echo $this->no_question; - $this->showQuestion($id, $this->no_question); + $_SESSION['score'] = isset($_SESSION['score']) ? ($_SESSION['score'] + 1) : 1; + $this->continueQuiz($id, $nb_questions); break; default: switch($id) @@ -61,13 +56,48 @@ class QuizControler // page erreur break; default: - $this->showQuestion($id, $this->no_question); + $_SESSION['score'] = $_SESSION['score'] ?? 0; + $this->showQuestion($id, $_SESSION['no_question'] ?? 0); break; } } } + /** + * @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; @@ -108,37 +138,23 @@ class QuizControler * @throws SyntaxError * @throws LoaderError */ - public function showQuestion(int $id, int $no) : void + public function showQuestion(int $id, int $num) : void { global $twig; + echo $num; + echo " : ", $_SESSION['score']; $q = $this->GetQuestion($id); - $question = $q[$no]; - + $question = $q[$num] ?? $q[0]; $idquestion = $question->getIdQuestion(); echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]); - } - 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(); } -} - -/* - -getUrl() ?>> = $new->getTitle() ?> - } - -?> - - -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/Model/QuizModel.php b/src/Model/QuizModel.php index 728d516..155a512 100644 --- a/src/Model/QuizModel.php +++ b/src/Model/QuizModel.php @@ -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; 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 + + diff --git a/vue/templates/quiz.html.twig b/vue/templates/quiz.html.twig index f78dd54..b53270d 100644 --- a/vue/templates/quiz.html.twig +++ b/vue/templates/quiz.html.twig @@ -9,7 +9,7 @@ - - - - - - - - - - - - - - + {{ include "bandeau.html.twig" }} ▶ Quiz ◀ {{ question.question }} - 300 seconds left .. + 10 seconds left .. @@ -59,7 +46,7 @@ {{ question.answerd }} - +