diff --git a/library/Class/Notice.php b/library/Class/Notice.php index d15fe036118ff035010137ad69618ffda300d2ad..fd23c1405975adc5a7706d5c2213e85d443a9139 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -39,45 +39,35 @@ class NoticeLoader extends Storm_Model_Loader { return $notices; } - - - public function findAllByRequeteRecherche($req, $nb_par_page,$page_no=1 ) { - if (!$page_no) $page_no=1; - $ret = array(); - - $fin_limit = 0; - if(strpos($req," LIMIT ") === false) { - $limit = ($page_no-1) * $nb_par_page; - $limit = " LIMIT ".$limit.",". $nb_par_page; - $req.=$limit; - } - else { - $debut_limit = ($page_no-1) * $nb_par_page; - $fin_limit = $nb_par_page; - } - - // Execute la requete - if (!$rows=fetchAll($req)) - $rows = []; - - if ($fin_limit) - $rows=array_slice($rows, $debut_limit, $fin_limit); - - if (!$rows) - return []; + public function getNoticeIdsByRequeteRecherche($req) { + $rows = fetchAll($req); $ids = []; foreach($rows as $row) { $ids []= $row['id_notice']; } - if (!$ids = array_filter($ids)) + return $ids; + } + + + public function findAllByRequeteRecherche($req, $nb_par_page, $page_no=1 ) { + if (!$page_no) $page_no=1; + + $ids = $this->getNoticeIdsByRequeteRecherche($req); + + if ($nb_par_page) + $ids = array_slice($ids, + ($page_no-1) * $nb_par_page, + $nb_par_page); + + if (empty($ids)) return []; return Class_Notice::getLoader()->findAllBy(['id_notice' => $ids, 'order' => 'FIELD(id_notice, '.implode(',', $ids).')']); - } + } public function getNoticeByOAIIdentifier($identifier) {