bludit/bl-kernel/boot/rules/99.paginator.php
2017-05-24 00:48:29 +02:00

55 lines
1.5 KiB
PHP

<?php defined('BLUDIT') or die('Bludit CMS.');
// Current page number
$currentPage = $Url->pageNumber();
Paginator::set('currentPage', $currentPage);
if($Url->whereAmI()=='admin') {
$itemsPerPage = ITEMS_PER_PAGE_ADMIN;
$amountOfItems = $dbPages->count(false);
}
elseif($Url->whereAmI()=='tag') {
$itemsPerPage = $Site->itemsPerPage();
$tagKey = $Url->slug();
$amountOfItems = $dbTags->countPagesByTag($tagKey);
}
elseif($Url->whereAmI()=='category') {
$itemsPerPage = $Site->itemsPerPage();
$categoryKey = $Url->slug();
$amountOfItems = $dbCategories->countPagesByCategory($categoryKey);
}
else {
$itemsPerPage = $Site->itemsPerPage();
$amountOfItems = $dbPages->count(true);
}
// Items per page
Paginator::set('itemsPerPage', $itemsPerPage);
// Amount of items
Paginator::set('amountOfItems', $amountOfItems);
// Amount of pages
$amountOfPages = (int) max(ceil($amountOfItems / $itemsPerPage), 1);
Paginator::set('amountOfPages', $amountOfPages);
// TRUE if exists a next page to show
$showNext = $amountOfPages > $currentPage;
Paginator::set('showNext', $showNext);
// TRUE if exists a previous page to show
$showPrev = $currentPage > Paginator::firstPage();
Paginator::set('showPrev', $showPrev);
// TRUE if exists a next and previous page to show
$showNextPrev = $showNext && $showPrev;
Paginator::set('showNextPrev', $showNextPrev);
// Integer with the next page
$nextPage = max(0, $currentPage+1);
Paginator::set('nextPage', $nextPage);
// Integer with the previous page
$prevPage = min($amountOfPages, $currentPage-1);
Paginator::set('prevPage', $prevPage);