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['auteur'])) { $membreDAO = new MembreDAO(BDD::getInstancePDO()); if (($res = $membreDAO->checkPseudoExiste($param['auteur'])) === false) { $std->msg[] = 'Aucun membre avec ce pseudo'; } else { $cond['auteur'] = $param['auteur']; $strPagination .= '&auteur=' . $param['auteur']; } } 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; } $technoteDAO = new TechnoteDAO(BDD::getInstancePDO()); // On récupère le nombre de technotes qu'on a en résultat $count = $technoteDAO->getTechnotesWithSearch(NB_TECHNOTES_PAGE, $cond, true); // On créé la pagination $std->pagination = new Pagination($page, $count, NB_TECHNOTES_PAGE, '/technotes?recherche=' . $strPagination . '&page='); // On récupère les technotes $std->technotes = $technoteDAO->getTechnotesWithSearch(NB_TECHNOTES_PAGE, $cond, false, $std->pagination->debut); if (empty($std->technotes)) { $std->msg[] = 'Aucune technote avec ces critères'; } else { $std->success = true; } return $std; }