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-06 21:46:58 +02:00
$numberOfItems = $pages->count(true);
2015-07-20 05:14:12 +02:00
}
elseif($url->whereAmI()=='tag') {
$itemsPerPage = $site->itemsPerPage();
$tagKey = $url->slug();
2018-08-06 21:46:58 +02:00
$numberOfItems = $tags->numberOfPages($tagKey);
2017-05-16 00:46:20 +02:00
}
elseif($url->whereAmI()=='category') {
$itemsPerPage = $site->itemsPerPage();
$categoryKey = $url->slug();
2018-08-06 21:46:58 +02:00
$numberOfItems = $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-06 21:46:58 +02:00
$numberOfItems = $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
2018-08-06 21:46:58 +02:00
Paginator::set('numberOfItems', $numberOfItems);
2015-07-20 05:14:12 +02:00
2017-05-16 00:46:20 +02:00
// Amount of pages
2018-08-06 21:46:58 +02:00
$numberOfPages = (int) max(ceil($numberOfItems / $itemsPerPage), 1);
Paginator::set('numberOfPages', $numberOfPages);
2015-07-20 05:14:12 +02:00
2017-05-24 00:48:29 +02:00
// TRUE if exists a next page to show
2018-08-06 21:46:58 +02:00
$showNext = $numberOfPages > $currentPage;
2017-05-24 00:48:29 +02:00
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
2018-08-06 21:46:58 +02:00
$prevPage = min($numberOfPages, $currentPage-1);
2015-07-20 05:14:12 +02:00
Paginator::set('prevPage', $prevPage);