From f23aec06492012cf52d468f03837062b21d4f525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 25 Oct 2019 14:35:34 +0200 Subject: [PATCH] fix errors in pagination --- CHANGELOG.md | 5 +++++ Pagination/Page.php | 15 +++++++++++++-- Pagination/Paginator.php | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80da558b3..8bbfc421e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Pagination/Page.php b/Pagination/Page.php index 2cf400e4e..e6b3943ed 100644 --- a/Pagination/Page.php +++ b/Pagination/Page.php @@ -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() diff --git a/Pagination/Paginator.php b/Pagination/Paginator.php index 54b71799c..82577d078 100644 --- a/Pagination/Paginator.php +++ b/Pagination/Paginator.php @@ -232,7 +232,8 @@ class Paginator implements PaginatorInterface array_merge($this->routeParameters, array( $this->pageKey => $number, $this->itemPerPageKey => $this->itemPerPage - )) + )), + $this->totalItems ); }