diff --git a/Project/php/controller/TeacherController.php b/Project/php/controller/TeacherController.php index dac863e..82a2197 100755 --- a/Project/php/controller/TeacherController.php +++ b/Project/php/controller/TeacherController.php @@ -20,22 +20,47 @@ class TeacherController extends UserController } public function DelById():void{ - global $twig; global $user; $mdl = new MdlTeacher(); - $id = $user->getId(); - $vocab = $mdl->removeVocById($id); - echo $twig->render('manageVocabListView.html', [ 'vocabularies' => $vocab, 'userID' => $user->getId(), 'userRole' => $user->getRoles() ]); + $id = Validation::filter_int($_GET['vocabID'] ?? null); + $mdl->removeVocById($id); + $this->affAllVocab(); } public function getContent(){ global $twig; global $user; $mdl = new MdlTeacher(); - $name = Validation::filter_str_simple($_GET['vocabID'] ?? null); + $vocabularies = $mdl->getAll(); + $groups = $mdl->getAllGroups(); + $name = Validation::filter_int($_GET['vocabID'] ?? null); $content= $mdl->findByIdVoc($name); - echo $twig->render('manageVocabListView.html', ['content' => $content, 'userID' => $user->getId(), 'userRole' => $user->getRoles() ]); + echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocabularies, 'groups' => $groups, 'userID' => $user->getId(), 'userRole' => $user->getRoles(), 'content' => $content, 'vocabID' => $name]); + + } + + public function addVocabToGroup():void { + global $twig; + global $user; + $vocabID = Validation::filter_int($_GET['vocabID'] ?? null); + $groupID = Validation::filter_int($_GET['selectedGroup'] ?? null); + $mdl = new MdlTeacher(); + $mdl->addVocabToGroup($vocabID, $groupID); + $this->getContent(); } + + public function removeVocabFromGroup():void { + global $twig; + global $user; + $vocabID = Validation::filter_int($_GET['vocabID'] ?? null); + $groupID = Validation::filter_int($_GET['selectedGroup'] ?? null); + $mdl = new MdlTeacher(); + + $mdl->removeVocabFromGroup($vocabID, $groupID); + $this->getContent(); + } + + public function showVocabListForm(): void { global $twig; global $user; diff --git a/Project/php/gateway/GroupGateway.php b/Project/php/gateway/GroupGateway.php index a8a89ba..80d0d72 100755 --- a/Project/php/gateway/GroupGateway.php +++ b/Project/php/gateway/GroupGateway.php @@ -99,7 +99,7 @@ class GroupGateway extends AbsGateway } } - public function ModifGroupById(int $id, int $num, int $year ,String $sector):void{ + public function modifGroupById(int $id, int $num, int $year ,String $sector):void{ try{ $query = "UPDATE Group_ SET num=:num, year=:year, sector=:sector WHERE id=:id"; $args = array(':id'=>array($id,PDO::PARAM_INT), @@ -112,4 +112,28 @@ class GroupGateway extends AbsGateway throw new Exception($e->getMessage()); } } + + public function addVocabToGroup(int $vocab, int $group) { + try { + $query = "INSERT INTO Practice VALUES (:vocabID, :groupID)"; + $args = array(':vocabID'=>array($vocab,PDO::PARAM_INT), + ':groupID'=>array($group,PDO::PARAM_INT)); + $this->con->ExecuteQuery($query,$args); + } + catch (PDOException $e){ + throw new Exception($e->getMessage()); + } + } + + public function removeVocabFromGroup(int $vocab, int $group) { + try { + $query = "DELETE FROM Practice WHERE vocabID=:vocabID and groupID=:groupID;"; + $args = array(':vocabID'=>array($vocab,PDO::PARAM_INT), + ':groupID'=>array($group,PDO::PARAM_INT)); + $this->con->ExecuteQuery($query,$args); + } + 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 992b86a..fddc44d 100755 --- a/Project/php/model/MdlTeacher.php +++ b/Project/php/model/MdlTeacher.php @@ -36,6 +36,16 @@ class MdlTeacher extends MdlUser } + public function removeVocabFromGroup(int $vocabID, int $groupID){ + $mdl = new GroupGateway(); + $mdl->removeVocabFromGroup($vocabID, $groupID); + } + + public function addVocabToGroup(int $vocabID, int $groupID){ + $mdl = new GroupGateway(); + $mdl->addVocabToGroup($vocabID, $groupID); + } + public function RemoveVocById(int $id):void{ $gtw = new VocabularyListGateway(); $res = $gtw->remove($id); @@ -46,7 +56,6 @@ class MdlTeacher extends MdlUser $vocabID = $vocabGtw->add(array($name, $image, $userID)); $transGtw = new TranslationGateway(); foreach ($words as $word) { - var_dump($word[0]." ".$word[1]); $transGtw->add(array($word[0], $word[1], $vocabID)); } } diff --git a/Project/php/templates/groupContainer.twig b/Project/php/templates/groupContainer.twig index 45cb379..606c6dc 100755 --- a/Project/php/templates/groupContainer.twig +++ b/Project/php/templates/groupContainer.twig @@ -37,7 +37,7 @@ {% if 'removeVocabFromGroup' in actions %} - + @@ -45,7 +45,7 @@ {% if 'addVocabToGroup' in actions %} - + diff --git a/Project/php/templates/manageVocabListView.html b/Project/php/templates/manageVocabListView.html index 2092693..0a66216 100755 --- a/Project/php/templates/manageVocabListView.html +++ b/Project/php/templates/manageVocabListView.html @@ -41,8 +41,8 @@ {% for trad in content %} - trad.word1 - trad.word2 + {{trad.word1}} + {{trad.word2}} {% endfor %} @@ -50,7 +50,7 @@

Groups

- {% if groups is defined %} + {% if groups is defined and vocabID is defined %} {% include 'groupContainer.twig' with {'actions' : ['addVocabToGroup', 'removeVocabFromGroup'] } %} {% endif %}
diff --git a/Project/php/templates/vocabularyContainer.twig b/Project/php/templates/vocabularyContainer.twig index 32ac29a..6d2c5b4 100755 --- a/Project/php/templates/vocabularyContainer.twig +++ b/Project/php/templates/vocabularyContainer.twig @@ -8,7 +8,11 @@ {% if vocabularies is defined %} {% for row in vocabularies %} - + {% if vocabID is defined and vocabID == row.id %} + + {% else %} + + {% endif %} {{ row.id }} {{ row.name }} {{ row.image }} @@ -19,7 +23,6 @@ {% if 'getContent' in actions %} - {% endif %}