aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-07-22 21:04:02 +0200
committerThomas Lange <code@nerdmind.de>2021-07-22 21:04:02 +0200
commitcb9097e0199cf6afca3f144edb7d7addaec1cb59 (patch)
treeb4aff017f6a8c22b4b32c8316f4ae3b887bcbd3a /admin
parentae38025d1d03ef3fa12c73b8ea48af3df02e2351 (diff)
downloadblog-cb9097e0199cf6afca3f144edb7d7addaec1cb59.tar.gz
blog-cb9097e0199cf6afca3f144edb7d7addaec1cb59.tar.xz
blog-cb9097e0199cf6afca3f144edb7d7addaec1cb59.zip
Add pagination for search results
Add pagination for search results in the admin and default theme.
Diffstat (limited to 'admin')
-rw-r--r--admin/page/search.php37
-rw-r--r--admin/post/search.php37
2 files changed, 66 insertions, 8 deletions
diff --git a/admin/page/search.php b/admin/page/search.php
index 8135b91..85448df 100644
--- a/admin/page/search.php
+++ b/admin/page/search.php
@@ -11,24 +11,53 @@ const AUTHENTICATION = TRUE;
require '../../core/application.php';
#===============================================================================
+# Get repositories
+#===============================================================================
+$PageRepository = Application::getRepository('Page');
+$UserRepository = Application::getRepository('User');
+
+#===============================================================================
+# Pagination
+#===============================================================================
+$site_size = Application::get('ADMIN.PAGE.LIST_SIZE');
+$site_sort = Application::get('ADMIN.PAGE.LIST_SORT');
+
+$currentSite = HTTP::GET('site') ?? 1;
+$currentSite = intval($currentSite);
+$offset = ($currentSite-1) * $site_size;
+
+#===============================================================================
# Check for search request
#===============================================================================
if($search = HTTP::GET('q')) {
- $PageRepository = Application::getRepository('Page');
- $UserRepository = Application::getRepository('User');
-
- foreach($PageRepository->search($search) as $Page) {
+ foreach($PageRepository->search($search, [], $site_size, $offset) as $Page) {
$User = $UserRepository->find($Page->get('user'));
$templates[] = generatePageItemTemplate($Page, $User);
}
}
#===============================================================================
+# Create pagination only if there are results
+#===============================================================================
+if($count = $PageRepository->getLastSearchOverallCount()) {
+ $last = ceil($count / $site_size);
+
+ $pagination_data = [
+ 'THIS' => $currentSite,
+ 'LAST' => $last,
+ 'HTML' => createPaginationTemplate(
+ $currentSite, $last, Application::getAdminURL('page/search.php')
+ )
+ ];
+}
+
+#===============================================================================
# Build document
#===============================================================================
$SearchTemplate = Template\Factory::build('page/search');
$SearchTemplate->set('QUERY', $search);
$SearchTemplate->set('PAGES', $templates ?? []);
+$SearchTemplate->set('PAGINATION', $pagination_data ?? []);
$MainTemplate = Template\Factory::build('main');
$MainTemplate->set('NAME', $Language->text('title_page_search'));
diff --git a/admin/post/search.php b/admin/post/search.php
index b438201..a270ccb 100644
--- a/admin/post/search.php
+++ b/admin/post/search.php
@@ -11,24 +11,53 @@ const AUTHENTICATION = TRUE;
require '../../core/application.php';
#===============================================================================
+# Get repositories
+#===============================================================================
+$PostRepository = Application::getRepository('Post');
+$UserRepository = Application::getRepository('User');
+
+#===============================================================================
+# Pagination
+#===============================================================================
+$site_size = Application::get('ADMIN.POST.LIST_SIZE');
+$site_sort = Application::get('ADMIN.POST.LIST_SORT');
+
+$currentSite = HTTP::GET('site') ?? 1;
+$currentSite = intval($currentSite);
+$offset = ($currentSite-1) * $site_size;
+
+#===============================================================================
# Check for search request
#===============================================================================
if($search = HTTP::GET('q')) {
- $PostRepository = Application::getRepository('Post');
- $UserRepository = Application::getRepository('User');
-
- foreach($PostRepository->search($search) as $Post) {
+ foreach($PostRepository->search($search, [], $site_size, $offset) as $Post) {
$User = $UserRepository->find($Post->get('user'));
$templates[] = generatePostItemTemplate($Post, $User);
}
}
#===============================================================================
+# Create pagination only if there are results
+#===============================================================================
+if($count = $PostRepository->getLastSearchOverallCount()) {
+ $last = ceil($count / $site_size);
+
+ $pagination_data = [
+ 'THIS' => $currentSite,
+ 'LAST' => $last,
+ 'HTML' => createPaginationTemplate(
+ $currentSite, $last, Application::getAdminURL('post/search.php')
+ )
+ ];
+}
+
+#===============================================================================
# Build document
#===============================================================================
$SearchTemplate = Template\Factory::build('post/search');
$SearchTemplate->set('QUERY', $search);
$SearchTemplate->set('POSTS', $templates ?? []);
+$SearchTemplate->set('PAGINATION', $pagination_data ?? []);
$MainTemplate = Template\Factory::build('main');
$MainTemplate->set('NAME', $Language->text('title_post_search'));