From 800179603162e4c6a79d6ce3f651a6ccb87de4e5 Mon Sep 17 00:00:00 2001 From: Marek Valuch Date: Fri, 10 Jun 2022 10:40:06 +0200 Subject: [PATCH 1/3] refaktorizace --- src/QueryObjectDataSource.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/QueryObjectDataSource.php b/src/QueryObjectDataSource.php index 7c950d5..47935dd 100644 --- a/src/QueryObjectDataSource.php +++ b/src/QueryObjectDataSource.php @@ -91,9 +91,9 @@ public function setLimitCallback($callback) { return $this; } - protected function getResultSet() { + protected function getResultSet(int $page = 1, ?int $itemsPerPage = null) { if (!$this->resultSet) { - $this->resultSet = $this->queryObject->fetch(); + $this->resultSet = $this->queryObject->getResultSet($page, $itemsPerPage); } return $this->resultSet; @@ -104,7 +104,7 @@ protected function getResultSet() { * @return int */ public function getCount(): int { - return $this->queryObject->fetch()->getTotalCount(); + return $this->queryObject->count(); } /** @@ -116,7 +116,7 @@ public function getData(): array { return $this->data; } - return $this->getResultSet()->toArray(); + return iterator_to_array($this->getResultSet()->getIterator()); } /** @@ -177,15 +177,12 @@ public function filterOne(array $filter): IDataSource { * @return static */ public function limit(int $offset, int $limit): IDataSource { - $defaultCallback = function () use ($offset, $limit) { - $this->getResultSet()->applyPaging($offset, $limit); - }; if (is_callable($this->limitCallback)) { call_user_func_array($this->limitCallback, [$offset, $limit, $defaultCallback]); } else { - $defaultCallback(); + $this->getResultSet($offset / $limit + 1, $limit); } return $this; From c0ef34f29dbc4186aba9c6e0f146b7056b0a117b Mon Sep 17 00:00:00 2001 From: superchlastac <108008045+superchlastac@users.noreply.github.com> Date: Wed, 22 Jun 2022 16:19:08 +0200 Subject: [PATCH 2/3] Update QueryObjectDataSource.php --- src/QueryObjectDataSource.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/QueryObjectDataSource.php b/src/QueryObjectDataSource.php index 47935dd..bda3d2d 100644 --- a/src/QueryObjectDataSource.php +++ b/src/QueryObjectDataSource.php @@ -93,7 +93,9 @@ public function setLimitCallback($callback) { protected function getResultSet(int $page = 1, ?int $itemsPerPage = null) { if (!$this->resultSet) { - $this->resultSet = $this->queryObject->getResultSet($page, $itemsPerPage); + $this->resultSet = $itemsPerPage + ? $this->queryObject->getResultSet($page, $itemsPerPage)->getIterator() + : $this->queryObject->fetch(); } return $this->resultSet; @@ -116,7 +118,7 @@ public function getData(): array { return $this->data; } - return iterator_to_array($this->getResultSet()->getIterator()); + return $this->getResultSet(); } /** From 0517ac7e83e9f6a917842ad00ad084482a1fb2e3 Mon Sep 17 00:00:00 2001 From: superchlastac <108008045+superchlastac@users.noreply.github.com> Date: Wed, 22 Jun 2022 16:37:29 +0200 Subject: [PATCH 3/3] Update QueryObjectDataSource.php --- src/QueryObjectDataSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryObjectDataSource.php b/src/QueryObjectDataSource.php index bda3d2d..2e81ee6 100644 --- a/src/QueryObjectDataSource.php +++ b/src/QueryObjectDataSource.php @@ -94,7 +94,7 @@ public function setLimitCallback($callback) { protected function getResultSet(int $page = 1, ?int $itemsPerPage = null) { if (!$this->resultSet) { $this->resultSet = $itemsPerPage - ? $this->queryObject->getResultSet($page, $itemsPerPage)->getIterator() + ? iterator_to_array($this->queryObject->getResultSet($page, $itemsPerPage)->getIterator()) : $this->queryObject->fetch(); }