From ccc48431e8da53e1dd4f45c5647761b10f81176a Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Fri, 10 Jan 2025 15:22:56 +0100 Subject: [PATCH] =?UTF-8?q?debut=20ajout=20quiz=20al=C3=A9atoire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controleur/UserControler.php | 28 ++++++++++++++++++++++--- src/Gateway/QuestionGateway.php | 4 ++++ src/Model/QuestionModel.php | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 32c58a3..e7e5ac6 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -27,16 +27,16 @@ class UserControler { private CommentaryModel $cMod; private UserModel $uMod; private QuoteModel $qMod; - private QuestionModel $mdl; private CharacterModel $caMod; private SourceModel $srcMod; + private QuestionModel $questMod; public function __construct() { global $co; $this->cMod = new CommentaryModel(new CommentaryGateway($co)); $this->uMod = new UserModel(new UserGateway($co)); $this->qMod = new QuoteModel(new QuoteGateway($co)); - $this -> mdl = new QuestionModel(new QuestionGateway($co)); + $this -> questMod = new QuestionModel(new QuestionGateway($co)); $this -> caMod = new CharacterModel(new CharacterGateway($co)); $this->srcMod = new SourceModel(new SourceGateway($co)); } @@ -174,7 +174,7 @@ class UserControler { $answer = explode('-', $answerd)[0]; $id = (int) explode('-', $answerd)[1]; } - $res = $this->mdl->getQuestion($id); + $res = $this->questMod->getQuestion($id); return $answer == $res->getCanswer(); } @@ -509,4 +509,26 @@ class UserControler { var_dump($error); } } + + // Quiz aléatoire + + // argument = Langue / type question / type reponse + public function quizAleatoire(){ + global $vues; + if(!isset($_POST["nbVie"])){ + $vie = 3; + } + $question = $questMod->getRandomQuestion([$_POST["questionType"],$_POST["awnserType"]],$_POST["langue"]); + addTab($question); + if($question == null){ + $require_once($vues["erreur"]); + } + else{ + $require_once($vues['quiz']); + } + } + + public function questionSuivantAleatoire(){ + + } } diff --git a/src/Gateway/QuestionGateway.php b/src/Gateway/QuestionGateway.php index d67e175..946ee4e 100644 --- a/src/Gateway/QuestionGateway.php +++ b/src/Gateway/QuestionGateway.php @@ -98,4 +98,8 @@ class QuestionGateway extends Gateway return $this -> co -> getResults(); } + public function getQuestionQuoteSrc(string $l) : array{ + + } + } diff --git a/src/Model/QuestionModel.php b/src/Model/QuestionModel.php index d560b18..1e6db0a 100644 --- a/src/Model/QuestionModel.php +++ b/src/Model/QuestionModel.php @@ -79,4 +79,39 @@ class QuestionModel extends Model ); return null; } + + public function getRandomQuestion(string $quesType, string $repType, string $langue) : ?QuestionEntity{ + switch([$questType,$repType]){ + case ["Quote","Src"]: + $q = $this -> gateway -> getQuestionQuoteSrc($langue); + return new QuestionEntity( + $q[], //idQuote + $q[], //Quote + $q[], //SrcJuste + $q[], //rndSrc 1 + $q[], //rndSrc 2 + $q[], //rndSrc 3 + $q[], //SrcJuste + ); + case ["Quote","Charac"]: + $q = $this -> gateway -> getQuestionQuoteCharac($langue); + + case ["Charac","Src"]: + $q = $this -> gateway -> getQuestionCharacSrc($langue); + + case ["Charac","Quote"]: + $q = $this -> gateway -> getQuestionCharacQuote($langue); + + case ["Src","Quote"]: + $q = $this -> gateway -> getQuestionSrcQuote($langue); + + case ["Src","Charac"]: + $q = $this -> gateway -> getQuestionSrcCharac($langue); + + case ["Test","Test"]: + return new QuestionEntity(-1,"1","1","2","3","4","1"); + default : + return null; + } + } } \ No newline at end of file