From 532fe9f7e6737c82e92d89cb1e41a90c89ce2839 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 16 Feb 2014 18:19:15 +0100 Subject: [PATCH] Added pagination to tag list --- data/config.ini | 1 + src/Controllers/TagController.php | 20 +++++++++++++++++-- .../SearchServices/TagSearchService.php | 2 +- src/Views/tag-list.phtml | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/data/config.ini b/data/config.ini index a9daccd9..dfcb0387 100644 --- a/data/config.ini +++ b/data/config.ini @@ -31,6 +31,7 @@ paths[privacy]=./data/privacy.md usersPerPage=8 postsPerPage=20 logsPerPage=250 +tagsPerPage=100 thumbWidth=150 thumbHeight=150 thumbStyle=outside diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 505ce4d9..c57118b2 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -3,17 +3,25 @@ class TagController { /** * @route /tags + * @route /tags/{page} * @route /tags/{filter} + * @route /tags/{filter}/{page} * @validate filter [a-zA-Z\32:,_-]+ + * @validate page \d* */ - public function listAction($filter = null) + public function listAction($filter = null, $page = 1) { $this->context->viewName = 'tag-list-wrapper'; PrivilegesHelper::confirmWithException(Privilege::ListTags); $suppliedFilter = $filter ?: InputHelper::get('filter') ?: 'order:alpha,asc'; + $page = max(1, intval($page)); + $tagsPerPage = intval($this->config->browsing->tagsPerPage); - $tags = TagSearchService::getEntitiesRows($suppliedFilter, null, null); + $tags = TagSearchService::getEntitiesRows($suppliedFilter, $tagsPerPage, $page); + $tagCount = TagSearchService::getEntityCount($suppliedFilter); + $pageCount = ceil($tagCount / $tagsPerPage); + $page = min($pageCount, $page); $this->context->filter = $suppliedFilter; $this->context->transport->tags = $tags; @@ -23,6 +31,14 @@ class TagController return ['name' => $tag['name'], 'count' => $tag['post_count']]; }, $this->context->transport->tags)); } + else + { + $this->context->transport->paginator = new StdClass; + $this->context->transport->paginator->page = $page; + $this->context->transport->paginator->pageCount = $pageCount; + $this->context->transport->paginator->entityCount = $tagCount; + $this->context->transport->paginator->entities = $tags; + } } /** diff --git a/src/Models/SearchServices/TagSearchService.php b/src/Models/SearchServices/TagSearchService.php index 9035bb2c..0c26b3f4 100644 --- a/src/Models/SearchServices/TagSearchService.php +++ b/src/Models/SearchServices/TagSearchService.php @@ -78,7 +78,7 @@ class TagSearchService extends AbstractSearchService break; case 'alpha': - $sqlQuery->orderBy('name'); + $sqlQuery->orderBy('tag.name'); break; } diff --git a/src/Views/tag-list.phtml b/src/Views/tag-list.phtml index 71a269cf..afd093f6 100644 --- a/src/Views/tag-list.phtml +++ b/src/Views/tag-list.phtml @@ -45,4 +45,6 @@ + + renderFile('paginator') ?>