From 1f9ef8b535c5302dd4fc837c99de92a1651ce674 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Tue, 21 Nov 2023 11:03:34 +0100 Subject: [PATCH] vocab --- Project/php/controller/TeacherController.php | 37 ++++++++++++------- Project/php/templates/addVocabList.html | 11 +++--- Project/php/templates/home.html | 2 +- Project/php/templates/manageGroupView.html | 2 +- .../php/templates/manageVocabListView.html | 30 +++++++-------- Project/php/templates/myAccountView.html | 2 +- Project/php/templates/resultatsJeux.html | 2 +- Project/php/templates/usersView.html | 2 +- .../php/templates/vocabularyContainer.twig | 29 ++------------- 9 files changed, 53 insertions(+), 64 deletions(-) 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' %}

Add words

- {% if user is defined %} -
+ {% if userID is defined %} + - {% for i in 0..1 %} + {% for i in 0..20 %} diff --git a/Project/php/templates/home.html b/Project/php/templates/home.html index 40dd435..0562ede 100755 --- a/Project/php/templates/home.html +++ b/Project/php/templates/home.html @@ -21,7 +21,7 @@ - {% include 'navbar.twig' %} + {% include 'navBar.twig' %}
diff --git a/Project/php/templates/manageGroupView.html b/Project/php/templates/manageGroupView.html index a5e35eb..07e1fe5 100755 --- a/Project/php/templates/manageGroupView.html +++ b/Project/php/templates/manageGroupView.html @@ -24,7 +24,7 @@ } -{% include 'navbar.twig' %} +{% include 'navBar.twig' %}

Group list

diff --git a/Project/php/templates/manageVocabListView.html b/Project/php/templates/manageVocabListView.html index 474b395..c46d76c 100755 --- a/Project/php/templates/manageVocabListView.html +++ b/Project/php/templates/manageVocabListView.html @@ -25,26 +25,26 @@ } -
+{% include 'navBar.twig' %} +
-

Vocab list

- {% include 'vocabularyContainer.twig' with {'actions' : 'affAllVocab', 'vocabularies' : vocabularies , 'userId' : userId } %} +

My lists

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

Vocab of the user

- {% include 'vocabularyContainer.twig' with {'vocabularies' : vocabularies , 'actions' : 'getByName', 'selectedName' : 'selectedName', 'userId' : userId } %} +
+

Content

+ {% if content is defined %} + {% endif %} + //for ou ça affiche chaque traduction french - english [remove]
- -
-

Add Vocabb

- {% include 'vocabularyContainer.twig' with { 'vocabularies' : vocabularies ,'actions' : 'addVocabList' , 'userId' : userId } %} +
+

Groups

+ //la liste des groupes [ajouter] ou [retirer]
- -
-

Unassigned vocab

- {% include 'vocabularyContainer.twig' with {'vocabularies' : vocabularies , 'actions' : 'delById', 'userId' : userId } %}
+ + +
diff --git a/Project/php/templates/myAccountView.html b/Project/php/templates/myAccountView.html index b12bd2f..afa293a 100755 --- a/Project/php/templates/myAccountView.html +++ b/Project/php/templates/myAccountView.html @@ -24,7 +24,7 @@ } -{% include 'navbar.twig' %} +{% include 'navBar.twig' %}

My account

diff --git a/Project/php/templates/resultatsJeux.html b/Project/php/templates/resultatsJeux.html index d77d353..58f958e 100755 --- a/Project/php/templates/resultatsJeux.html +++ b/Project/php/templates/resultatsJeux.html @@ -43,7 +43,7 @@ -{% include 'navbar.twig' %} +{% include 'navBar.twig' %}
diff --git a/Project/php/templates/usersView.html b/Project/php/templates/usersView.html index 7d0d15f..a6c96d4 100755 --- a/Project/php/templates/usersView.html +++ b/Project/php/templates/usersView.html @@ -8,7 +8,7 @@ - {% include 'navbar.twig' %} + {% include 'navBar.twig' %} {% if users is defined %}
diff --git a/Project/php/templates/vocabularyContainer.twig b/Project/php/templates/vocabularyContainer.twig index 571e118..54da6ac 100755 --- a/Project/php/templates/vocabularyContainer.twig +++ b/Project/php/templates/vocabularyContainer.twig @@ -14,40 +14,19 @@
- {% if actions is defined %} + {% if actions is defined%}
-
{{ row.image }} {{ row.author }} - {% if actions == 'affAllVocab' %} - - - - {% elseif actions == 'getByName' %} + {% if 'getByName' in actions %} - {% elseif actions == 'delById' %} + {% endif %} + {% if 'delById' in actions %} {% endif %} {% endif %} {% endfor %} -
- - {% if actions == 'addVocabList' %} - - -

- - -

- - -

- - - - - - {% endif %}