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
31 changes: 26 additions & 5 deletions src/Picqer/Financials/Exact/Query/Findable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ abstract public function connection();

abstract protected function isFillable($key);

/**
* @return string
*/
abstract public function url(): string;

abstract public function primaryKey(): string;

/**
* @return static
*/
public function find($id)
{
$filter = $this->primaryKey() . " eq guid'$id'";
Expand All @@ -41,6 +41,9 @@ public function find($id)
return new static($this->connection(), $result);
}

/**
* @return static
*/
public function findWithSelect($id, $select = '')
{
//eg: $oAccounts->findWithSelect('5b7f4515-b7a0-4839-ac69-574968677d96', 'Code, Name');
Expand Down Expand Up @@ -83,13 +86,19 @@ public function findId($code, $key = 'Code')
}
}

/**
* @return static[]
*/
public function filter($filter, $expand = '', $select = '', $system_query_options = null, array $headers = []): array
{
return iterator_to_array(
$this->filterAsGenerator($filter, $expand, $select, $system_query_options, $headers)
);
}

/**
* @return Generator<static>
*/
public function filterAsGenerator($filter, $expand = '', $select = '', $system_query_options = null, array $headers = []): Generator
{
$originalDivision = $this->connection()->getDivision();
Expand Down Expand Up @@ -127,7 +136,7 @@ public function filterAsGenerator($filter, $expand = '', $select = '', $system_q
/**
* Returns the first Financial model in by applying $top=1 to the query string.
*
* @return \Picqer\Financials\Exact\Model|null
* @return ?static
*/
public function first($filter = '', $expand = '', $select = '', $system_query_options = null, array $headers = [])
{
Expand All @@ -147,30 +156,42 @@ public function first($filter = '', $expand = '', $select = '', $system_query_op
return count($results) > 0 ? $results[0] : null;
}

public function getResultSet(array $params = [])
public function getResultSet(array $params = []): Resultset
{
return new Resultset($this->connection(), $this->url(), get_class($this), $params);
}

/**
* @return static[]
*/
public function get(array $params = []): array
{
return iterator_to_array($this->getAsGenerator($params));
}

/**
* @return Generator<static>
*/
public function getAsGenerator(array $params = []): Generator
{
$result = $this->connection()->get($this->url(), $params);

return $this->collectionFromResultAsGenerator($result);
}

/**
* @return static[]
*/
public function collectionFromResult($result, array $headers = []): array
{
return iterator_to_array(
$this->collectionFromResultAsGenerator($result, $headers)
);
}

/**
* @return Generator<static>
*/
public function collectionFromResultAsGenerator($result, array $headers = []): Generator
{
// If we have one result which is not an assoc array, make it the first element of an array for the
Expand Down