Exemple #1
0
 public static function recherche(&$param, $page)
 {
     $std = (object) array('success' => false, 'msg' => array());
     $cond = array();
     $strPagination = '';
     // On construit l'URL pour la pagination, et on construit un tableau pour la requête SQL
     if (!empty($param['titre'])) {
         $cond['titre'] = $param['titre'];
         $strPagination .= '&titre=' . urlencode($param['titre']);
     }
     if (!empty($param['date_debut'])) {
         if (($res = Date::verifierDate($param['date_debut'])) !== true) {
             $std->msg[] = $res . ' (date de début)';
         } else {
             $cond['date_debut'] = $param['date_debut'];
             $strPagination .= '&date_debut=' . $param['date_debut'];
         }
     }
     if (!empty($param['date_fin'])) {
         if (($res = Date::verifierDate($param['date_fin'])) !== true) {
             $std->msg[] = $res . ' (date de fin)';
         } else {
             $cond['date_fin'] = $param['date_fin'];
             $strPagination .= '&date_fin=' . $param['date_fin'];
         }
     }
     if (!empty($param['resolu'])) {
         if ($param['resolu'] != 'oui' && $param['resolu'] != 'non') {
             $std->msg[] = 'Valeur invalide pour le champ résolu';
         } else {
             $cond['resolu'] = $param['resolu'];
             $strPagination .= '&resolu=' . $param['resolu'];
         }
     }
     if (!empty($param['mots_cles'])) {
         // Construit un tableau de mots clés
         $tabMC = explode(',', $param['mots_cles']);
         $tabMCClean = array();
         foreach ($tabMC as $key => $value) {
             // On enlève les espaces de début et de fin
             $valueClean = trim($value);
             if ($valueClean != '') {
                 $tabMCClean[] = $valueClean;
                 // Si le mot clé est obligatoire, on supprime le + de début
                 if ($valueClean[0] == '+') {
                     $valueClean = substr($valueClean, 1);
                 }
                 if (($res = MotCle::checkExisteByLabel($valueClean)) !== true) {
                     $std->msg[] = $res;
                 }
             }
         }
         $cond['mots_cles'] = $tabMCClean;
     }
     // S'il y a des erreurs, on s'arrête
     if (!empty($std->msg)) {
         return $std;
     }
     $questionDAO = new QuestionDAO(BDD::getInstancePDO());
     // On récupère le nombre de questions qu'on a en résultat
     $count = $questionDAO->getQuestionsWithSearch(NB_QUESTIONS_PAGE, $cond, true);
     // On créé la pagination
     $std->pagination = new Pagination($page, $count, NB_QUESTIONS_PAGE, '/questions?recherche=' . $strPagination . '&page=');
     // On récupère les questions
     $std->questions = $questionDAO->getQuestionsWithSearch(NB_QUESTIONS_PAGE, $cond, false, $std->pagination->debut);
     if (empty($std->questions)) {
         $std->msg[] = 'Aucune question avec ces critères';
     } else {
         $std->success = true;
     }
     return $std;
 }
Exemple #2
0
 /**
  * Vérifie les attributs d'une technote
  * @param array $param Les attributs à vérifier
  * @return object 2 attributs, bool success et array string msg
  * @static
  */
 private static function checkTechnote(&$param, &$files, $typeCheck)
 {
     $std = (object) array('success' => false, 'msg' => array());
     if (($res = Technote::checkDescription($param['description'])) !== true) {
         $std->msg[] = $res;
     }
     if (($res = Technote::checkPublie($param['publie'])) !== true) {
         $std->msg[] = $res;
     }
     if (($res = Technote::checkTitre($param['titre'])) !== true) {
         $std->msg[] = $res;
     }
     if (($res = Technote::checkContenu($param['contenu'])) !== true) {
         $std->msg[] = $res;
     }
     // Si on ajoute une technote, ou que c'est une édition avec modification de l'image
     if ($typeCheck == 'add' || !empty($files['image'])) {
         if (($res = Technote::checkImage($files['image'])) !== true) {
             $std->msg[] = $res;
         }
         // On génère un nom aléatoire
         do {
             $gen = uniqid(rand());
             $nom = pathinfo($files['image']['name'], PATHINFO_FILENAME);
             $extension = pathinfo($files['image']['name'], PATHINFO_EXTENSION);
             $base = dirname(__FILE__) . '/..';
             $chemin = '/assets/images/uploads/' . $nom . $gen . '.' . $extension;
         } while (file_exists($base . $chemin));
         if (move_uploaded_file($files['image']['tmp_name'], $base . $chemin)) {
             $param['url_image'] = $chemin;
         } else {
             $std->msg[] = 'Problème de déplacement de l\'image sur le serveur, veuillez contacter un admin';
         }
     } else {
         if (($res = Technote::checkURLImage($param['url_image'])) !== true) {
             $std->msg[] = $res;
         }
     }
     if (!empty($param['id_mot_cle'])) {
         foreach ($param['id_mot_cle'] as $id_mot_cle) {
             if (($res = MotCle::checkExiste($id_mot_cle)) !== true) {
                 $std->msg[] = $res;
             }
         }
     }
     if (empty($std->msg)) {
         $std->success = true;
     }
     return $std;
 }
Exemple #3
0
 public function mots_cles($action, $id, $vars)
 {
     switch ($action) {
         case 'add':
             // Si un formulaire a été envoyé
             if (!empty($_POST)) {
                 // On essaye de se connecter
                 $res = MotCle::add($_POST);
                 echo json_encode($res);
                 exit;
             }
             $this->vue->display('403.twig', $vars);
             exit;
         default:
             $this->vue->display('404.twig', $vars);
             exit;
     }
 }
Exemple #4
0
 public function statistiques($action, $id, $vars)
 {
     switch ($action) {
         /**** GET ****/
         case 'get':
             $vars['titrePage'] = 'Statistiques';
             // <h1> de la page
             $vars['visites'] = Visite::getStat();
             $vars['membres'] = Membre::getStat();
             $vars['technotes'] = Technote::getStat();
             $vars['commentaires'] = Commentaire::getStat();
             $vars['questions'] = Question::getStat();
             $vars['reponses'] = Reponse::getStat();
             $vars['motsCles'] = MotCle::getStat();
             $this->vue->display('admin/statistiques.twig', $vars);
             exit;
         default:
             $this->vue->display('404.twig', $vars);
             exit;
     }
 }
Exemple #5
0
 public static function checkLabel(&$label)
 {
     if (!empty($label)) {
         if (MotCle::checkExisteByLabel($label) !== true) {
             if (mb_strlen($label) >= 1 && mb_strlen($label) <= 31) {
                 return true;
             }
             return 'Le label ne respecte pas les règles de longueur (1 à 31 caractères)';
         } else {
             return 'Le label est déjà utilisé';
         }
     }
     return 'Le label n\'est pas renseigné';
 }