fix errors in pagination

This commit is contained in:
Julien Fastré 2019-10-25 14:35:34 +02:00
parent 517ea1de31
commit f23aec0649
3 changed files with 20 additions and 3 deletions

View File

@ -80,3 +80,8 @@ Version 1.5.13
- allow to customize logo on login screen and main layout ;
- remove desert background image on page, handle it from cache in login screen;
Master branch
=============
- fix errors in pagination

View File

@ -63,6 +63,13 @@ class Page implements PageInterface
* @var int
*/
protected $itemPerPage;
/**
* The number of items in the whole iteration
*
* @var int
*/
protected $totalItems;
public function __construct(
@ -70,13 +77,15 @@ class Page implements PageInterface
$itemPerPage,
UrlGeneratorInterface $urlGenerator,
$route,
array $routeParameters
array $routeParameters,
$totalItems
) {
$this->urlGenerator = $urlGenerator;
$this->number = $number;
$this->itemPerPage = $itemPerPage;
$this->route = $route;
$this->routeParameters = $routeParameters;
$this->totalItems = $totalItems;
}
public function generateUrl()
@ -91,7 +100,9 @@ class Page implements PageInterface
public function getLastItemNumber()
{
return $this->number * $this->itemPerPage - 1;
$last = $this->number * $this->itemPerPage - 1;
return $last < $this->totalItems ? $last : $this->totalItems;
}
public function getNumber()

View File

@ -232,7 +232,8 @@ class Paginator implements PaginatorInterface
array_merge($this->routeParameters, array(
$this->pageKey => $number,
$this->itemPerPageKey => $this->itemPerPage
))
)),
$this->totalItems
);
}