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 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 QueryBuilderPaginator.php (limited to 'QueryBuilderPaginator.php') 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); + } +} -- cgit v1.2.3