From 790f8b6fd00f4f450a190967b1a67f87a78600a2 Mon Sep 17 00:00:00 2001 From: "anthony.richard" Date: Mon, 20 Nov 2023 17:07:23 +0100 Subject: [PATCH 1/4] =?UTF-8?q?s=C3=A9paration=20user=20visitor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/php/controller/AdminController.php | 2 +- Project/php/controller/FrontController.php | 7 +- Project/php/controller/StudentController.php | 2 +- Project/php/controller/TeacherController.php | 2 +- Project/php/controller/UserController.php | 120 +------------------ Project/php/controller/VisitorController.php | 116 ++++++++++++++++++ Project/php/model/MdlStudent.php | 15 --- Project/php/model/MdlUser.php | 31 +++++ 8 files changed, 157 insertions(+), 138 deletions(-) create mode 100755 Project/php/controller/VisitorController.php create mode 100755 Project/php/model/MdlUser.php diff --git a/Project/php/controller/AdminController.php b/Project/php/controller/AdminController.php index cbc9da9..24882d8 100755 --- a/Project/php/controller/AdminController.php +++ b/Project/php/controller/AdminController.php @@ -6,7 +6,7 @@ use config\Validation; use model\MdlAdmin; use Exception; -class AdminController +class AdminController extends UserController { public function showAllUsers(): void { global $twig; diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index 5c31005..1d3873d 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -23,8 +23,7 @@ class 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', '/user/[a:action]?', 'User'); - $router->map('GET|POST', '/user/[a:action]/[i:id]', 'User'); + $router->map('GET|POST', '/visitor/[a:action]/[i:id]?', 'Visitor'); $twig->addGlobal('base', $altorouterPath); @@ -38,8 +37,8 @@ class FrontController $action = Validation::val_action($match['params']['action'] ?? null); $id = $match['params']['id'] ?? null; - if ($target == 'User') { - $userCtrl = new UserController(); + if ($target == 'Visitor') { + $userCtrl = new VisitorController(); if (is_callable(array($userCtrl, $action))) call_user_func_array(array($userCtrl, $action), array($match['params'])); } diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index aef9087..1e716d7 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -6,7 +6,7 @@ use model\MdlStudent; use gateway\TranslationGateway; use Exception; -class StudentController +class StudentController extends UserController { public function affAllVocab(): void { diff --git a/Project/php/controller/TeacherController.php b/Project/php/controller/TeacherController.php index da42c5e..48e99a4 100755 --- a/Project/php/controller/TeacherController.php +++ b/Project/php/controller/TeacherController.php @@ -6,7 +6,7 @@ use model\MdlTeacher; use gateway\VocabularyListGateway; use Exception; -class TeacherController +class TeacherController extends UserController { public function affAllStudent(): void { diff --git a/Project/php/controller/UserController.php b/Project/php/controller/UserController.php index cd43abb..a3d9b36 100755 --- a/Project/php/controller/UserController.php +++ b/Project/php/controller/UserController.php @@ -10,20 +10,13 @@ use model\MdlStudent; use model\VocabularyList; use model\Translation; -class UserController +class UserController extends VisitorController { public function showAccountInfos(): void { - try { - global $twig; - $userID = Validation::filter_int($_GET['user'] ?? null); - $mdl = new MdlStudent(); - $user = $mdl->getUser($userID); - echo $twig->render('myAccountView.html', ['user' => $user]); - } - catch (Exception $e){ - throw new Exception("invalid user ID"); - } + global $twig; + global $user; + echo $twig->render('myAccountView.html', ['user' => $user, 'userID' => $user->getId(), 'userRole' => $user->getRoles()]); } public function modifyPassword(): void { @@ -60,109 +53,4 @@ class UserController throw new Exception("invalid entries"); } } - - public static function memory($match): void{ - global $twig; - - try{ - $idVoc = Validation::filter_int($match['id'] ?? null); - $wordList = (new \gateway\TranslationGateway)->findByIdVoc($idVoc); - $wordShuffle = array(); - - shuffle($wordList); - $pairs = []; - $maxWords = 28; - - for ($i = 0; $i < min(count($wordList), $maxWords / 2); $i++) { - $wordShuffle[] = $word1 = $wordList[$i]->getWord1(); - $wordShuffle[] = $word2 = $wordList[$i]->getWord2(); - - $pairs[] = [$word1, $word2]; - } - - - shuffle($wordShuffle); - - echo $twig->render('memory.html', [ - 'wordShuffle' => $wordShuffle, - 'pairs' => json_encode($pairs), - ]); - - } - catch (Exception $e){ - throw new Exception("Erreur"); - } - } - public function quiz($match): void - { - 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; - shuffle($shuffle); - - $questions = array(); - $goodAnswers = array(); - $allEnglishWords = array(); - - foreach ($allTranslation as $translation) { - $questions[] = $translation->getWord1(); - $allEnglishWords[] = $translation->getWord2(); - $goodAnswers[] = $translation->getWord2(); - } - - $answers = array(); - - for($i=0 ; $i< count($questions) ; $i++) { - $correctAnswer = $allTranslation[$i]->getWord2(); - array_splice($allEnglishWords, array_search($correctAnswer, $allEnglishWords), 1); - - $tab = array_rand(array_flip($allEnglishWords), 3); - - array_push($allEnglishWords, $correctAnswer); - - $tab[] = $correctAnswer; - shuffle($tab); - $answers[] = $tab; - } - - echo $twig->render('quizView.html', ['questions' => $questions, 'answers' => $answers, 'goodAnswers' => $goodAnswers, 'listName' => $vocabList->getName()]); - } - - public function login(): void { - global $twig; - echo $twig->render('login.html'); - } - - public function confirmLogin(): void { - $model = new MdlStudent(); - if($_POST['logemail']!=null && $_POST['logpass']!=null) { - $login = strip_tags($_POST['logemail']); - $password = strip_tags($_POST['logpass']); - } - else throw new Exception("logmail ou logpass null"); - if (!$this->checkLoginExist($login)) throw new Exception(("login invalide")); - $user = $model->connection($login, $password); - if ($user == null) throw new Exception("mot de passe invalide"); - FrontController::home(); - } - - public function checkLoginExist(string $login): bool { - $mdl = new MdlStudent(); - return $mdl->checkLoginExist($login); - } - - public function disconnect(): void { - $mdl = new MdlStudent(); - $mdl->deconnection(); - FrontController::home(); - } - - public function resultatsJeux(): void{ - global $twig; - echo $twig->render('resultatsJeux.html'); - } } \ No newline at end of file diff --git a/Project/php/controller/VisitorController.php b/Project/php/controller/VisitorController.php new file mode 100755 index 0000000..78f66cd --- /dev/null +++ b/Project/php/controller/VisitorController.php @@ -0,0 +1,116 @@ +findByIdVoc($idVoc); + $wordShuffle = array(); + + shuffle($wordList); + $pairs = []; + $maxWords = 28; + + for ($i = 0; $i < min(count($wordList), $maxWords / 2); $i++) { + $wordShuffle[] = $word1 = $wordList[$i]->getWord1(); + $wordShuffle[] = $word2 = $wordList[$i]->getWord2(); + + $pairs[] = [$word1, $word2]; + } + + + shuffle($wordShuffle); + + echo $twig->render('memory.html', [ + 'wordShuffle' => $wordShuffle, + 'pairs' => json_encode($pairs), + ]); + + } + catch (Exception $e){ + throw new Exception("Erreur"); + } + } + public function quiz($match): void + { + 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; + shuffle($shuffle); + + $questions = array(); + $goodAnswers = array(); + $allEnglishWords = array(); + + foreach ($allTranslation as $translation) { + $questions[] = $translation->getWord1(); + $allEnglishWords[] = $translation->getWord2(); + $goodAnswers[] = $translation->getWord2(); + } + + $answers = array(); + + for($i=0 ; $i< count($questions) ; $i++) { + $correctAnswer = $allTranslation[$i]->getWord2(); + array_splice($allEnglishWords, array_search($correctAnswer, $allEnglishWords), 1); + + $tab = array_rand(array_flip($allEnglishWords), 3); + + array_push($allEnglishWords, $correctAnswer); + + $tab[] = $correctAnswer; + shuffle($tab); + $answers[] = $tab; + } + + echo $twig->render('quizView.html', ['questions' => $questions, 'answers' => $answers, 'goodAnswers' => $goodAnswers, 'listName' => $vocabList->getName()]); + } + + public function login(): void { + global $twig; + echo $twig->render('login.html'); + } + + public function confirmLogin(): void { + $model = new MdlUser(); + if($_POST['logemail']!=null && $_POST['logpass']!=null) { + $login = strip_tags($_POST['logemail']); + $password = strip_tags($_POST['logpass']); + } + else throw new Exception("logmail ou logpass null"); + if (!$this->checkLoginExist($login)) throw new Exception(("login invalide")); + $user = $model->connection($login, $password); + if ($user == null) throw new Exception("mot de passe invalide"); + FrontController::home(); + } + + public function checkLoginExist(string $login): bool { + $mdl = new MdlUser(); + return $mdl->checkLoginExist($login); + } + + public function disconnect(): void { + $mdl = new MdlUser(); + $mdl->deconnection(); + FrontController::home(); + } + + public function resultatsJeux(): void{ + global $twig; + echo $twig->render('resultatsJeux.html'); + } +} \ No newline at end of file diff --git a/Project/php/model/MdlStudent.php b/Project/php/model/MdlStudent.php index d827743..98bf2fd 100755 --- a/Project/php/model/MdlStudent.php +++ b/Project/php/model/MdlStudent.php @@ -31,21 +31,6 @@ class MdlStudent extends AbsModel return $res; } - public function getUser(int $id): User{ - $gtw = new UserGateway(); - return $gtw->findById($id); - } - - public function modifyNickname(int $id, string $newNickname): void{ - $gtw = new UserGateway(); - $gtw->modifyNickname($id, $newNickname); - } - - public function ModifyPassword(int $id, string $newPassword): void { - $gtw = new UserGateway(); - $gtw->modifyPassword($id, $newPassword); - } - public function is(string $login, array $roles) { $gtw = new UserGateway(); diff --git a/Project/php/model/MdlUser.php b/Project/php/model/MdlUser.php new file mode 100755 index 0000000..294f1fd --- /dev/null +++ b/Project/php/model/MdlUser.php @@ -0,0 +1,31 @@ +findById($id); + } + + public function modifyNickname(int $id, string $newNickname): void{ + $gtw = new UserGateway(); + $gtw->modifyNickname($id, $newNickname); + } + + public function ModifyPassword(int $id, string $newPassword): void { + $gtw = new UserGateway(); + $gtw->modifyPassword($id, $newPassword); + } + + public function is(string $login, array $roles) + { + $gtw = new UserGateway(); + $user = $gtw->findUserByEmail($login); + + if (!empty($user->getRoles())) return $user; + else return false; + } +} From 81689755a5a533c51ed2dfe90637a114c5b5eaf3 Mon Sep 17 00:00:00 2001 From: Antoine Jourdain Date: Mon, 20 Nov 2023 17:12:46 +0100 Subject: [PATCH 2/4] Transition des cartes --- Project/php/css/memory.css | 13 +++++++++++-- Project/php/templates/memory.html | 14 ++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Project/php/css/memory.css b/Project/php/css/memory.css index 4a503bb..00968b9 100755 --- a/Project/php/css/memory.css +++ b/Project/php/css/memory.css @@ -6,6 +6,7 @@ body { background-color: #f0f0f0; margin-left: 15vh; margin-right: 15vh; + overflow: hidden; } #memory-game { @@ -14,6 +15,7 @@ body { grid-template-rows: repeat(4, minmax(0, 1fr)); gap: 10px; margin: auto; + perspective: 1000px; } .card { @@ -27,15 +29,22 @@ body { align-items: center; font-size: 18px; cursor: pointer; - transition: background-color 0.3s ease; + transition: transform 0.6s ease; + transform-style: preserve-3d; min-height: 10vh; min-width: 20vh; aspect-ratio: 1/1; } +.card span { + backface-visibility: hidden; +} + + .flipped { background: url("../assets/img/carte.png") no-repeat scroll center; background-size: cover; + transform: rotateY(180deg); } .flipped>span{ @@ -61,4 +70,4 @@ body { .hidden { display: none; -} +} \ No newline at end of file diff --git a/Project/php/templates/memory.html b/Project/php/templates/memory.html index 5f12a8f..db1095d 100755 --- a/Project/php/templates/memory.html +++ b/Project/php/templates/memory.html @@ -7,15 +7,17 @@ -
- {% for word in wordShuffle %} -
- {{ word }} +
+

Memory Game : {{ nameVoc }}

+
+ {% for word in wordShuffle %} +
+ {{ word }} +
+ {% endfor %}
- {% endfor %}
- From 76e58f4efc878d47e9255f7e787927fabfb735f6 Mon Sep 17 00:00:00 2001 From: "lucie.goigoux2" Date: Mon, 20 Nov 2023 17:13:40 +0100 Subject: [PATCH 3/4] modif --- Project/php/templates/{addVocalList.html => addVocabList.html} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Project/php/templates/{addVocalList.html => addVocabList.html} (100%) diff --git a/Project/php/templates/addVocalList.html b/Project/php/templates/addVocabList.html similarity index 100% rename from Project/php/templates/addVocalList.html rename to Project/php/templates/addVocabList.html From d023a0ca52bc341919ec867d636e9932fa384edc Mon Sep 17 00:00:00 2001 From: "anthony.richard" Date: Mon, 20 Nov 2023 17:14:46 +0100 Subject: [PATCH 4/4] routes --- Project/php/model/MdlAdmin.php | 2 +- Project/php/model/MdlStudent.php | 2 +- Project/php/model/MdlTeacher.php | 2 +- Project/php/model/MdlUser.php | 6 +----- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Project/php/model/MdlAdmin.php b/Project/php/model/MdlAdmin.php index c37b577..a78a7d4 100755 --- a/Project/php/model/MdlAdmin.php +++ b/Project/php/model/MdlAdmin.php @@ -5,7 +5,7 @@ namespace model; use gateway\GroupGateway; use gateway\UserGateway; -class MdlAdmin extends AbsModel +class MdlAdmin extends MdlUser { public function __construct() { diff --git a/Project/php/model/MdlStudent.php b/Project/php/model/MdlStudent.php index 98bf2fd..4333d12 100755 --- a/Project/php/model/MdlStudent.php +++ b/Project/php/model/MdlStudent.php @@ -6,7 +6,7 @@ use gateway\UserGateway; use gateway\VocabularyGateway; use gateway\VocabularyListGateway; -class MdlStudent extends AbsModel +class MdlStudent extends MdlUser { public function __construct() diff --git a/Project/php/model/MdlTeacher.php b/Project/php/model/MdlTeacher.php index 5fc3a4b..2ee07b0 100755 --- a/Project/php/model/MdlTeacher.php +++ b/Project/php/model/MdlTeacher.php @@ -7,7 +7,7 @@ use gateway\UserGateway; use gateway\VocabularyGateway; use gateway\VocabularyListGateway; -class MdlTeacher extends AbsModel +class MdlTeacher extends MdlUser { public function __construct() diff --git a/Project/php/model/MdlUser.php b/Project/php/model/MdlUser.php index 294f1fd..6d95345 100755 --- a/Project/php/model/MdlUser.php +++ b/Project/php/model/MdlUser.php @@ -4,11 +4,7 @@ namespace model; use gateway\UserGateway; -public class MdlUser extends AbsModel { - public function getUser(int $id): User{ - $gtw = new UserGateway(); - return $gtw->findById($id); - } +class MdlUser extends AbsModel { public function modifyNickname(int $id, string $newNickname): void{ $gtw = new UserGateway();