aboutsummaryrefslogtreecommitdiffstats
path: root/core/functions.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-07-02 20:17:42 +0200
committerThomas Lange <code@nerdmind.de>2021-07-02 20:17:42 +0200
commitf5f94531c9d5b369fdf9c287f63c41476496e5ee (patch)
tree54aa2e26a044dca2d1f3604a920f1527c34e9021 /core/functions.php
parent3939dc93d0c11438e8a3e44c48aab2f37128eebc (diff)
downloadblog-f5f94531c9d5b369fdf9c287f63c41476496e5ee.tar.gz
blog-f5f94531c9d5b369fdf9c287f63c41476496e5ee.tar.xz
blog-f5f94531c9d5b369fdf9c287f63c41476496e5ee.zip
Add generic function to create pagination template
This commit adds and uses the new function createPaginationTemplate to create the generic pagination template for various entity lists. This function replaces the many old confusing functions: * generateNaviTemplate * generatePageNaviTemplate * generatePostNaviTemplate * generateUserNaviTemplate * generateCategoryNaviTemplate * generateCategoryPostNaviTemplate
Diffstat (limited to 'core/functions.php')
-rw-r--r--core/functions.php65
1 files changed, 7 insertions, 58 deletions
diff --git a/core/functions.php b/core/functions.php
index 3282f1c..8a46b5b 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -9,66 +9,15 @@ use Template\Template as Template;
use Template\Factory as TemplateFactory;
#===============================================================================
-# Helper function to reduce duplicate code
-#===============================================================================
-function generateNaviTemplate(int $current, $location, $namespace): Template {
- $Repository = Application::getRepository($namespace);
-
- $listSize = Application::get(strtoupper($namespace).'.LIST_SIZE');
- $lastSite = ceil($Repository->getCount() / $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
-#===============================================================================
-function generatePageNaviTemplate($current): Template {
- return generateNaviTemplate($current, Application::getPageURL(), 'Page');
-}
-
+# Create generic pagination template
#===============================================================================
-# Helper function to reduce duplicate code
-#===============================================================================
-function generatePostNaviTemplate($current): Template {
- return generateNaviTemplate($current, Application::getPostURL(), 'Post');
-}
-
-#===============================================================================
-# Helper function to reduce duplicate code
-#===============================================================================
-function generateUserNaviTemplate($current): Template {
- return generateNaviTemplate($current, Application::getUserURL(), 'User');
-}
-
-#===============================================================================
-# Helper function to reduce duplicate code
-#===============================================================================
-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");
+function createPaginationTemplate($current, $last, string $location): Template {
+ $Pagination = TemplateFactory::build('pagination');
+ $Pagination->set('THIS', $current);
+ $Pagination->set('LAST', $last);
+ $Pagination->set('HREF', "{$location}?site=%d");
- return $PaginationTemplate;
+ return $Pagination;
}
#===============================================================================