A collection holds instances of models by converting them from raw data.
It has meta information about the total amount of items, pages and references to other pages. Further more it allows to iterate over all total items, by simply fetching the next page if the bounds of the current page have been reached.
If you want to fetch the next page manually, you can call Collection::fetchNextPage(). This will fetch the next page, if it is available and apply the content to this collection.
In order to fetch a specific page and apply it to the collection, you can fetch it with the rest client
and then apply it via Collection::setData(). Whether you want to reset the current data or not
can be controlled with the flag reset.
| package |
NextEvent\PHPSDK\Model |
|---|
__construct(string $modelClass, array $instanceArgs = null, array $data = null, \NextEvent\PHPSDK\Rest\Client $restClient = null)
stringThe class of the models in this collection.
arrayAdditional instance arguments to pass to the model constructor.
arrayOptional response data to initialize the collection with.
count() : integer
integer
current() : mixed
mixed
fetchNextPage() : boolean
| Throws |
|
|---|
booleanWhether the next page has been fetched or not. false means, we have no next page to fetch.
filter(callable $callback) : \NextEvent\PHPSDK\Model\Collection
callable
\NextEvent\PHPSDK\Model\CollectionA new collection instance with the filtered content.
getAutofetch() : boolean
boolean
getCurrentPage() : string
string
getLastPage() : string
string
getModelClass() : string
string
getNextPage() : string
string
getPage() : integer
integer
getPages() : integer
integer
getPageSize() : integer
integer
getPreviousPage() : string
string
key() : integer
integer
map(callable $callback) : array
This works similar to PHP's array_map() function and allows to
transform the collection with a given callback function.
| Throws |
|
|---|
callableCallback function to run for each element. Receives the current element as argument.
arraycontaining all the elements of the collection1 after applying the callback function to each one
next() : void
offsetExists(mixed $offset) : boolean
mixedThe offset to check.
boolean
offsetGet(mixed $offset) : mixed
mixedThe offset to get the value at.
mixed
offsetSet(mixed $offset, mixed $value) : void
Only instances of the current model class can be set in this collection.
| Throws |
|
|---|
mixedThe offset to set the value at.
mixedThe value to set.
offsetUnset(mixed $offset) : void
mixedThe offset at which to remove the value.
rewind() : void
setAutofetch(boolean $autoFetch)
If enabled, iterating the collection will automatically fetch all pages and thus list all records that match the request/query.
boolean
setData(array $data, boolean $reset = true) : void
This method assumes that the given data holds the structure of a HAL response.
| Throws |
|
|---|
array
booleanWhether to reset the internal models array.
setInstanceArguments(array $arguments) : void
You can pass a function as a value, which has to return the value type expected by the constructor of the model. The raw model data will be passed to that function.
array
valid() : boolean
If the iterator position is at the end of the page, but not at the end of the whole collection, the next page will be fetched.
boolean