Improved paginator properties

This commit is contained in:
Alejandro Celaya 2018-06-17 18:29:40 +02:00
parent 8cfb4f61ca
commit f78a7f12a9
3 changed files with 23 additions and 5 deletions

View File

@ -3,11 +3,23 @@
"properties": {
"currentPage": {
"type": "integer",
"description": "The number of current page being displayed."
"description": "The number of current page."
},
"pagesCount": {
"type": "integer",
"description": "The total number of pages that can be displayed."
"description": "The total number of pages that can be obtained."
},
"itemsPerPage": {
"type": "integer",
"description": "The number of items for every page."
},
"itemsInCurrentPage": {
"type": "integer",
"description": "The number of items in current page (could be smaller than itemsPerPage)."
},
"totalItems": {
"type": "integer",
"description": "The total number of items among all pages."
}
}
}

View File

@ -116,7 +116,10 @@
],
"pagination": {
"currentPage": 5,
"pagesCount": 12
"pagesCount": 12,
"itemsPerPage": 10,
"itemsInCurrentPage": 10,
"totalItems": 115
}
}
}

View File

@ -8,13 +8,16 @@ use Zend\Stdlib\ArrayUtils;
trait PaginatorUtilsTrait
{
protected function serializePaginator(Paginator $paginator)
protected function serializePaginator(Paginator $paginator): array
{
return [
'data' => ArrayUtils::iteratorToArray($paginator->getCurrentItems()),
'pagination' => [
'currentPage' => $paginator->getCurrentPageNumber(),
'pagesCount' => $paginator->count(),
'itemsPerPage' => $paginator->getItemCountPerPage(),
'itemsInCurrentPage' => $paginator->getCurrentItemCount(),
'totalItems' => $paginator->getTotalItemCount(),
],
];
}
@ -25,7 +28,7 @@ trait PaginatorUtilsTrait
* @param Paginator $paginator
* @return bool
*/
protected function isLastPage(Paginator $paginator)
protected function isLastPage(Paginator $paginator): bool
{
return $paginator->getCurrentPageNumber() >= $paginator->count();
}