pull/19/head
parent 27e3cf94ce
commit 15a3e67b38

@ -0,0 +1,71 @@
<?php
namespace Controller;
use Gateway\Connection;
use Gateway\QuizQuestionGateway;
use Model\QuizQuestionModel;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader;
class QuizController
{
private Environment $twig;
private Connection $co;
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function __construct(Connection $co)
{
$this -> 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]);
}
}

@ -2,55 +2,78 @@
namespace Model; namespace Model;
use Entity\QuestionEntity;
use Entity\QuizEntity;
use Entity\QuizQuestionEntity; use Entity\QuizQuestionEntity;
use Gateway\Connection;
use Gateway\QuestionGateway;
use Gateway\QuizGateway;
use Gateway\QuizQuestionGateway; use Gateway\QuizQuestionGateway;
class QuizQuestionModel class QuizQuestionModel
{ {
private QuizQuestionGateway $gw; private QuizQuestionGateway $gw;
/**
* @param QuizGateway $gw
*/
public function __construct(QuizQuestionGateway $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); $q = $this ->gw->findQuizQuestionByIdQuiz($id);
if ($q) {
if ($res) return new QuizQuestionEntity(
{ $q['idQuiz'],
return new QuizQuestionEntity ( $q['idQuestion'],
$res[0]['quiz_qq'],
$res[0]['question_qq']
); );
} }
return null; 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 = []; $questions = [];
$gw = new QuestionGateway($co);
$qmdl = new QuestionModel($gw);
foreach ($res as $question) foreach ($q as $question){
{ $questions [] = $qmdl->getQuestion($question[1]);
$questions[] = new QuizQuestionEntity (
$question['quiz_qq'],
$question['question_qq']
);
} }
return $questions; 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);
}
} }
Loading…
Cancel
Save