diff --git a/Project/php/assets/img/celeb.png b/Project/php/assets/img/celeb.png new file mode 100644 index 0000000..4a55ec4 Binary files /dev/null and b/Project/php/assets/img/celeb.png differ diff --git a/Project/php/assets/img/points.png b/Project/php/assets/img/points.png new file mode 100644 index 0000000..26c1b8a Binary files /dev/null and b/Project/php/assets/img/points.png differ diff --git a/Project/php/controller/AbsController.php b/Project/php/controller/AbsController.php old mode 100755 new mode 100644 index 7ea1463..0515142 --- 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 { @@ -64,7 +64,7 @@ abstract class AbsController global $twig; try{ - $idVoc = Validation::filter_int($match['params']['id'] ?? null); + $idVoc = Validation::filter_int($match['id'] ?? null); $wordList = (new \gateway\TranslationGateway)->findByIdVoc($idVoc); $wordShuffle = array(); @@ -92,14 +92,40 @@ 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['id'] ?? null); $mdl = new TranslationGateway(); $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]); + } + + 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..e259505 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -19,11 +19,14 @@ 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'); + $router->map('GET|POST', '/abs/[a:action]/[i:id]', 'Abs'); + + $twig->addGlobal('base', $altorouterPath); $match = $router->match(); @@ -35,57 +38,45 @@ class FrontController $action = Validation::val_action($match['params']['action'] ?? null); $id = $match['params']['id'] ?? null; - switch ($action) { - case null: - $this->home(); - break; - - case 'memory': - AbsController::memory($match); - break; - - case 'login': - $this->login(); - break; + if ($target == 'Abs') { + $abs = new AbsController(); + if (is_callable(array($abs, $action))) + call_user_func_array(array($abs, $action), array($match['params'])); + } + else { + switch ($action) { + case null: + $this->home(); + break; - case 'confirmLogin': - $this->confirmLogin(); - break; + default : + if ($id != null && !$this->checkIdExist($id)) throw new Exception("identifiant invalide"); + if ($target == null) throw new Exception("pas de target"); - case 'disconnect': - $this->disconnect(); - break; + if (isset($_SESSION['login']) && isset($_SESSION['roles'])) { - case 'quiz': - $this->quiz(); - break; + $_SESSION['login'] = strip_tags($_SESSION['login']); + for ($i=0 ; $igetId() != $id) throw new Exception("erreur 403 permission denied"); + } - $mdl = '\\model\\Mdl' . $target; - $mdl = new $mdl; + $controller = '\\controller\\' . $target . 'Controller'; + $controller = new $controller; - if (is_callable(array($mdl, 'is'))) { - $user = call_user_func_array(array($mdl, 'is'), array($_SESSION['login'], $_SESSION['roles'])); + if (is_callable(array($controller, $action))) + call_user_func_array(array($controller, $action), array($match['params'])); - if (!$user || $user->getId() != $id) throw new Exception("erreur 403 permission denied"); + break; } - - $controller = '\\controller\\' . $target . 'Controller'; - $controller = new $controller; - - if (is_callable(array($controller, $action))) - call_user_func_array(array($controller, $action), array($match['params'])); - - break; - } - else $this->login(); + else (new AbsController())->login(); + } } } } @@ -96,40 +87,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

-
+
diff --git a/Project/php/templates/quizzView.html b/Project/php/templates/quizzView.html index a161632..f2d75fc 100755 --- a/Project/php/templates/quizzView.html +++ b/Project/php/templates/quizzView.html @@ -5,24 +5,51 @@ Manage groups -
+

Quiz

- - {% 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 }}
+
+ {% if translations is defined %} + {% for translation in translations %} +

{{ translation.word1 }}

+ {% 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 %} - {% endfor %} - {% endif %} - + {% endfor %} + +
+ {{ correctAnswer }}
+
+ {% for otherTranslation in otherTranslations %} + {{ otherTranslation }}
+ + {% endfor %} + + +
+ + {% endif %} + {% endfor %} + {% endif %} + {% if submitted %} {% if isCorrect %}

Correct answer!

@@ -45,4 +72,64 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/Project/php/templates/resultatsJeux.html b/Project/php/templates/resultatsJeux.html new file mode 100644 index 0000000..4e81204 --- /dev/null +++ b/Project/php/templates/resultatsJeux.html @@ -0,0 +1,53 @@ + + + + + + + Félicitations! + + + + +
+
+ Bravo ! Vous avez gagné 125 points !! +
+ Célébration +
+ +