You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.7 KiB
83 lines
2.7 KiB
<?php
|
|
|
|
namespace controller;
|
|
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, 'userID' => $user->getId(), 'userRole' => $user->getRoles()]);
|
|
|
|
}
|
|
|
|
public function affAllVocab(): void
|
|
{
|
|
global $twig;
|
|
global $user;
|
|
$id = $user->getId();
|
|
$mdl = new MdlTeacher();
|
|
$vocabularies = $mdl->getAll();
|
|
echo $twig->render('manageVocabListView.html', ['vocabularies' => $vocabularies, 'userID' => $user->getId(), 'userRole' => $user->getRoles()]);
|
|
}
|
|
|
|
public function getByName(): void
|
|
{
|
|
global $twig;
|
|
global $user;
|
|
$mdl = new MdlTeacher();
|
|
$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' => $user->getId(), 'userRole' => $user->getRoles() ]);
|
|
|
|
}
|
|
|
|
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() ]);
|
|
}
|
|
|
|
public function showVocabListForm(): void {
|
|
global $twig;
|
|
global $user;
|
|
echo $twig->render('addVocabList.html', ['userID' => $user->getId(), 'userRole' => $user->getRoles() ]);
|
|
}
|
|
|
|
public function addVocabList():void {
|
|
global $twig;
|
|
global $user;
|
|
$mdl = new MdlTeacher();
|
|
$name = Validation::filter_str_simple($_POST['listName'] ?? null);
|
|
$words = array();
|
|
|
|
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);
|
|
}
|
|
|
|
if (count($words) % 2 == 1) throw new Exception("il manque un mot");
|
|
else {
|
|
$addvoc= $mdl->addVocabList($user->getId(), $name, "", $words);
|
|
$this->affAllVocab();
|
|
}
|
|
}
|
|
|
|
} |