From dbb85c2c681f4addfaf0e3324b1bfe2d81fd784c Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Sat, 18 Nov 2023 16:06:54 +0100 Subject: [PATCH] =?UTF-8?q?modification=20du=20modele=20de=20student=20et?= =?UTF-8?q?=20de=20son=20controller=20pour=20rendre=20certaines=20methodes?= =?UTF-8?q?=20fonctionnel,=20d=C3=A9but=20de=20modification=20du=20frontCo?= =?UTF-8?q?ntroller=20pour=20rendre=20les=20connexion=20plus=20securis?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/php/controller/FrontController.php | 85 +++++++++++--------- Project/php/controller/StudentController.php | 9 ++- Project/php/model/MdlStudent.php | 6 +- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/Project/php/controller/FrontController.php b/Project/php/controller/FrontController.php index 4f6e544..bb85901 100755 --- a/Project/php/controller/FrontController.php +++ b/Project/php/controller/FrontController.php @@ -8,14 +8,15 @@ use model\MdlStudent; class FrontController { - public function __construct() { + public function __construct() + { global $twig; global $altorouterPath; session_start(); - //var_dump($_SESSION['login']); - //var_dump($_SESSION['roles']); + var_dump($_SESSION['login']); + var_dump($_SESSION['roles']); try { $router = new \AltoRouter(); @@ -23,46 +24,58 @@ class FrontController $router->map('GET', '/', 'AppController'); $router->map('GET|POST', '/[a:action]?', 'NULL'); - $router->map( 'GET|POST', '/admin/[i:id]/[a:action]?', 'AdminController'); - $router->map( 'GET|POST', '/teacher/[i:id]/[a:action]?', 'TeacherController'); - $router->map( 'GET|POST', '/student/[i:id]/[a:action]?', 'StudentController'); + $router->map('GET|POST', '/admin/[i:id]/[a:action]?', 'AdminController'); + $router->map('GET|POST', '/teacher/[i:id]/[a:action]?', 'TeacherController'); + $router->map('GET|POST', '/student/[i:id]/[a:action]?', 'StudentController'); $match = $router->match(); - if (!$match) { throw new Exception("Erreur 404");} - - $controller = $match['target'] ?? null; - $action = Validation::val_action($match['params']['action'] ?? null); - - switch ($action) { - case null: - $this->home(); - break; - - case 'login': - $this->login(); - break; - - case 'confirmLogin': - $this->confirmLogin(); - break; - - default : - $controller = '\\controller\\' . $controller; - $controller = new $controller; - - if (is_callable(array($controller, $action))) - call_user_func_array(array($controller, $action), array($match['params'])); - - break; + if (!$match) { + throw new Exception("Erreur 404"); + } + if ($match) { +//list($controller, $action) = explode('#', $match['target'] ); + $controller = $match['target'] ?? null; + $action = Validation::val_action($match['params']['action'] ?? null); + $id = $match['params']['id'] ?? null; + print 'user Id received ' . $id . '
'; + print 'controleur appelé ' . $controller . '
'; + print $action . '
'; + print $id . '
'; + + + switch ($action) { + case null: + $this->home(); + break; + + case 'login': + $this->login(); + break; + + case 'confirmLogin': + $this->confirmLogin(); + break; + + default : + $controller = '\\controller\\' . $controller; + $controller = new $controller; + + if (is_callable(array($controller, $action))) + call_user_func_array(array($controller, $action), array($match['params'])); + + break; + } } } - catch (Exception $e) { - $dVueEreur[] = $e->getMessage(); - echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); - } + catch + (Exception $e) { + $dVueEreur[] = $e->getMessage(); + echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); + } } + public function home(): void { global $twig; echo $twig->render('home.html'); diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index 1ed57d2..eda3c1c 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -12,8 +12,8 @@ class StudentController { global $twig; $mdl = new MdlStudent(); - $student = $mdl->getAll(); - echo $twig->render('usersView.html', ['users' => $student]); + $voc = $mdl->getAll(); + echo $twig->render('manageVocabListView.html', ['vocabularies' => $voc]); } @@ -26,12 +26,13 @@ class StudentController } - public function getByName($name): void + public function getByName(): void { global $twig; $mdl = new MdlStudent(); + $name = Validation::filter_str_simple($_GET['listName'] ?? null); $vocab = $mdl->getVocabByName($name); - echo $twig->render('usersView.html', ['users' => $vocab]); + echo $twig->render('manageVocabView.html', ['vocabularies' => $vocab]); } public function showAccountInfos(): void { diff --git a/Project/php/model/MdlStudent.php b/Project/php/model/MdlStudent.php index 3b8e6ac..befc845 100755 --- a/Project/php/model/MdlStudent.php +++ b/Project/php/model/MdlStudent.php @@ -4,6 +4,8 @@ namespace model; use gateway\UserGateway; use gateway\VocabularyGateway; +use gateway\VocabularyListGateway; + class MdlStudent extends AbsModel { @@ -14,7 +16,7 @@ class MdlStudent extends AbsModel public function getAll():array{ global $twig; - $gtw = new VocabularyGateway(); + $gtw = new VocabularyListGateway(); return $gtw->findAll(); /* foreach ($data as $row){ @@ -25,7 +27,7 @@ class MdlStudent extends AbsModel } public function getVocabByName(string $name):array{ - $gtw = new VocabularyGateway(); + $gtw = new VocabularyListGateway(); $res = $gtw->findByName($name); return $res; }