Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/QueryObjectDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ 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 = $itemsPerPage
? iterator_to_array($this->queryObject->getResultSet($page, $itemsPerPage)->getIterator())
: $this->queryObject->fetch();
}

return $this->resultSet;
Expand All @@ -104,7 +106,7 @@ protected function getResultSet() {
* @return int
*/
public function getCount(): int {
return $this->queryObject->fetch()->getTotalCount();
return $this->queryObject->count();
}

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

return $this->getResultSet()->toArray();
return $this->getResultSet();
}

/**
Expand Down Expand Up @@ -177,15 +179,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;
Expand Down