AccessCodeCollection

Extends \NextEvent\PHPSDK\Model\Collection

The access code collection holds access code instances.

An instance of this collection can update the entry state of all access codes inside of it with one single API request.

package

NextEvent\PHPSDK\Model

Methods

Creates a new collection.

__construct(string $modelClass, array $instanceArgs = null, array $data = null, \NextEvent\PHPSDK\Rest\Client $restClient = null) 
inherited

Arguments

$modelClass

string

The class of the models in this collection.

$instanceArgs

array

Additional instance arguments to pass to the model constructor.

$data

array

Optional response data to initialize the collection with.

$restClient

\NextEvent\PHPSDK\Rest\Client

Rest client for fetching next pages.

Returns the total amount of items in this collection.

count() : integer
inherited

Response

integer

Returns the value at current iterator position.

current() : mixed
inherited

Response

mixed

Fetches the next page, if it is set and updates the data.

fetchNextPage() : boolean
inherited
Throws
\NextEvent\PHPSDK\Exception\CollectionException

If no rest client has been set.

Response

boolean

Whether the next page has been fetched or not. false means, we have no next page to fetch.

Filters this collection with the given callback.

filter(callable $callback) : \NextEvent\PHPSDK\Model\Collection
inherited

Arguments

$callback

callable

Response

\NextEvent\PHPSDK\Model\Collection

A new collection instance with the filtered content.

Getter for the autofetch flag

getAutofetch() : boolean
inherited

Response

boolean

Returns the current page.

getCurrentPage() : string
inherited

Response

string

Returns the last page.

getLastPage() : string
inherited

Response

string

The model class of this collection.

getModelClass() : string
inherited

Response

string

Returns the next page.

getNextPage() : string
inherited

Response

string

The current page number.

getPage() : integer
inherited

Response

integer

The amount of pages in total.

getPages() : integer
inherited

Response

integer

The page size of this collection.

getPageSize() : integer
inherited

Response

integer

Returns the previous page.

getPreviousPage() : string
inherited

Response

string

Returns the current iterator position.

key() : integer
inherited

Response

integer

Applies a callback to the elements of the collection

map(callable $callback) : array
inherited

This works similar to PHP's array_map() function and allows to transform the collection with a given callback function.

Throws
\NextEvent\PHPSDK\Exception\InvalidArgumentException

Arguments

$callback

callable

Callback function to run for each element. Receives the current element as argument.

Response

array

containing all the elements of the collection1 after applying the callback function to each one

Increases the iterator position.

next() : void
inherited

Returns whether the given offset exists.

offsetExists(mixed $offset) : boolean
inherited

Arguments

$offset

mixed

The offset to check.

Response

boolean

Returns the value at the given offset.

offsetGet(mixed $offset) : mixed
inherited

Arguments

$offset

mixed

The offset to get the value at.

Response

mixed

Sets the given value at the given offset.

offsetSet(mixed $offset, mixed $value) : void
inherited

Only instances of the current model class can be set in this collection.

Throws
\NextEvent\PHPSDK\Exception\CollectionException

If the value is not an instance of the current model class.

Arguments

$offset

mixed

The offset to set the value at.

$value

mixed

The value to set.

Removes the value at the given $offset.

offsetUnset(mixed $offset) : void
inherited

Arguments

$offset

mixed

The offset at which to remove the value.

Resets the iterator position.

rewind() : void
inherited

Setter for the autofetch flag

setAutofetch(boolean $autoFetch) 
inherited

If enabled, iterating the collection will automatically fetch all pages and thus list all records that match the request/query.

Arguments

$autoFetch

boolean

Sets the data data by applying the given response data.

setData(array $data, boolean $reset = true) : void
inherited

This method assumes that the given data holds the structure of a HAL response.

Throws
\NextEvent\PHPSDK\Exception\CollectionException

Arguments

$data

array

$reset

boolean

Whether to reset the internal models array.

Updates the entry state of the access codes via the given device at the logged in gate.

setEntryState(\NextEvent\PHPSDK\Model\Device $device, integer $entryState = null, string $connection = 'online', array|null $categories = null, string $processed = null) : \NextEvent\PHPSDK\Model\AccessCodeCollection

You will receive validation messages for each access code which failed to update the entry state.

see \NextEvent\PHPSDK\Model\AccessCode::ENTRY_IN

and

\NextEvent\PHPSDK\Model\AccessCode::ENTRY_OUT

when passing $entryState

Throws
\NextEvent\PHPSDK\Exception\AccessCodeValidateException

If the device is not logged in.
If $entryState is not set but the gate mode is both.
If an invalid $entryState has been passed.
If no rest client has been set on this model.

Arguments

$device

\NextEvent\PHPSDK\Model\Device

The device on which the codes have to be validated.

$entryState

integer

The new entry state of the code. If the mode of the gate is not both, the mode of the gate will be used by default.

$connection

string

Optional connection parameter. Default is 'online'.

$categories

array|null

Optional list of categories to validate. By default the category id of this access code will be set.

$processed

string

Optional processed time. Default is the current time of the server this code runs on.

Response

\NextEvent\PHPSDK\Model\AccessCodeCollection

Set additional arguments which should be passed to the model constructor.

setInstanceArguments(array $arguments) : void
inherited

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.

Arguments

$arguments

array

Returns whether the current iterator position has a valid value.

valid() : boolean
inherited

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.

Response

boolean