mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
36 lines
1019 B
PHP
36 lines
1019 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Common\Paginator\Util;
|
|
|
|
use Zend\Paginator\Paginator;
|
|
use Zend\Stdlib\ArrayUtils;
|
|
|
|
trait PaginatorUtilsTrait
|
|
{
|
|
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(),
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Checks if provided paginator is in last page
|
|
*
|
|
* @param Paginator $paginator
|
|
* @return bool
|
|
*/
|
|
protected function isLastPage(Paginator $paginator): bool
|
|
{
|
|
return $paginator->getCurrentPageNumber() >= $paginator->count();
|
|
}
|
|
}
|