Skip to content

Commit 8001796

Browse files
committed
refaktorizace
1 parent cea6fe0 commit 8001796

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

src/QueryObjectDataSource.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public function setLimitCallback($callback) {
9191
return $this;
9292
}
9393

94-
protected function getResultSet() {
94+
protected function getResultSet(int $page = 1, ?int $itemsPerPage = null) {
9595
if (!$this->resultSet) {
96-
$this->resultSet = $this->queryObject->fetch();
96+
$this->resultSet = $this->queryObject->getResultSet($page, $itemsPerPage);
9797
}
9898

9999
return $this->resultSet;
@@ -104,7 +104,7 @@ protected function getResultSet() {
104104
* @return int
105105
*/
106106
public function getCount(): int {
107-
return $this->queryObject->fetch()->getTotalCount();
107+
return $this->queryObject->count();
108108
}
109109

110110
/**
@@ -116,7 +116,7 @@ public function getData(): array {
116116
return $this->data;
117117
}
118118

119-
return $this->getResultSet()->toArray();
119+
return iterator_to_array($this->getResultSet()->getIterator());
120120
}
121121

122122
/**
@@ -177,15 +177,12 @@ public function filterOne(array $filter): IDataSource {
177177
* @return static
178178
*/
179179
public function limit(int $offset, int $limit): IDataSource {
180-
$defaultCallback = function () use ($offset, $limit) {
181-
$this->getResultSet()->applyPaging($offset, $limit);
182-
};
183180

184181
if (is_callable($this->limitCallback)) {
185182
call_user_func_array($this->limitCallback, [$offset, $limit, $defaultCallback]);
186183

187184
} else {
188-
$defaultCallback();
185+
$this->getResultSet($offset / $limit + 1, $limit);
189186
}
190187

191188
return $this;

0 commit comments

Comments
 (0)