|
|
|
@ -4,37 +4,68 @@ namespace Controller;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
use PDOException;
|
|
|
|
|
use Config\DataManagement;
|
|
|
|
|
use Config\Validate;
|
|
|
|
|
use Config\Clean;
|
|
|
|
|
use Config\AltoRouter;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Permet de gérer l'appel des controllers en fonction de l'action et du rôle de l'utilisateur
|
|
|
|
|
*/
|
|
|
|
|
class FrontController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Définit le comportement de la classe à sa création, on appelle le bon controller en fonction de l'action
|
|
|
|
|
* et du rôle de la personne qui souhaite réaliser cette action (utilisateur, administrateur...).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$listControllers = array("\\Controller\\ControllerCandidate", "\\Controller\\ControllerAdmin");
|
|
|
|
|
|
|
|
|
|
global $rep, $views;
|
|
|
|
|
$dVueError = array();
|
|
|
|
|
class FrontController {
|
|
|
|
|
private $router;
|
|
|
|
|
private $rights;
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
$this->router = new AltoRouter();
|
|
|
|
|
$this->router->setBasePath($_SERVER['BASE_URI']);
|
|
|
|
|
$this->mapRoutes();
|
|
|
|
|
$this->rights = array (
|
|
|
|
|
'Candidate' => array('ControllerCandidate'),
|
|
|
|
|
'Admin' => array('ControllerCandidate','ControllerAdmin')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
public function run() {
|
|
|
|
|
global $error,$rep,$views;
|
|
|
|
|
$exists=false;
|
|
|
|
|
$match = $this->router->match();
|
|
|
|
|
if ($match) {
|
|
|
|
|
$target = $match['target'];
|
|
|
|
|
$params = $match['params'];
|
|
|
|
|
if(!isset($_SESSION['role'])) {
|
|
|
|
|
$_SESSION['role'] = 'Candidate';
|
|
|
|
|
}
|
|
|
|
|
$role = Clean::simpleString($_SESSION['role']);
|
|
|
|
|
foreach($this->rights[$role] as $controllerName) {
|
|
|
|
|
if(strcmp($controllerName,$target[0])===0) {
|
|
|
|
|
$controllerClass = '\Controller\\' . $target[0];
|
|
|
|
|
$controller = new $controllerClass();
|
|
|
|
|
$controller->{$target[1]}($params);
|
|
|
|
|
$exists=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (PDOException|Exception $e) {
|
|
|
|
|
$dVueError[] = "Erreur innatendue !"; // Ecriture du message d'erreur
|
|
|
|
|
echo "ERREUUUUUR";
|
|
|
|
|
if(!$exists) {
|
|
|
|
|
$error = $error['403'];
|
|
|
|
|
require_once($rep . $views['error']);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// no route was matched
|
|
|
|
|
$error = $error['404'];
|
|
|
|
|
require_once($rep . $views['error']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
private function mapRoutes() {
|
|
|
|
|
global $controller;
|
|
|
|
|
$this->router->map('GET', '/', array($controller['Candidate'], 'goToForm'), 'goToForm');
|
|
|
|
|
$this->router->map('POST', '/submitForm', array($controller['Candidate'], 'submitForm'), 'submitForm');
|
|
|
|
|
$this->router->map('POST', '/addQuestion', array($controller['Admin'], 'addQuestion'), 'addQuestion');
|
|
|
|
|
$this->router->map('POST', '/addResponse', array($controller['Admin'], 'addResponse'), 'addResponse');
|
|
|
|
|
$this->router->map('POST','/continueResponse',array($controller['Admin'],'continueResponse'),'continueResponse');
|
|
|
|
|
$this->router->map('POST','/createForm',array($controller['Admin'],'createForm'),'createForm');
|
|
|
|
|
$this->router->map('POST','/addKeyword',array($controller['Admin'],'addKeyword'),'addKeyword');
|
|
|
|
|
$this->router->map('GET','/goToAdmin',array($controller['Admin'],'goToAdmin'),'goToAdmin');
|
|
|
|
|
$this->router->map('GET','/goToAdminLogin',array($controller['Candidate'],'goToAdminLogin'),'goToLogin');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|