meilleure gestion d'erreur + affichage nom de la liste à la place de quiz

php
Anthony RICHARD 1 year ago
parent 4877d9b4ac
commit 657d7fb711

@ -97,6 +97,8 @@ class AbsController
{ {
global $twig; global $twig;
$vocabId = Validation::filter_int($match['id'] ?? null); $vocabId = Validation::filter_int($match['id'] ?? null);
$vocabList = (new VocabularyListGateway())->findById($vocabId) ?? null;
if ($vocabList == null) throw new Exception("liste inconnue");
$mdl = new TranslationGateway(); $mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($vocabId); $allTranslation = $mdl->findByIdVoc($vocabId);
$shuffle = $allTranslation; $shuffle = $allTranslation;
@ -127,7 +129,7 @@ class AbsController
$answers[] = $tab; $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 { public function login(): void {

@ -73,8 +73,9 @@ class VocabularyListGateway extends AbsGateway
$query = "SELECT * FROM VocabularyList WHERE id = :id"; $query = "SELECT * FROM VocabularyList WHERE id = :id";
$args = array(':id' => array($id, PDO::PARAM_INT)); $args = array(':id' => array($id, PDO::PARAM_INT));
$this->con->executeQuery($query, $args); $this->con->executeQuery($query, $args);
$results = $this->con->getResults();
return $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){ catch (PDOException $e){
throw new Exception($e->getMessage()); throw new Exception($e->getMessage());

@ -21,7 +21,7 @@
<body> <body>
<section id="quiz"> <section id="quiz">
<h1>Quiz</h1> <h1>{{listName}}</h1>
<div id="questionContainer"> <div id="questionContainer">
{% if questions is defined %} {% if questions is defined %}
{% for i in 0..questions|length %} {% for i in 0..questions|length %}

Loading…
Cancel
Save