aboutsummaryrefslogtreecommitdiffstats
path: root/core/include/category/list.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/include/category/list.php')
-rw-r--r--core/include/category/list.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/core/include/category/list.php b/core/include/category/list.php
new file mode 100644
index 0000000..9bd2a68
--- /dev/null
+++ b/core/include/category/list.php
@@ -0,0 +1,69 @@
+<?php
+#===============================================================================
+# Get instances
+#===============================================================================
+$Language = Application::getLanguage();
+
+#===============================================================================
+# Get repositories
+#===============================================================================
+$CategoryRepository = Application::getRepository('Category');
+$PostRepository = Application::getRepository('Post');
+
+#===============================================================================
+# Pagination
+#===============================================================================
+$site_size = Application::get('CATEGORY.LIST_SIZE');
+$site_sort = Application::get('CATEGORY.LIST_SORT');
+
+#$count = $CategoryRepository->getCount(['parent' => NULL]);
+$count = $CategoryRepository->getCount();
+$lastSite = ceil($count / $site_size);
+
+$currentSite = HTTP::GET('site') ?? 1;
+$currentSite = intval($currentSite);
+
+if($currentSite < 1 OR ($currentSite > $lastSite AND $lastSite > 0)) {
+ Application::error404();
+}
+
+#===============================================================================
+# Single redirect
+#===============================================================================
+if(Application::get('CATEGORY.SINGLE_REDIRECT') === TRUE AND $count === 1) {
+ $Category = $CategoryRepository->getLast();
+ HTTP::redirect(Application::getEntityURL($Category));
+}
+
+#===============================================================================
+# Get paginated category list
+#===============================================================================
+$categories = $CategoryRepository->getPaginatedTree(
+ $site_size,
+ ($currentSite-1) * $site_size
+);
+
+foreach($categories as $Category) {
+ $templates[] = generateCategoryItemTemplate($Category, TRUE);
+}
+
+#===============================================================================
+# Build document
+#===============================================================================
+$ListTemplate = Template\Factory::build('category/list');
+$ListTemplate->set('PAGINATION', [
+ 'THIS' => $currentSite,
+ 'LAST' => $lastSite,
+ 'HTML' => generateCategoryNaviTemplate($currentSite)
+]);
+$ListTemplate->set('LIST', [
+ 'CATEGORIES' => $templates ?? []
+]);
+
+$MainTemplate = Template\Factory::build('main');
+$MainTemplate->set('HTML', $ListTemplate);
+$MainTemplate->set('HEAD', [
+ 'NAME' => $Language->text('title_category_overview', $currentSite)
+]);
+
+echo $MainTemplate;