Skip to content

Commit 9941647

Browse files
authored
Merge pull request #9 from AppsDevTeam/refaktorizace
refaktorizace
2 parents cea6fe0 + 0517ac7 commit 9941647

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

src/QueryObjectDataSource.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ 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 = $itemsPerPage
97+
? iterator_to_array($this->queryObject->getResultSet($page, $itemsPerPage)->getIterator())
98+
: $this->queryObject->fetch();
9799
}
98100

99101
return $this->resultSet;
@@ -104,7 +106,7 @@ protected function getResultSet() {
104106
* @return int
105107
*/
106108
public function getCount(): int {
107-
return $this->queryObject->fetch()->getTotalCount();
109+
return $this->queryObject->count();
108110
}
109111

110112
/**
@@ -116,7 +118,7 @@ public function getData(): array {
116118
return $this->data;
117119
}
118120

119-
return $this->getResultSet()->toArray();
121+
return $this->getResultSet();
120122
}
121123

122124
/**
@@ -177,15 +179,12 @@ public function filterOne(array $filter): IDataSource {
177179
* @return static
178180
*/
179181
public function limit(int $offset, int $limit): IDataSource {
180-
$defaultCallback = function () use ($offset, $limit) {
181-
$this->getResultSet()->applyPaging($offset, $limit);
182-
};
183182

184183
if (is_callable($this->limitCallback)) {
185184
call_user_func_array($this->limitCallback, [$offset, $limit, $defaultCallback]);
186185

187186
} else {
188-
$defaultCallback();
187+
$this->getResultSet($offset / $limit + 1, $limit);
189188
}
190189

191190
return $this;

0 commit comments

Comments
 (0)