public function technotes($action, $id, $vars) { $technoteDAO = new TechnoteDAO(BDD::getInstancePDO()); switch ($action) { /**** GET ****/ case 'get': $vars['active_technotes'] = 1; // Active le style dans le menu technotes // Si on veut voir une technote précise if (!empty($id)) { // On récupère la technote $vars['technote'] = $technoteDAO->getOne($id); // Si la technote existe if ($vars['technote'] !== false && $vars['technote']->visible && ($vars['technote']->publie || $vars['technote']->id_auteur == $_SESSION['user']->id_membre || $_SESSION['user']->groupe == 'Administrateur' || $_SESSION['user']->groupe == 'Modérateur')) { $vars['titrePage'] = $vars['technote']->titre; // <h1> de la page $this->vue->display('technotes_get_one.twig', $vars); } else { $this->vue->display('404.twig', $vars); } } else { // On récupère la page $page = !empty($_GET['page']) ? $_GET['page'] : 1; $technoteDAO = new TechnoteDAO(BDD::getInstancePDO()); // Si on veut faire une recherche de technotes if (isset($_GET['recherche'])) { $vars['titrePage'] = 'Chercher une technote'; // <h1> de la page // on recupère la page $page = !empty($_GET['page']) ? $_GET['page'] : 1; // On essaye de récupèrer les technotes avec les critères de recherche $res = Technote::recherche($_GET, $page); if ($res->success) { $vars['pagination'] = $res->pagination; $vars['technotes'] = $res->technotes; } else { $vars['res'] = $res; } } elseif (isset($_GET['nonpublie'])) { $vars['titrePage'] = 'Mes technotes non publié'; // <h1> de la page $vars['active_technotes_non_publie'] = 1; // Active le style dans le sous menu toutes les technotes // On récupère le nombre total de technotes non publié par l' $count = $technoteDAO->getNbRedige($_SESSION['user']->id_membre, 0); // On créé la pagination $vars['pagination'] = new Pagination($page, $count, NB_TECHNOTES_PAGE, '/technotes/get?nonpublie&page='); // On récupère les technotes $vars['technotes'] = $technoteDAO->getLastNTechnotes(NB_TECHNOTES_PAGE, $vars['pagination']->debut, 0, $_SESSION['user']->id_membre); $vars['getNonPublie'] = true; } else { $vars['titrePage'] = 'Toutes les technotes'; // <h1> de la page $vars['active_technotes_all'] = 1; // Active le style dans le sous menu toutes les technotes // On récupère le nombre total de technotes $count = $technoteDAO->getCount(); // On créé la pagination $vars['pagination'] = new Pagination($page, $count, NB_TECHNOTES_PAGE, '/technotes/get?page='); // On récupère les technotes $vars['technotes'] = $technoteDAO->getLastNTechnotes(NB_TECHNOTES_PAGE, $vars['pagination']->debut); } $this->vue->display('technotes_get_all.twig', $vars); } exit; /**** ADD ****/ /**** ADD ****/ case 'add': $vars['active_technotes'] = 1; // Active le style dans le menu technotes $vars['active_technotes_add'] = 1; // Active le style dans le sous menu ajout de technote $vars['titrePage'] = 'Ajouter une technote'; // <h1> de la page // On récupère tous les mots clés $motCleDAO = new MotCleDAO(BDD::getInstancePDO()); $vars['motsCles'] = $motCleDAO->getAllActif(); // Si un formulaire a été envoyé if (!empty($_POST)) { // Si le formulaire est valide au niveau faille CSRF if (!empty($_POST['jetonCSRF']) && $_POST['jetonCSRF'] == $_SESSION['jetonCSRF']) { // On essaye d'enregistrer la technote $res = Technote::addTechnote($_POST, $_FILES); if ($res->success) { $res->redirect = "/technotes/get/{$res->id_technote}"; } echo json_encode($res); exit; } } $this->vue->display('technotes_add.twig', $vars); exit; /**** EDIT ****/ /**** EDIT ****/ case 'edit': $vars['active_technotes'] = 1; // Active le style dans le menu technotes $vars['titrePage'] = 'Modifier une technote'; // <h1> de la page $vars['technote'] = $technoteDAO->getOne($id); // On récupère tous les mots clés $motCleDAO = new MotCleDAO(BDD::getInstancePDO()); $vars['motsCles'] = $motCleDAO->getAllActif(); // Si un formulaire a été envoyé if (!empty($_POST)) { // Si le formulaire est valide au niveau faille CSRF if (!empty($_POST['jetonCSRF']) && $_POST['jetonCSRF'] == $_SESSION['jetonCSRF']) { // On essaye d'enregistrer la technote $res = Technote::editTechnote($_POST, $_FILES, $id); if ($res->success) { $res->redirect = "/technotes/get/{$id}"; } echo json_encode($res); exit; } } $this->vue->display('technotes_edit.twig', $vars); exit; /**** DROP ****/ /**** DROP ****/ case 'drop': if (!empty($_POST)) { // Si le formulaire est valide au niveau faille CSRF if (!empty($_POST['jetonCSRF']) && $_POST['jetonCSRF'] == $_SESSION['jetonCSRF']) { // On essaye d'enregistrer le commentaire $res = Technote::dropTechnote($id); if ($res->success) { $res->redirect = "/technotes"; } echo json_encode($res); } } exit; default: $this->vue->display('404.twig', $vars); exit; } }
private static function checkAdd(&$param) { $std = (object) array('success' => false, 'msg' => array()); $technoteDAO = new TechnoteDAO(BDD::getInstancePDO()); if (($res = $technoteDAO->getOne($param['id_technote'])) !== false) { if (($res = self::checkCommentaire($param['commentaire'])) !== true) { $std->msg[] = $res; } if (($res = self::checkCommentaireParent($param['id_commentaire_parent'], $param['id_technote'])) !== true) { $std->msg[] = $res; } } else { $std->msg[] = 'La technote n\'existe pas'; } if (empty($std->msg)) { $std->success = true; } return $std; }