Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
midorikocak committed Feb 3, 2020
1 parent 90febf8 commit 7a4f56c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .phpcs-cache

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,34 @@ class Users implements RepositoryInterface
return self::fromArray($data);
}

public function readAll(array $constraints = [], array $columns = ['*']): array
{
public function readAll(
array $filter = [],
array $columns = ['*'],
?int $limit = null,
?int $offset = null
):array {
$db = $this->db->select('users', $columns);

if (!empty($constraints)) {
$value = reset($constraints);
$key = key($constraints);
if (!empty($filter)) {
$value = reset($filter);
$key = key($filter);
$db->where($key, $value);

unset($constraints[key($constraints)]);
unset($filter[key($filter)]);

foreach ($constraints as $key => $value) {
foreach ($filter as $key => $value) {
$db->and($key, $value);
}
}

if ($limit) {
$this->db->limit($limit);
}

if ($limit && $offset) {
$this->db->offset($offset);
}

$db->execute();
return array_map(fn($data) => self::fromArray($data), $db->fetchAll());
}
Expand Down

0 comments on commit 7a4f56c

Please sign in to comment.