From 657d7fb711f2688fcedc01d98cea17b0c41590f7 Mon Sep 17 00:00:00 2001 From: "anthony.richard" Date: Sun, 19 Nov 2023 23:45:04 +0100 Subject: [PATCH] =?UTF-8?q?meilleure=20gestion=20d'erreur=20+=20affichage?= =?UTF-8?q?=20nom=20de=20la=20liste=20=C3=A0=20la=20place=20de=20quiz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/php/controller/AbsController.php | 4 +++- Project/php/gateway/VocabularyListGateway.php | 5 +++-- Project/php/templates/quizView.html | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php index 150cbeb..bd27757 100644 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -97,6 +97,8 @@ class AbsController { global $twig; $vocabId = Validation::filter_int($match['id'] ?? null); + $vocabList = (new VocabularyListGateway())->findById($vocabId) ?? null; + if ($vocabList == null) throw new Exception("liste inconnue"); $mdl = new TranslationGateway(); $allTranslation = $mdl->findByIdVoc($vocabId); $shuffle = $allTranslation; @@ -127,7 +129,7 @@ class AbsController $answers[] = $tab; } - echo $twig->render('quizView.html', ['questions' => $questions, 'answers' => $answers, 'goodAnswers' => $goodAnswers]); + echo $twig->render('quizView.html', ['questions' => $questions, 'answers' => $answers, 'goodAnswers' => $goodAnswers, 'listName' => $vocabList->getName()]); } public function login(): void { diff --git a/Project/php/gateway/VocabularyListGateway.php b/Project/php/gateway/VocabularyListGateway.php index e4cdcef..4714986 100755 --- a/Project/php/gateway/VocabularyListGateway.php +++ b/Project/php/gateway/VocabularyListGateway.php @@ -73,8 +73,9 @@ class VocabularyListGateway extends AbsGateway $query = "SELECT * FROM VocabularyList WHERE id = :id"; $args = array(':id' => array($id, PDO::PARAM_INT)); $this->con->executeQuery($query, $args); - - return $this->con->getResults(); + $results = $this->con->getResults(); + if (empty($results)) return null; + return new VocabularyList($results[0]['id'],$results[0]['name'],$results[0]['image'],$results[0]['userID']); } catch (PDOException $e){ throw new Exception($e->getMessage()); diff --git a/Project/php/templates/quizView.html b/Project/php/templates/quizView.html index 57fce13..9ad6dea 100644 --- a/Project/php/templates/quizView.html +++ b/Project/php/templates/quizView.html @@ -21,7 +21,7 @@
-

Quiz

+

{{listName}}

{% if questions is defined %} {% for i in 0..questions|length %}