From f1d09d8cdc6e4a1ed0fb44544b368c6632bbd379 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Thu, 1 Jul 2021 21:25:43 +0200 Subject: Add function generateCategoryPostNaviTemplate Add and use the function generateCategoryPostNaviTemplate to build the pagination template for posts in a category. This fixes a mistake. TODO: Get rid of that confusing function mess! --- core/functions.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'core/functions.php') diff --git a/core/functions.php b/core/functions.php index ea4b7eb..3282f1c 100644 --- a/core/functions.php +++ b/core/functions.php @@ -53,6 +53,24 @@ function generateCategoryNaviTemplate($current): Template { return generateNaviTemplate($current, Application::getCategoryURL(), 'Category'); } +#=============================================================================== +# Generate the post navigation template for posts in a category +#=============================================================================== +function generateCategoryPostNaviTemplate(int $current, Category $Category): Template { + $location = Application::getEntityURL($Category); + $Repository = Application::getRepository('Post'); + + $listSize = Application::get('POST.LIST_SIZE'); + $lastSite = ceil($Repository->getCountByCategory($Category) / $listSize); + + $PaginationTemplate = TemplateFactory::build('pagination'); + $PaginationTemplate->set('THIS', $current); + $PaginationTemplate->set('LAST', $lastSite); + $PaginationTemplate->set('HREF', "{$location}?site=%d"); + + return $PaginationTemplate; +} + #=============================================================================== # Helper function to reduce duplicate code #=============================================================================== -- cgit v1.2.3