22 private $pageSize = 10;
25 private $totalCount = 0;
26 private $ignoreTotalCount =
false;
36 public function __construct($pageSize, $ignoreTotalCount=
false) {
37 $this->pageSize = intval($pageSize);
38 if ($this->pageSize == self::SIZE_INFINITE) {
39 $this->pageSize = PHP_INT_MAX;
41 $this->ignoreTotalCount = $ignoreTotalCount;
49 $this->totalCount = intval($totalCount);
57 return $this->totalCount;
65 $this->page = intval($page);
66 $this->offset = ($page - 1) * $this->pageSize;
82 return $this->pageSize;
90 return ceil($this->totalCount / $this->pageSize);
98 $this->offset = $offset;
99 $this->page = ceil(intval($offset) / $this->pageSize) + 1;
107 return $this->offset;
115 return $this->page == 1;
123 return $this->page == $this->getPageCount;
131 return $this->ignoreTotalCount;
146 $getPage =
function($val) use ($urlPattern) {
147 return [
'num' => $val,
'url' => str_replace(
'{page}', $val, $urlPattern)];
154 $halfRange = floor($maxDisplayPages/2);
155 $startPage = ($page < $halfRange) ? $first : max([$page-$halfRange, $first]);
156 $endPage = $maxDisplayPages-1 + $startPage;
157 $endPage = ($last < $endPage) ? $last : $endPage;
158 $diff = $startPage - $endPage + $maxDisplayPages-1;
159 $startPage -= ($startPage - $diff > 0) ? $diff : 0;
161 $pages = array_map($getPage, range($startPage, $endPage));
164 'first' => $getPage($first),
165 'last' => $getPage($last),
166 'current' => $getPage($page),
167 'prev' => $page > $startPage ? $getPage($page-1) :
null,
168 'next' => $page < $endPage ? $getPage($page+1) :
null,
setPage($page)
Set the current page (1-based) (also sets the offset).
isIgnoringTotalCount()
Check if this instance iignores the total count.
getPage()
Get the current page (1-based).
isOnFirstPage()
Determine if we are on the first page.
Persistence layer related interfaces and classes.
setOffset($offset)
Set the current offset (also selects the page).
setTotalCount($totalCount)
Set the number of list items.
getPageCount()
Get the number of pages.
__construct($pageSize, $ignoreTotalCount=false)
Creates a PagingInfo object.
getPagination($urlPattern, $maxDisplayPages=10)
Get the pages for a pagination navigation.
PagingInfo contains information about a paged list.
isOnLastPage()
Determine if we are on the first page.
getTotalCount()
Get the number of list items.
getOffset()
Get the current offset.
getPageSize()
Get the size of a pages.