diff --git a/Project/php/controller/TeacherController.php b/Project/php/controller/TeacherController.php index fb51a9c..95244c1 100755 --- a/Project/php/controller/TeacherController.php +++ b/Project/php/controller/TeacherController.php @@ -5,15 +5,17 @@ use config\Validation; use model\MdlTeacher; use gateway\VocabularyListGateway; use Exception; +use model\MdlUser; class TeacherController extends UserController { public function affAllStudent(): void { global $twig; + global $user; $mdl = new MdlTeacher(); $student = $mdl->getAllStudent(); - echo $twig->render('usersView.html', ['users' => $student]); + echo $twig->render('usersView.html', ['users' => $student, 'userID' => $user->getId(), 'userRole' => $user->getRoles()]); } @@ -24,7 +26,7 @@ class TeacherController extends UserController $id = $user->getId(); $mdl = new MdlTeacher(); $vocabularies = $mdl->getAll(); - echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocabularies, 'userId' => $id]); + echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocabularies, 'userID' => $user->getId(), 'userRole' => $user->getRoles()]); } public function getByName(): void @@ -35,7 +37,7 @@ class TeacherController extends UserController $id = $user->getId(); $name = Validation::filter_str_simple($_GET['listName'] ?? null); $vocab = $mdl->getVocabByName($name); - echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocab, 'selectedName' => $name, 'userId' => $id ]); + echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocab, 'selectedName' => $name, 'userID' => $user->getId(), 'userRole' => $user->getRoles() ]); } @@ -45,28 +47,37 @@ class TeacherController extends UserController $mdl = new MdlTeacher(); $id = $user->getId(); $vocab = $mdl->removeVocById($id); - echo $twig->render('manageVocabListView.html', [ 'vocabularies' => $vocab, 'userId' => $id ]); + echo $twig->render('manageVocabListView.html', [ 'vocabularies' => $vocab, 'userID' => $user->getId(), 'userRole' => $user->getRoles() ]); } public function showVocabListForm(): void { global $twig; - $userID = Validation::filter_int($_GET['userID'] ?? null); - echo $twig->render('addVocabList.html', ['user' => $userID]); + global $user; + echo $twig->render('addVocabList.html', ['userID' => $user->getId(), 'userRole' => $user->getRoles() ]); } public function addVocabList():void { global $twig; global $user; - $id = $user->getId(); $mdl = new MdlTeacher(); - $name = Validation::filter_str_simple($_GET['listName'] ?? null); + $name = Validation::filter_str_simple($_POST['listName'] ?? null); $words = array(); - $frenchWord = Validation::filter_str_simple($_GET['frenchWord'] ?? null); - $englishWord = Validation::filter_str_simple($_GET['englishWord'] ?? null); + + for ($i = 0; $i <= 19; $i++) { + echo $i; + if (!isset($_POST['frenchWord' . $i]) == null || !isset($_POST['englishWord' . $i]) == null) break; + + $frenchWord = Validation::filter_str_simple($_POST['frenchWord' . $i] ?? null); + $englishWord = Validation::filter_str_simple($_POST['englishWord' . $i] ?? null); + $words[] = array($frenchWord, $englishWord); - var_dump($words); - $addvoc= $mdl->addVocabList($id, $name, "", $words); - echo $twig->render('manageVocabListView.html', [ 'vocabularies' => $addvoc ,'userId' => $id]); + } + + if (count($words) % 2 == 1) throw new Exception("il manque un mot"); + else { + $addvoc= $mdl->addVocabList($user->getId(), $name, "", $words); + $this->affAllVocab(); + } } } \ No newline at end of file diff --git a/Project/php/templates/addVocabList.html b/Project/php/templates/addVocabList.html index 3f6da50..7e096be 100755 --- a/Project/php/templates/addVocabList.html +++ b/Project/php/templates/addVocabList.html @@ -15,22 +15,21 @@ href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet" /> - + -{% include 'navbar.twig' %} +{% include 'navBar.twig' %}