diff --git a/src/Controleur/QuizController.php b/src/Controleur/QuizController.php new file mode 100644 index 0000000..0a21fad --- /dev/null +++ b/src/Controleur/QuizController.php @@ -0,0 +1,71 @@ + co = $co; + $loader = new FilesystemLoader('vue/templates'); + $this->twig = new \Twig\Environment($loader, [ + 'cache' => false, + ]); + + $action = $_REQUEST['action'] ?? null; + + $id = explode('-', $_SERVER['REQUEST_URI'])[1] ?? null; + + switch($id) + { + case null: + // page erreur + break; + default: + $this->showQuestion($id); + break; + } + } + + + public function GetQuestion(int $id): array + { + $gw = new QuizQuestionGateway($this->co); + $quizModel = new QuizQuestionModel($gw); + return $quizModel->getAllQuestionByQuiz($id, $this->co); + } + + /** + * @throws RuntimeError + * @throws SyntaxError + * @throws LoaderError + */ + public function showQuestion(int $id) : void + { + $q = $this->GetQuestion($id); + $i = 0; + // en fonction du nb de question restante et du answer submit changer le i + $q = $q[$i]; + + echo $this->twig->render('quiz.html.twig', ['question' => $q]); + } +} \ No newline at end of file diff --git a/src/Model/QuizQuestionModel.php b/src/Model/QuizQuestionModel.php index e4ff7cf..4a3fd94 100644 --- a/src/Model/QuizQuestionModel.php +++ b/src/Model/QuizQuestionModel.php @@ -2,55 +2,78 @@ namespace Model; +use Entity\QuestionEntity; +use Entity\QuizEntity; use Entity\QuizQuestionEntity; +use Gateway\Connection; +use Gateway\QuestionGateway; +use Gateway\QuizGateway; use Gateway\QuizQuestionGateway; class QuizQuestionModel { private QuizQuestionGateway $gw; + /** + * @param QuizGateway $gw + */ public function __construct(QuizQuestionGateway $gw) { - $this -> gw = $gw; + $this->gw = $gw; } - public function createQuizQuestionModel(int $idQuiz, int $idQuestion) : bool + public function createQuizQuestion(int $idQuiz, int $idQuestion): bool { - return $this -> gw -> createQuizQuestionGateway($idQuiz, $idQuestion); + return $this->gw->create($idQuiz,$idQuestion); } - public function getQuizQuestionById(int $idQuiz, int $idQuestion) : ?QuizQuestionEntity + public function findQuizQuestionByIdQuiz(int $id): ?QuizQuestionEntity { - $res = $this -> gw -> findQuizQuestionById($idQuiz, $idQuestion); - - if ($res) - { - return new QuizQuestionEntity ( - $res[0]['quiz_qq'], - $res[0]['question_qq'] + $q = $this ->gw->findQuizQuestionByIdQuiz($id); + if ($q) { + return new QuizQuestionEntity( + $q['idQuiz'], + $q['idQuestion'], ); } return null; } - public function getQuestionsFromQuiz(int $idQuiz) : array + public function getAllQuestionByQuiz(int $id, Connection $co): array { - $res = $this -> gw -> findQuestionsFromQuiz($idQuiz); + $q = $this ->gw->findQuizQuestionByIdQuestion($id); $questions = []; + $gw = new QuestionGateway($co); + $qmdl = new QuestionModel($gw); - foreach ($res as $question) - { - $questions[] = new QuizQuestionEntity ( - $question['quiz_qq'], - $question['question_qq'] - ); + foreach ($q as $question){ + $questions [] = $qmdl->getQuestion($question[1]); } return $questions; } - public function deleteQuizQuestionModel(int $idQuiz, int $idQuestion) : bool + public function findAll(): array { - return $this -> gw -> deleteQuizQuestionGateway($idQuiz, $idQuestion); + $q = $this -> gw -> findAll(); + + $quizzes = []; + + foreach ($q as $quiz) { + $quizzes[] = new QuizQuestionEntity( + $quiz['idQuiz'], + $quiz['idQuestion'] + ); + } + return $quizzes; } + + public function deleteQuizQuestion(int $id): bool + { + return $this -> gw -> delete($id); + } + + + + } \ No newline at end of file