Skip to content
Open
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
12 changes: 9 additions & 3 deletions src/Picqer/Financials/Moneybird/Actions/Filterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,29 @@ trait Filterable
/**
* @param array $filters
* @param int|null $perPage Number of results per page
* @param int|null $page Page to load, typically starts at 1
* @param int|null $page Page to load, typically starts at 1.
* @param bool $fetchAll Whether to fetch all results or just the current page, this will override perPage and page parameters.
* @return mixed
*
* @throws \Picqer\Financials\Moneybird\Exceptions\ApiException
*/
public function filter(array $filters, $perPage = null, $page = null)
public function filter(array $filters, $perPage = null, $page = null, $fetchAll = false)
{
$filterList = [];
foreach ($filters as $key => $value) {
$filterList[] = $key . ':' . $value;
}

if($fetchAll === true) {
$perPage = null; // If fetching all, perPage should not be set
$page = null; // If fetching all, page should not be set
}

$result = $this->connection()->get($this->getFilterEndpoint(), [
'filter' => implode(',', $filterList),
'per_page' => $perPage,
'page' => $page,
], false);
], $fetchAll);

return $this->collectionFromResult($result);
}
Expand Down