From 6a466b062b3986d20e221332ffde9d5de9c46ab7 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Sun, 19 Nov 2023 16:49:34 +0100 Subject: [PATCH 1/6] avancement du quiz --- Project/php/controller/AbsController.php | 4 +- Project/php/controller/StudentController.php | 4 +- Project/php/css/memory.css | 0 Project/php/templates/memory.html | 0 Project/php/templates/quizzView.html | 56 +++++++++++--------- 5 files changed, 37 insertions(+), 27 deletions(-) mode change 100644 => 100755 Project/php/css/memory.css mode change 100644 => 100755 Project/php/templates/memory.html diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php index 04e8fec..58f3d99 100755 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -94,6 +94,8 @@ abstract class AbsController $vocabId = $_GET['vocabID']; $mdl = new TranslationGateway(); $allTranslation = $mdl->findByIdVoc($vocabId); - echo $twig->render('quizzView.html', ['translations' => $allTranslation]); + $shuffle = $allTranslation; + shuffle($shuffle); + echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']); } } \ No newline at end of file diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index 10dc1f6..5569511 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -42,7 +42,9 @@ class StudentController $vocabId = $_GET['vocabID']; $mdl = new TranslationGateway(); $allTranslation = $mdl->findByIdVoc($vocabId); - echo $twig->render('quizzView.html', ['translations' => $allTranslation]); + $shuffle = $allTranslation; + shuffle($shuffle); + echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']); } /* public function flashcard(VocabularyList $v) { diff --git a/Project/php/css/memory.css b/Project/php/css/memory.css old mode 100644 new mode 100755 diff --git a/Project/php/templates/memory.html b/Project/php/templates/memory.html old mode 100644 new mode 100755 diff --git a/Project/php/templates/quizzView.html b/Project/php/templates/quizzView.html index cbd9c81..a161632 100755 --- a/Project/php/templates/quizzView.html +++ b/Project/php/templates/quizzView.html @@ -2,41 +2,47 @@ - Manage groups - - - - - - - - - - - + Manage groups

Quiz

-
-

{{frenchWord}}

- {% for i in 0..3 %} - - {{answers[i]}}
+ {% if translations is defined %} + {% for translation in translations %} +

{{ translation.word1 }}

+ {% set correctAnswer = translation.word2 %} + {% set otherTranslations = [translation.word2, translations[0].word2, translations[1].word2, translations[2].word2] %} + {{ correctAnswer }}
+ {% for otherTranslation in otherTranslations %} + {% if otherTranslation != correctAnswer %} + {{ otherAnswer }}
+ {% endif %} {% endfor %} - - + {% endfor %} + {% endif %} +
+ {% if submitted %} + {% if isCorrect %} +

Correct answer!

+ {% else %} +

Wrong answer!

+ {% endif %} + {% endif %} +
+

Translator

-
- - + + {% if translations is defined %} + {% for translation in translations %} + + + + {% endfor %} + {% endif %}
- \ No newline at end of file From a63a94e6bae5ca0b026fc13abca602577be2aeb8 Mon Sep 17 00:00:00 2001 From: Antoine Jourdain Date: Sun, 19 Nov 2023 17:22:04 +0100 Subject: [PATCH 2/6] Fix mdp invalide --- Project/php/controller/FrontController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index b2597d3..1467b2f 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -113,6 +113,7 @@ class FrontController $login = strip_tags($_POST['logemail']); $password = strip_tags($_POST['logpass']); $user = $model->connection($login, $password); + if ($user == null) throw new Exception("mot de passe invalide"); $this->home(); } From c38194573bcd60f28fe4be22efa9681a32ee5e87 Mon Sep 17 00:00:00 2001 From: "anthony.richard" Date: Sun, 19 Nov 2023 17:51:29 +0100 Subject: [PATCH 3/6] fix login --- Project/php/controller/FrontController.php | 11 ++++------- Project/php/gateway/UserGateway.php | 17 +++-------------- Project/php/model/AbsModel.php | 5 +++++ Project/php/model/MdlStudent.php | 4 ---- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index 1467b2f..97c0877 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -55,12 +55,12 @@ class FrontController case 'disconnect': $this->disconnect(); break; + case 'quiz': $this->quiz(); break; default : - if ($id != null && !$this->checkIdExist($id)) throw new Exception("identifiant invalide"); if ($target == null) throw new Exception("pas de target"); if (isset($_SESSION['login']) && isset($_SESSION['roles'])) { @@ -112,16 +112,15 @@ class FrontController $model = new MdlStudent(); $login = strip_tags($_POST['logemail']); $password = strip_tags($_POST['logpass']); + if (!$this->checkLoginExist($login)) throw new Exception(("login invalide")); $user = $model->connection($login, $password); if ($user == null) throw new Exception("mot de passe invalide"); $this->home(); } - public function checkIdExist(int $id):bool - { + public function checkLoginExist(string $login): bool { $mdl = new MdlStudent(); - $res = $mdl->checkIdExist($id); - return $res; + return $mdl->checkLoginExist($login); } public function disconnect(): void { @@ -133,6 +132,4 @@ class FrontController $ctrl = new StudentController(); $ctrl->quiz(); } - - } \ No newline at end of file diff --git a/Project/php/gateway/UserGateway.php b/Project/php/gateway/UserGateway.php index 1bff787..b75b6f9 100755 --- a/Project/php/gateway/UserGateway.php +++ b/Project/php/gateway/UserGateway.php @@ -125,6 +125,7 @@ class UserGateway extends AbsGateway $args = array(':id' => array($id, PDO::PARAM_INT)); $this->con->executeQuery($query, $args); $results = $this->con->getResults(); + if (empty($results)) return null; return new User($results[0]['id'], $results[0]['password'], $results[0]['email'], $results[0]['name'], $results[0]['surname'], $results[0]['nickname'], $results[0]['image'], $results[0]['extraTime'], $results[0]['groupID'], $this->getRoles($results[0]['id'])); } catch(PDOException $e ){ @@ -159,12 +160,13 @@ class UserGateway extends AbsGateway } } - public function findUserByEmail(string $email) : User{ + public function findUserByEmail(string $email){ try { $query = "SELECT * FROM User_ WHERE email=:email"; $args = array(':email' => array($email, PDO::PARAM_STR)); $this->con->executeQuery($query, $args); $results = $this->con->getResults(); + if (empty($results)) return null; return new User($results[0]['id'], $results[0]['password'], $results[0]['email'], $results[0]['name'], $results[0]['surname'], $results[0]['nickname'], $results[0]['image'], $results[0]['extraTime'], $results[0]['groupID'], $this->getRoles($results[0]['id'])); } catch(PDOException $e ){ @@ -296,17 +298,4 @@ class UserGateway extends AbsGateway throw new Exception($e->getMessage()); } } - public function checkIdExist(int $id): bool { - $query = "SELECT COUNT(*) AS count FROM User_ WHERE id = :id"; - $args = array(':id' => array($id, PDO::PARAM_INT)); - $this->con->executeQuery($query, $args); - $results = $this->con->getResults(); - - if (is_array($results) && count($results) > 0) { - $count = $results[0]['count']; - return ($count > 0); - } - - return false; - } } \ No newline at end of file diff --git a/Project/php/model/AbsModel.php b/Project/php/model/AbsModel.php index 919e20c..5c5f604 100755 --- a/Project/php/model/AbsModel.php +++ b/Project/php/model/AbsModel.php @@ -40,5 +40,10 @@ abstract class AbsModel $_SESSION = array(); } + public function checkLoginExist(string $login) { + $gtw = new UserGateway(); + return $gtw->findUserByEmail($login) != null; + } + public abstract function is(string $login, array $roles); } \ No newline at end of file diff --git a/Project/php/model/MdlStudent.php b/Project/php/model/MdlStudent.php index 08d16d9..d827743 100755 --- a/Project/php/model/MdlStudent.php +++ b/Project/php/model/MdlStudent.php @@ -13,10 +13,6 @@ class MdlStudent extends AbsModel { parent::__construct("student"); } - public function checkIdExist(int $id):bool { - $gtw = new UserGateway(); - return $gtw->checkIdExist($id); - } public function getAll():array{ $gtw = new VocabularyListGateway(); From 54bbd3e5a9d612a651d2eab9540c5373fd92b248 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Sun, 19 Nov 2023 18:00:03 +0100 Subject: [PATCH 4/6] avancement du quiz --- Project/php/controller/AbsController.php | 2 +- Project/php/controller/FrontController.php | 7 +---- Project/php/controller/StudentController.php | 11 +------ Project/php/templates/quizzView.html | 31 +++++++++++++------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php index 6633b4e..73630dc 100755 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -100,6 +100,6 @@ abstract class AbsController $allTranslation = $mdl->findByIdVoc($vocabId); $shuffle = $allTranslation; shuffle($shuffle); - echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']); + echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations' => $shuffle]); } } \ No newline at end of file diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index b2597d3..bfa626b 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -56,7 +56,7 @@ class FrontController $this->disconnect(); break; case 'quiz': - $this->quiz(); + AbsController::quiz(); break; default : @@ -128,10 +128,5 @@ class FrontController $mdl->deconnection(); $this->home(); } - public function quiz(){ - $ctrl = new StudentController(); - $ctrl->quiz(); - } - } \ No newline at end of file diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index 5569511..9e47f65 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -36,16 +36,7 @@ class StudentController echo $twig->render('manageVocabView.html', ['vocabularies' => $vocab]); } - public function quiz(): void - { - global $twig; - $vocabId = $_GET['vocabID']; - $mdl = new TranslationGateway(); - $allTranslation = $mdl->findByIdVoc($vocabId); - $shuffle = $allTranslation; - shuffle($shuffle); - echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']); - } + /* public function flashcard(VocabularyList $v) { $idVoc = $v->getId(); diff --git a/Project/php/templates/quizzView.html b/Project/php/templates/quizzView.html index a161632..e188dd4 100755 --- a/Project/php/templates/quizzView.html +++ b/Project/php/templates/quizzView.html @@ -8,19 +8,28 @@

Quiz

- {% if translations is defined %} - {% for translation in translations %} + {% if translations is defined %} + {% for translation in translations %}

{{ translation.word1 }}

- {% set correctAnswer = translation.word2 %} - {% set otherTranslations = [translation.word2, translations[0].word2, translations[1].word2, translations[2].word2] %} - {{ correctAnswer }}
- {% for otherTranslation in otherTranslations %} - {% if otherTranslation != correctAnswer %} - {{ otherAnswer }}
+ {% set correctAnswer = translation.word2 %} + {% if randomtranslations is defined %} + {% set otherTranslations = [correctAnswer] %} + {% for randomtranslation in randomtranslations %} + {% if randomtranslation.word2 != correctAnswer and otherTranslations|length <= 3 %} + {% set otherTranslations = otherTranslations|merge([randomtranslation.word2]) %} + {% endif %} + {% endfor %} + + + + {# Affichage des réponses sous forme de radio buttons #} + {{ correctAnswer }}
+ {% for otherTranslation in otherTranslations %} + {{ otherTranslation }}
+ {% endfor %} + {% endif %} + {% endfor %} {% endif %} - {% endfor %} - {% endfor %} - {% endif %} {% if submitted %} From 58aefe864e0668c00ac72da10f5525dfd337e283 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Sun, 19 Nov 2023 18:07:48 +0100 Subject: [PATCH 5/6] le quiz marche avec l'autoloader maintenant --- Project/php/controller/AbsController.php | 4 ++-- Project/php/controller/FrontController.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php index 73630dc..1ab18d3 100755 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -92,10 +92,10 @@ abstract class AbsController throw new Exception("Erreur"); } } - public function quiz(): void + public function quiz($match): void { global $twig; - $vocabId = $_GET['vocabID']; + $vocabId = Validation::filter_int($match['params']['id'] ?? null); $mdl = new TranslationGateway(); $allTranslation = $mdl->findByIdVoc($vocabId); $shuffle = $allTranslation; diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index bfa626b..7da60d3 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -56,7 +56,7 @@ class FrontController $this->disconnect(); break; case 'quiz': - AbsController::quiz(); + AbsController::quiz($match); break; default : From c59733d6b801064b031826ef958e2784c5de7535 Mon Sep 17 00:00:00 2001 From: "anthony.richard" Date: Sun, 19 Nov 2023 19:07:54 +0100 Subject: [PATCH 6/6] rangement --- Project/php/controller/AbsController.php | 30 +++++++++- Project/php/controller/FrontController.php | 59 ++------------------ Project/php/controller/StudentController.php | 21 ------- Project/php/templates/home.html | 2 +- Project/php/templates/login.html | 6 +- 5 files changed, 37 insertions(+), 81 deletions(-) mode change 100755 => 100644 Project/php/controller/AbsController.php diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php old mode 100755 new mode 100644 index 6633b4e..945c987 --- a/Project/php/controller/AbsController.php +++ b/Project/php/controller/AbsController.php @@ -9,7 +9,7 @@ use gateway\VocabularyListGateway; use model\MdlStudent; use model\VocabularyList; -abstract class AbsController +class AbsController { public function showAccountInfos(): void { @@ -92,7 +92,7 @@ abstract class AbsController throw new Exception("Erreur"); } } - public function quiz(): void + public static function quiz(): void { global $twig; $vocabId = $_GET['vocabID']; @@ -102,4 +102,30 @@ abstract class AbsController shuffle($shuffle); echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']); } + + public function login(): void { + global $twig; + echo $twig->render('login.html'); + } + + public function confirmLogin(): void { + $model = new MdlStudent(); + $login = strip_tags($_POST['logemail']); + $password = strip_tags($_POST['logpass']); + if (!$this->checkLoginExist($login)) throw new Exception(("login invalide")); + $user = $model->connection($login, $password); + if ($user == null) throw new Exception("mot de passe invalide"); + $this->home(); + } + + public function checkLoginExist(string $login): bool { + $mdl = new MdlStudent(); + return $mdl->checkLoginExist($login); + } + + public function disconnect(): void { + $mdl = new MdlStudent(); + $mdl->deconnection(); + $this->home(); + } } \ No newline at end of file diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index 97c0877..f5bcf73 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -19,11 +19,13 @@ class FrontController $router = new \AltoRouter(); $router->setBasePath($altorouterPath); - $router->map('GET', '/', 'AppController'); - $router->map('GET|POST', '/[a:action]?/[i:id]?', 'NULL'); + $router->map('GET', '/', 'FrontController'); $router->map('GET|POST', '/admin/[i:id]/[a:action]?', 'Admin'); $router->map('GET|POST', '/teacher/[i:id]/[a:action]?', 'Teacher'); $router->map('GET|POST', '/student/[i:id]/[a:action]?', 'Student'); + $router->map('GET|POST', '/abs/[a:action]?', 'Abs'); + + $twig->addGlobal('base', $altorouterPath); $match = $router->match(); @@ -40,26 +42,6 @@ class FrontController $this->home(); break; - case 'memory': - AbsController::memory($match); - break; - - case 'login': - $this->login(); - break; - - case 'confirmLogin': - $this->confirmLogin(); - break; - - case 'disconnect': - $this->disconnect(); - break; - - case 'quiz': - $this->quiz(); - break; - default : if ($target == null) throw new Exception("pas de target"); @@ -85,7 +67,7 @@ class FrontController break; } - else $this->login(); + else (new AbsController())->login(); } } } @@ -96,40 +78,9 @@ class FrontController } } - public function home(): void { global $twig; echo $twig->render('home.html'); var_dump($_SESSION['roles']); } - - public function login(): void { - global $twig; - echo $twig->render('login.html'); - } - - public function confirmLogin(): void { - $model = new MdlStudent(); - $login = strip_tags($_POST['logemail']); - $password = strip_tags($_POST['logpass']); - if (!$this->checkLoginExist($login)) throw new Exception(("login invalide")); - $user = $model->connection($login, $password); - if ($user == null) throw new Exception("mot de passe invalide"); - $this->home(); - } - - public function checkLoginExist(string $login): bool { - $mdl = new MdlStudent(); - return $mdl->checkLoginExist($login); - } - - public function disconnect(): void { - $mdl = new MdlStudent(); - $mdl->deconnection(); - $this->home(); - } - public function quiz(){ - $ctrl = new StudentController(); - $ctrl->quiz(); - } } \ No newline at end of file diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index 5569511..aef9087 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -35,25 +35,4 @@ class StudentController $vocab = $mdl->getVocabByName($name); echo $twig->render('manageVocabView.html', ['vocabularies' => $vocab]); } - - public function quiz(): void - { - global $twig; - $vocabId = $_GET['vocabID']; - $mdl = new TranslationGateway(); - $allTranslation = $mdl->findByIdVoc($vocabId); - $shuffle = $allTranslation; - shuffle($shuffle); - echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']); - } - /* - public function flashcard(VocabularyList $v) { - $idVoc = $v->getId(); - $mdl = new TranslationGateway(); - $allTranslation = $mdl->findByIdVoc($idVoc); - while(1) { - - } - } - }*/ } \ No newline at end of file diff --git a/Project/php/templates/home.html b/Project/php/templates/home.html index fbffde0..420f245 100755 --- a/Project/php/templates/home.html +++ b/Project/php/templates/home.html @@ -34,7 +34,7 @@ diff --git a/Project/php/templates/login.html b/Project/php/templates/login.html index 3b56b83..ce44e08 100755 --- a/Project/php/templates/login.html +++ b/Project/php/templates/login.html @@ -5,12 +5,12 @@ - + Login
- +
@@ -24,7 +24,7 @@

Log In

-
+