From 26e98ed144640c8fc93445ce60391ad18ced33fd Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Tue, 21 Nov 2023 13:28:32 +0100 Subject: [PATCH] ajout d'un fonction pour que le teacher vois que ses listes --- Project/php/controller/TeacherController.php | 8 ++++++++ Project/php/gateway/VocabularyListGateway.php | 15 +++++++++++++++ Project/php/model/MdlTeacher.php | 6 ++++++ Project/php/templates/manageVocabListView.html | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Project/php/controller/TeacherController.php b/Project/php/controller/TeacherController.php index 82a2197..f4f88b7 100755 --- a/Project/php/controller/TeacherController.php +++ b/Project/php/controller/TeacherController.php @@ -18,6 +18,14 @@ class TeacherController extends UserController $groups = $mdl->getAllGroups(); echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocabularies, 'groups' => $groups, 'userID' => $user->getId(), 'userRole' => $user->getRoles()]); } + public function findByUser():void { + global $twig; + global $user; + $mdl = new MdlTeacher(); + $vocabularies = $mdl->findByUser($user->getId()); + $groups = $mdl->getAllGroups(); + echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocabularies, 'groups' => $groups, 'userID' => $user->getId(), 'userRole' => $user->getRoles()]); + } public function DelById():void{ global $user; diff --git a/Project/php/gateway/VocabularyListGateway.php b/Project/php/gateway/VocabularyListGateway.php index 4714986..ee0b356 100755 --- a/Project/php/gateway/VocabularyListGateway.php +++ b/Project/php/gateway/VocabularyListGateway.php @@ -131,4 +131,19 @@ class VocabularyListGateway extends AbsGateway throw new Exception($e->getMessage()); } } + + public function findByUser(int $id): array { + try { + $query = "SELECT v.* FROM VocabularyList v, User_ u WHERE v.userID =u.id AND u.id=:id"; + $args = array(':id' => array($id, PDO::PARAM_INT)); + $this->con->executeQuery($query, $args); + $results = $this->con->getResults(); + $tab = array(); + foreach ($results as $row) $tab[] = new VocabularyList($row['id'], $row['name'], $row['image'], $row['userID']); + return $tab; + } + catch (PDOException $e) { + throw new Exception($e->getMessage()); + } + } } \ No newline at end of file diff --git a/Project/php/model/MdlTeacher.php b/Project/php/model/MdlTeacher.php index fddc44d..62ab657 100755 --- a/Project/php/model/MdlTeacher.php +++ b/Project/php/model/MdlTeacher.php @@ -24,6 +24,12 @@ class MdlTeacher extends MdlUser $gtw = new UserGateway(); return $gtw->findAll(); } + public function findByUser($id):array + { + $gtw = new VocabularyListGateway(); + return $gtw->findByUser($id); + } + public function getVocabByName(string $name):array{ $gtw = new VocabularyListGateway(); diff --git a/Project/php/templates/manageVocabListView.html b/Project/php/templates/manageVocabListView.html index 0a66216..d3cd868 100755 --- a/Project/php/templates/manageVocabListView.html +++ b/Project/php/templates/manageVocabListView.html @@ -29,7 +29,7 @@

My lists

- {% include 'vocabularyContainer.twig' with {'actions' : ['affContent', 'delById', 'getContent' ], 'vocabularies' : vocabularies, 'vocabID' : vocabID, 'content' : content } %} + {% include 'vocabularyContainer.twig' with {'actions' : ['findByUser', 'delById', 'getContent' ], 'vocabularies' : vocabularies, 'vocabID' : vocabID, 'content' : content } %}

Content