|
|
|
@ -4,6 +4,7 @@ namespace Controller;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use PDOException;
|
|
|
|
|
use Config\DataManagement;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Permet de gérer l'appel des controllers en fonction de l'action et du rôle de l'utilisateur
|
|
|
|
@ -16,23 +17,26 @@ class FrontController
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$listControllers = array("\\Controller\\ControllerCandidate", "\\Controller\\ControllerAdmin");
|
|
|
|
|
|
|
|
|
|
global $rep, $views;
|
|
|
|
|
$dVueError = array();
|
|
|
|
|
|
|
|
|
|
$controllerPath = "\\Controller\\Controller";
|
|
|
|
|
$mapRoleAccess = array(
|
|
|
|
|
"Candidate" => array("Candidate"),
|
|
|
|
|
"Admin" => array("Candidate", "Admin"));
|
|
|
|
|
if (!isset($_SESSION["role"]))
|
|
|
|
|
$currentRole = "Candidate";
|
|
|
|
|
else $currentRole = Clean::simpleString($_SESSION["role"]);
|
|
|
|
|
try {
|
|
|
|
|
$action = $_REQUEST['action'] ? $action = $_REQUEST['action'] : (new ControllerCandidate())->goToForm();
|
|
|
|
|
foreach ($listControllers as $controller) {
|
|
|
|
|
if (method_exists($controller, $action)) {
|
|
|
|
|
(new $controller)->$action(); // Si oui, on appelle cette fonction
|
|
|
|
|
$action = isset($_REQUEST['action']) ? Clean::simpleString($_REQUEST['action']) : (new ControllerCandidate())->goToForm();
|
|
|
|
|
foreach ($mapRoleAccess[$currentRole] as $role) {
|
|
|
|
|
if (method_exists($controllerPath . $role, $action)) {
|
|
|
|
|
(new $controllerPath . $role)->$action(); // Si oui, on appelle cette fonction
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (PDOException|Exception $e) {
|
|
|
|
|
$dVueError[] = "Erreur innatendue !"; // Ecriture du message d'erreur
|
|
|
|
|
echo "ERREUUUUUR";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|