diff --git a/Project/php/controller/TeacherController.php b/Project/php/controller/TeacherController.php
index f4f88b7..d571fb8 100755
--- a/Project/php/controller/TeacherController.php
+++ b/Project/php/controller/TeacherController.php
@@ -39,11 +39,11 @@ class TeacherController extends UserController
global $user;
$mdl = new MdlTeacher();
$vocabularies = $mdl->getAll();
- $groups = $mdl->getAllGroups();
$name = Validation::filter_int($_GET['vocabID'] ?? null);
+ $groupsVocab = $mdl->findGroupVocab($name);
+ $groupsNoVocab = $mdl->findGroupNoVocab($name);
$content= $mdl->findByIdVoc($name);
- echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocabularies, 'groups' => $groups, 'userID' => $user->getId(), 'userRole' => $user->getRoles(), 'content' => $content, 'vocabID' => $name]);
-
+ echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocabularies, 'groupsVocab' => $groupsVocab, 'groupsNoVocab' => $groupsNoVocab, 'userID' => $user->getId(), 'userRole' => $user->getRoles(), 'content' => $content, 'vocabID' => $name]);
}
public function addVocabToGroup():void {
diff --git a/Project/php/gateway/GroupGateway.php b/Project/php/gateway/GroupGateway.php
index 80d0d72..86d72d4 100755
--- a/Project/php/gateway/GroupGateway.php
+++ b/Project/php/gateway/GroupGateway.php
@@ -127,7 +127,7 @@ class GroupGateway extends AbsGateway
public function removeVocabFromGroup(int $vocab, int $group) {
try {
- $query = "DELETE FROM Practice WHERE vocabID=:vocabID and groupID=:groupID;";
+ $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);
@@ -136,4 +136,28 @@ class GroupGateway extends AbsGateway
throw new Exception($e->getMessage());
}
}
+
+ public function findGroupVocab(int $vocab) : array{
+ $query = "SELECT g.* FROM Practice p, Group_ g WHERE g.id=p.groupID AND p.vocabID=:vocabID;";
+ $args = array(':vocabID'=>array($vocab,PDO::PARAM_INT));
+ $this->con->ExecuteQuery($query,$args);
+ $results = $this->con->getResults();
+ $tab = array();
+
+ foreach ($results as $row) $tab[] = new Group($row['id'],$row['num'],$row['year'],$row['sector']);
+
+ return $tab;
+ }
+
+ public function findGroupNoVocab(int $vocab) : array {
+ $query = "SELECT * FROM Group_ WHERE id NOT IN (SELECT groupID FROM Practice Where vocabID=:vocabID);";
+ $args = array(':vocabID'=>array($vocab,PDO::PARAM_INT));
+ $this->con->ExecuteQuery($query,$args);
+ $results = $this->con->getResults();
+ $tab = array();
+
+ foreach ($results as $row) $tab[] = new Group($row['id'],$row['num'],$row['year'],$row['sector']);
+
+ return $tab;
+ }
}
\ No newline at end of file
diff --git a/Project/php/model/MdlTeacher.php b/Project/php/model/MdlTeacher.php
index 62ab657..30f3a79 100755
--- a/Project/php/model/MdlTeacher.php
+++ b/Project/php/model/MdlTeacher.php
@@ -52,6 +52,16 @@ class MdlTeacher extends MdlUser
$mdl->addVocabToGroup($vocabID, $groupID);
}
+ public function findGroupVocab(int $vocab): array {
+ $mdl = new GroupGateway();
+ return $mdl->findGroupVocab($vocab);
+ }
+
+ public function findGroupNoVocab(int $vocab): array {
+ $mdl = new GroupGateway();
+ return $mdl->findGroupNoVocab($vocab);
+ }
+
public function RemoveVocById(int $id):void{
$gtw = new VocabularyListGateway();
$res = $gtw->remove($id);
diff --git a/Project/php/templates/manageVocabListView.html b/Project/php/templates/manageVocabListView.html
index d3cd868..3391a29 100755
--- a/Project/php/templates/manageVocabListView.html
+++ b/Project/php/templates/manageVocabListView.html
@@ -49,9 +49,16 @@
{% endif %}
- Groups
- {% if groups is defined and vocabID is defined %}
- {% include 'groupContainer.twig' with {'actions' : ['addVocabToGroup', 'removeVocabFromGroup'] } %}
+ Groups with vocab
+ {% if vocabID is defined %}
+ {% include 'groupContainer.twig' with {'actions' : 'removeVocabFromGroup', groups : groupsVocab } %}
+ {% endif %}
+
+
+
+ Groups without vocab
+ {% if groupsNoVocab is defined and vocabID is defined %}
+ {% include 'groupContainer.twig' with {'actions' : 'addVocabToGroup', groups : groupsNoVocab } %}
{% endif %}