From 738d98d128059b52b99bda336f5410f3b9b6bd7b Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 19 Jan 2026 08:29:59 +0100 Subject: --- QueryBuilderPaginator.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++ README.rst | 1 + 2 files changed, 56 insertions(+) create mode 100644 QueryBuilderPaginator.php create mode 100644 README.rst diff --git a/QueryBuilderPaginator.php b/QueryBuilderPaginator.php new file mode 100644 index 0000000..02bed79 --- /dev/null +++ b/QueryBuilderPaginator.php @@ -0,0 +1,55 @@ +queryBuilder = $queryBuilder; + $this->setCurrentPageNumber($currentPageNumber); + $this->setItemsPerPage($itemsPerPage); + + $this->updateInternalState(); + } + + public function getPaginatedItems(): iterable + { + return $this->paginatedQueryResult; + } + + protected function updatePaginatedItems(int $limit, int $offset): void + { + $this->paginatedQueryResult = $this->queryBuilder + ->setMaxResults($limit) + ->setFirstResult($offset) + ->execute() + ->fetchAllAssociative(); + } + + protected function getTotalAmountOfItems(): int + { + return (clone $this->queryBuilder)->count('uid')->executeQuery()->fetchOne(); + } + + protected function getAmountOfItemsOnCurrentPage(): int + { + return count($this->paginatedQueryResult); + } +} diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..19ed342 --- /dev/null +++ b/README.rst @@ -0,0 +1 @@ +.. which only fetches the records that shall be displayed, instead of all records from database like the "QueryResultPaginator" does. \ No newline at end of file -- cgit v1.2.3