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]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue