From 3c75a3a6079a563645f4d416be335aba574377ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Costa?= Date: Fri, 12 Apr 2024 14:19:23 +0200 Subject: [PATCH] fix(add-paging-to-result-set): corrected page calculation to include position as well --- src/ResultSet.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ResultSet.php b/src/ResultSet.php index be71ac4..94811da 100644 --- a/src/ResultSet.php +++ b/src/ResultSet.php @@ -61,12 +61,13 @@ public function __construct(Traversable $traversable, $limit = null, $offset = n public function getCurrentPage(): int { if ($this->pageSize) { - if ($this->offset && $this->offset > $this->pageSize) { - // offset is not on the first page anymore - return intval(floor($this->offset / $this->pageSize)); + $offset = $this->offset ?: 0; + if ($this->position && ($this->position + $offset) > $this->pageSize) { + // we are not on the first page anymore, calculating proper page + return intval(floor(($this->position + $offset) / $this->pageSize)); } - // no offset defined or still on page 1 + // still on the first page return 1; }