diff --git a/Project/php/controller/StudentController.php b/Project/php/controller/StudentController.php index d5fadef..088e314 100755 --- a/Project/php/controller/StudentController.php +++ b/Project/php/controller/StudentController.php @@ -8,23 +8,21 @@ use config\Connection; class StudentController { - public function __construct(){ + public function __construct() + { global $twig; - global $gtw; - global $con; - $con = new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger'); - $gtw = new UserGateway($con); - $actionList = ['showUsers']; - $dVueEreur= []; session_start(); - try{ - $action = $_REQUEST['action']?? null; - switch($action) { - case "AllVocab": - affAllVocab(); + $actionList = ['showVocab', 'getByName']; + $dVueEreur = []; + try { + $action = $_REQUEST['action'] ?? null; + switch ($action) { + case 'allVocab': + case null: + $this->affAllVocab(); break; - case "getByName": - getByName(); + case 'getByName': + $this->getByName($_REQUEST['nom']); break; default: @@ -32,33 +30,41 @@ class StudentController echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]); break; } - } - catch(\PDOException $e){ - $dataVueEreur[]= "Erreur inattendue"; - $twig->render("vuephp1.html",['dVueErreur' =>$dataVueEreur]); + } catch (\PDOException $e) { + $dataVueEreur[] = "Erreur inattendue"; + $twig->render("vuephp1.html", ['dVueErreur' => $dataVueEreur]); - } - catch (Exception $e2) - { + } catch (Exception $e2) { $dataVueEreur[] = "Erreur inattendue!!! "; require($dataVueEreur['erreur']); } } - public function affAllVocab():void{ + public function affAllVocab(): void + { + global $twig; + $mdl = new MdlStudent(); + $student = $mdl->getAll(); + echo $twig->render('usersView.html', ['users' => $student]); + + } + + public function affAllStudent(): void + { global $twig; $mdl = new MdlStudent(); $student = $mdl->getAll(); - echo $twig->render('usersView.html', ['users'=> $student]); + echo $twig->render('usersView.html', ['users' => $student]); } - public function getByName($name):void{ - global $twig; - $mdl = new MdlStudent(); - $vocab = $mdl->getVocabByName($name); - echo $twig->render('usersView.html', ['users'=> $vocab]); + public function getByName($name): void + { + global $twig; + $mdl = new MdlStudent(); + $vocab = $mdl->getVocabByName($name); + echo $twig->render('usersView.html', ['users' => $vocab]); + } - } } diff --git a/Project/php/controller/TeacherController.php b/Project/php/controller/TeacherController.php new file mode 100755 index 0000000..e2dc9b0 --- /dev/null +++ b/Project/php/controller/TeacherController.php @@ -0,0 +1,89 @@ +affAllStudent(); + break; + + case 'allVocab': + $this->affAllVocab(); + break; + case 'getVocabByName': + $this->getByName($_REQUEST['name']); + break; + case 'addVocab': + break; + + /* case 'delVoc': + $this->delById($_REQUEST['id']); + break;*/ + + default: + $dVueEreur[] = "Erreur d'appel php"; + echo $twig->render('vuephp1.html', ['dVueEreur' => $dVueEreur]); + break; + } + } + catch (\PDOException $e) { + $dataVueEreur[] = "Erreur inattendue"; + $twig->render("vuephp1.html", ['dVueErreur' => $dataVueEreur]); + + } catch (Exception $e2) { + $dataVueEreur[] = "Erreur inattendue!!! "; + require($dataVueEreur['erreur']); + } + } + public function affAllStudent(): void + { + global $twig; + $mdl = new MdlTeacher(); + $student = $mdl->getAllStudent(); + echo $twig->render('usersView.html', ['users' => $student]); + + } + + + public function affAllVocab(): void + { + global $twig; + $mdl = new MdlTeacher(); + $student = $mdl->getAll(); + echo $twig->render('usersView.html', ['users' => $student]); + + } + + public function getByName($name): void + { + global $twig; + $mdl = new MdlTeacher(); + $vocab = $mdl->getVocabByName($name); + echo $twig->render('usersView.html', ['users' => $vocab]); + + } + + public function DelById($id):void{ + global $twig; + $mdl = new MdlTeacher(); + $vocab = $mdl->removeVocById($id); + echo $twig->render('usersView.html', ['users' => $vocab]); + + } + + + +} \ No newline at end of file diff --git a/Project/php/model/MdlTeacher.php b/Project/php/model/MdlTeacher.php new file mode 100755 index 0000000..8faa491 --- /dev/null +++ b/Project/php/model/MdlTeacher.php @@ -0,0 +1,48 @@ +findAll(); + /* + foreach ($data as $row){ + $AllStudent[] = User($row['id'],$row['password'],$row['email'],$row['name'],$row['surname'],$row['nickname'],$row['image'],$row['extraTime'],$row['group'],$row['roles']); + } + return $AllStudent; + */ + } + + public function getAllStudent():array { + $gtw = new UserGateway(new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger')); + return $gtw->findAll(); + } + + public function getVocabByName($name):array{ + $gtw = new VocabularyGateway(new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger')); + $res = $gtw->findByName($name); + return $res; + } + + public function RemoveVocById($id):void{ + $gtw = new VocabularyGateway(new Connection('mysql:host=localhost;dbname=dbanrichard7','anrichard7','achanger')); + $res = $gtw->remove($id); + } + + + + +} \ No newline at end of file