From cb9097e0199cf6afca3f144edb7d7addaec1cb59 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Thu, 22 Jul 2021 21:04:02 +0200 Subject: Add pagination for search results Add pagination for search results in the admin and default theme. --- core/include/search/main.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'core/include/search/main.php') diff --git a/core/include/search/main.php b/core/include/search/main.php index 564f0dd..14c2ac9 100644 --- a/core/include/search/main.php +++ b/core/include/search/main.php @@ -10,6 +10,16 @@ $Language = Application::getLanguage(); $PostRepository = Application::getRepository('Post'); $UserRepository = Application::getRepository('User'); +#=============================================================================== +# Pagination +#=============================================================================== +$site_size = Application::get('POST.LIST_SIZE'); +$site_sort = Application::get('POST.LIST_SORT'); + +$currentSite = HTTP::GET('site') ?? 1; +$currentSite = intval($currentSite); +$offset = ($currentSite-1) * $site_size; + if($search = HTTP::GET('q')) { $filter = [ 'day' => HTTP::GET('d'), @@ -17,7 +27,7 @@ if($search = HTTP::GET('q')) { 'year' => HTTP::GET('y') ]; - if(!$posts = $PostRepository->search($search, $filter)) { + if(!$posts = $PostRepository->search($search, $filter, $site_size, $offset)) { $message = $Language->text('search_no_results', escapeHTML($search)); } } @@ -49,6 +59,9 @@ if(!empty($posts)) { $templates[] = generatePostItemTemplate($Post, $User); } + $count = $PostRepository->getLastSearchOverallCount(); + $last = ceil($count / $site_size); + $ResultTemplate = Template\Factory::build('search/result'); $ResultTemplate->set('FORM', $form_data); $ResultTemplate->set('SEARCH', $search_data); @@ -56,6 +69,14 @@ if(!empty($posts)) { 'LIST' => $templates ?? [] ]); + $ResultTemplate->set('PAGINATION', [ + 'THIS' => $currentSite, + 'LAST' => $last, + 'HTML' => createPaginationTemplate( + $currentSite, $last, Application::getURL('search/') + ) + ]); + $MainTemplate = Template\Factory::build('main'); $MainTemplate->set('HTML', $ResultTemplate); $MainTemplate->set('HEAD', [ -- cgit v1.2.3