bludit/bl-kernel/boot/rules/99.paginator.php

55 lines
1.5 KiB
PHP
Raw Normal View History

2015-07-20 05:14:12 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
2017-05-16 00:46:20 +02:00
// Current page number
$currentPage = $url->pageNumber();
2015-07-20 05:14:12 +02:00
Paginator::set('currentPage', $currentPage);
if($url->whereAmI()=='admin') {
2017-05-16 00:46:20 +02:00
$itemsPerPage = ITEMS_PER_PAGE_ADMIN;
2018-08-03 18:59:23 +02:00
$amountOfItems = $pages->count(true);
2015-07-20 05:14:12 +02:00
}
elseif($url->whereAmI()=='tag') {
$itemsPerPage = $site->itemsPerPage();
$tagKey = $url->slug();
2018-08-04 12:44:37 +02:00
$amountOfItems = $tags->numberOfPages($tagKey);
2017-05-16 00:46:20 +02:00
}
elseif($url->whereAmI()=='category') {
$itemsPerPage = $site->itemsPerPage();
$categoryKey = $url->slug();
2018-08-04 12:44:37 +02:00
$amountOfItems = $categories->numberOfPages($categoryKey);
2016-01-17 01:11:58 +01:00
}
2015-07-20 05:14:12 +02:00
else {
$itemsPerPage = $site->itemsPerPage();
2018-08-03 18:59:23 +02:00
$amountOfItems = $pages->count(true);
2015-07-20 05:14:12 +02:00
}
2017-05-16 00:46:20 +02:00
// Items per page
Paginator::set('itemsPerPage', $itemsPerPage);
2015-07-24 05:28:25 +02:00
2017-05-16 00:46:20 +02:00
// Amount of items
Paginator::set('amountOfItems', $amountOfItems);
2015-07-20 05:14:12 +02:00
2017-05-16 00:46:20 +02:00
// Amount of pages
2017-05-24 00:48:29 +02:00
$amountOfPages = (int) max(ceil($amountOfItems / $itemsPerPage), 1);
2017-05-16 00:46:20 +02:00
Paginator::set('amountOfPages', $amountOfPages);
2015-07-20 05:14:12 +02:00
2017-05-24 00:48:29 +02:00
// TRUE if exists a next page to show
$showNext = $amountOfPages > $currentPage;
Paginator::set('showNext', $showNext);
2015-07-20 05:14:12 +02:00
2017-05-24 00:48:29 +02:00
// TRUE if exists a previous page to show
$showPrev = $currentPage > Paginator::firstPage();
Paginator::set('showPrev', $showPrev);
2015-07-20 05:14:12 +02:00
2017-05-24 00:48:29 +02:00
// TRUE if exists a next and previous page to show
$showNextPrev = $showNext && $showPrev;
Paginator::set('showNextPrev', $showNextPrev);
2015-07-20 05:14:12 +02:00
2017-05-24 00:48:29 +02:00
// Integer with the next page
2015-07-20 05:14:12 +02:00
$nextPage = max(0, $currentPage+1);
Paginator::set('nextPage', $nextPage);
2017-05-24 00:48:29 +02:00
// Integer with the previous page
2017-05-16 00:46:20 +02:00
$prevPage = min($amountOfPages, $currentPage-1);
2015-07-20 05:14:12 +02:00
Paginator::set('prevPage', $prevPage);