ajout validation dans admin controller

php
Anthony RICHARD 2 years ago
parent 38da4e87f1
commit 09b7c93821

@ -2,6 +2,7 @@
namespace controller; namespace controller;
use config\Validation;
use model\MdlAdmin; use model\MdlAdmin;
use Exception; use Exception;
@ -12,7 +13,7 @@ class AdminController
global $twig; global $twig;
try { try {
$action = $_REQUEST['action'] ?? null; $action = Validation::val_action($_REQUEST['action']);
switch($action) { switch($action) {
case 'showAllUsers': case 'showAllUsers':
@ -76,102 +77,120 @@ class AdminController
exit(0); exit(0);
} }
/*public function Reinit()
{
global $twig;
$dVue = [
'nom' => '',
'age' => 0,
];
echo $twig->render('vuephp1.html', [
'dVue' => $dVue
]);
}*/
public function showAllUsers(): void { public function showAllUsers(): void {
global $twig; global $twig;
$model = new MdlAdmin(); $model = new MdlAdmin();
$users = $model->showAllUsers(); $users = $model->getAllUsers();
echo $twig->render('usersView.html', ['users' => $users]); echo $twig->render('usersView.html', ['users' => $users]);
} }
public function showAllAdmins(): void { public function showAllAdmins(): void {
global $twig; global $twig;
$model = new MdlAdmin(); $model = new MdlAdmin();
$users = $model->showAllAdmins(); $users = $model->getAllAdmins();
echo $twig->render('usersView.html', ['users' => $users]); echo $twig->render('usersView.html', ['users' => $users]);
} }
public function showAllTeachers(): void { public function showAllTeachers(): void {
global $twig; global $twig;
$model = new MdlAdmin(); $model = new MdlAdmin();
$users = $model->showAllTeachers(); $users = $model->getAllTeachers();
echo $twig->render('usersView.html', ['users' => $users]); echo $twig->render('usersView.html', ['users' => $users]);
} }
public function showAllStudents(): void { public function showAllStudents(): void {
global $twig; global $twig;
$model = new MdlAdmin(); $model = new MdlAdmin();
$users = $model->showAllStudents(); $users = $model->getAllStudents();
echo $twig->render('usersView.html', ['users' => $users]); echo $twig->render('usersView.html', ['users' => $users]);
} }
public function removeUser(): void { public function removeUser(): void {
$id = $_GET['id']; try {
$id = Validation::filter_int($_GET['id']);
$model = new MdlAdmin(); $model = new MdlAdmin();
$model->removeUser($id); $model->removeUser($id);
$this->showAllUsers(); $this->showAllUsers();
} }
catch (Exception $e) {
throw new Exception("invalid user ID");
}
}
public function showAllGroups(): void { public function showAllGroups(): void {
global $twig; global $twig;
$model = new MdlAdmin(); $model = new MdlAdmin();
$groups = $model->showAllGroups(); $groups = $model->getAllGroups();
$unassignedUsers = $model->getUnassignedUsers(); $unassignedUsers = $model->getUnassignedUsers();
echo $twig->render('manageGroupView.html', ['groups' => $groups, 'unassignedUsers' => $unassignedUsers]); echo $twig->render('manageGroupView.html', ['groups' => $groups, 'unassignedUsers' => $unassignedUsers]);
} }
public function showGroupDetails(): void { public function showGroupDetails(): void {
try {
global $twig; global $twig;
$selectedGroup = Validation::filter_int($_GET['selectedGroup'] ?? null);
$model = new MdlAdmin(); $model = new MdlAdmin();
$id = $_GET['selectedGroup']; $groups = $model->getAllGroups();
$groups = $model->showAllGroups(); $users = $model->getUsersOfGroup($selectedGroup);
$users = $model->getUsersOfGroup($id);
$unassignedUsers = $model->getUnassignedUsers(); $unassignedUsers = $model->getUnassignedUsers();
echo $twig->render('manageGroupView.html', ['groups' => $groups, 'selectedGroup' => $id, 'users' => $users, 'unassignedUsers' => $unassignedUsers]); echo $twig->render('manageGroupView.html', ['groups' => $groups, 'selectedGroup' => $selectedGroup, 'users' => $users, 'unassignedUsers' => $unassignedUsers]);
}
catch (Exception $e) {
throw new Exception("invalid group ID");
}
} }
public function removeUserFromGroup(): void { public function removeUserFromGroup(): void {
try {
$id = Validation::filter_int($_GET['id']);
$model = new MdlAdmin(); $model = new MdlAdmin();
$id = $_GET['id'];
$model->removeUserFromGroup($id); $model->removeUserFromGroup($id);
$this->showGroupDetails(); $this->showGroupDetails();
} }
catch (Exception $e) {
throw new Exception("invalid group ID");
}
}
public function removeGroup(): void { public function removeGroup(): void {
try {
$selectedGroup = Validation::filter_int($_GET['selectedGroup']);
$model = new MdlAdmin(); $model = new MdlAdmin();
$id = $_GET['selectedGroup']; $model->removeGroup($selectedGroup);
$model->removeGroup($id);
$this->showAllGroups(); $this->showAllGroups();
} }
catch (Exception $e) {
throw new Exception("invalid group ID");
}
}
public function addGroup(): void { public function addGroup(): void {
try {
$num = Validation::filter_int($_GET['num']);
$year = Validation::filter_int($_GET['year']);
$sector = Validation::filter_str_simple($_GET['sector']);
$model = new MdlAdmin(); $model = new MdlAdmin();
$num = $_GET['num'];
$year = $_GET['year'];
$sector = $_GET['sector'];
$groupID = $model->addGroup($num, $year, $sector); $groupID = $model->addGroup($num, $year, $sector);
$_GET['selectedGroup'] = $groupID; $_GET['selectedGroup'] = $groupID;
$this->showGroupDetails(); $this->showGroupDetails();
} }
catch (Exception $e) {
throw new Exception("invalid form");
}
}
public function addUserToGroup(): void { public function addUserToGroup(): void {
try {
$user = Validation::filter_int($_GET['userID']);
$group = Validation::filter_int($_GET['groupID']);
$model = new MdlAdmin(); $model = new MdlAdmin();
$user = $_GET['userID'];
$group = $_GET['groupID'];
$model->addUserToGroup($user, $group); $model->addUserToGroup($user, $group);
$_GET['selectedGroup'] = $group; $_GET['selectedGroup'] = $group;
$this->showGroupDetails(); $this->showGroupDetails();
} }
catch (Exception $e) {
throw new Exception("invalid IDs");
}
}
} }

Loading…
Cancel
Save