vocabListView

php
Anthony RICHARD 1 year ago
parent 36e559ff8e
commit ff80500986

@ -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;

@ -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());
}
}
}

@ -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));
}
}

@ -37,7 +37,7 @@
{% if 'removeVocabFromGroup' in actions %}
<td>
<a href="{{base}}/teacher/{{userID}}/removeVocabFromGroup&vocabID={{ vocabID }}&selectedGroup={{ row.id }}">
<a href="{{base}}/teacher/{{userID}}/removeVocabFromGroup?vocabID={{ vocabID }}&selectedGroup={{ row.id }}">
<input class="btn-black" type="button" value="Remove from group"/>
</a>
</td>
@ -45,7 +45,7 @@
{% if 'addVocabToGroup' in actions %}
<td>
<a href="{{base}}/admin/{{userID}}/addVocabToGroup?vocabID={{ vocabID }}&selectedGroup={{ row.id }}">
<a href="{{base}}/teacher/{{userID}}/addVocabToGroup?vocabID={{ vocabID }}&selectedGroup={{ row.id }}">
<input class="btn-black" type="button" value="Add to group"/>
</a>
</td>

@ -41,8 +41,8 @@
</tr>
{% for trad in content %}
<tr>
<td>trad.word1</td>
<td>trad.word2</td>
<td>{{trad.word1}}</td>
<td>{{trad.word2}}</td>
</tr>
{% endfor %}
</table>
@ -50,7 +50,7 @@
</section>
<section>
<h2>Groups</h2>
{% if groups is defined %}
{% if groups is defined and vocabID is defined %}
{% include 'groupContainer.twig' with {'actions' : ['addVocabToGroup', 'removeVocabFromGroup'] } %}
{% endif %}
</section>

@ -8,7 +8,11 @@
{% if vocabularies is defined %}
{% for row in vocabularies %}
<tr>
{% if vocabID is defined and vocabID == row.id %}
<tr style="background-color:red;">
{% else %}
<tr>
{% endif %}
<td>{{ row.id }}</td>
<td>{{ row.name }}</td>
<td>{{ row.image }}</td>
@ -19,7 +23,6 @@
{% if 'getContent' in actions %}
<a href="{{base}}/teacher/{{userID}}/getContent?vocabID={{row.id}}">
<input class="btn-black" type="button" value="aff content" />
</a>
{% endif %}

Loading…
Cancel
Save