class ModelCollection implements ArrayAccess, IteratorAggregate, Countable

Properties

protected Model $model reference to model-type
protected bool|Model[] $models Array of models in this collection
protected bool $loaded Boolean which indicates whether collection is loaded or not (not equal empty!)

Methods

mixed
__call(mixed $method, mixed $args = array())

Handle find functions

__construct(Model $model, array|ModelCollection|bool $model_array = null)

Create new Model Array

__toString()

No description

_scope_by(mixed $fn, mixed $parameters)

Magic Function to add Scope (Used by Model)

_search_by(string $query, array|bool $parameters = false, boolean $return_single = true)

returns model found by property => value

add_formatted_property(string $property, string $format, array $options = array())

Apply lib->format multi_format on passed property. The result will be written to ->[property]_formatted

add_scope_condition(string $new_condition)

Add condition to scope, e.g. customer_id=2

all(mixed $args = array())

Find Function to find models using the passed condition

append(mixed $value)

Adds an Object to the models-array.

attach(string $property, array $values, string $key_field = null)

Set property values to models from array

clear_scope()

Resets the scope of this collection

int
count()

returns the number of containing models this function is called if the php function count(this_collection) is used

debug()

No description

void
filter(mixed $callback = false)

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

getIterator()

put your comment there.

get_clone()

Generates a Clone (useful for slicing an collection to lots of slices)

array|bool
get_db_properties()

No description

get_model()

Returns the Default-Model (-Type) for this Collection

string
get_model_class()

put your comment there.

array
get_models()

Returns array with objects

array
invoke(string $method)

Calls the passed method for each object

boolean
is_loaded()

Returns true if this collection has been filled

Model|bool
last()

Return the last element of the collection

void
merge()

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

bool
offsetExists(mixed $offset)

put your comment there.

offsetGet(mixed $offset)

put your comment there.

offsetSet(mixed $offset, mixed $value)

put your comment there.

offsetUnset(mixed $offset)

put your comment there.

overwrite_models(ModelCollection|Model|Model[] $model_array)

This will overwrite the models-array with any value

array([$key_field]
pluck(string|string[] $property, string $key_field = null)

Returns the passed property of all objects in an array

array
pluck_unique(mixed $property, mixed $key_field = false)

Returns the passed property of all objects in an array (unique and filtered)

mixed
pop()

this function returns the last value of the models-array, shortening the models-array by one element.

int
push($model1, $model2 = null)

this function treats models-array as a stack, and pushes the passed variables onto the end of array.

bool
require_loading()

If the collection is not loaded yes the collection will use all() to be filled

reverse(boolean $preserve_keys = false)

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

Model
search_by_id($id, $query_params = false)

No description

search_by_transition_id(int $id)

No description

mixed
shift()

This function shifts the first value of the models-array off and returns it, shortening the array by one element and moving everything down.

slice(int $offset, int|bool $length = false, boolean $preserve_keys = false)

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

sort_by(string $property, string $order_by = 'asc', int $type = XF_SORTTYPE_ALPHABETICAL)

Sorts the current Collection by given Property-Name

mixed
sum(string $property, string|bool $group_field = false)

Returns the sum of the passed property across all models

array|Model[]
to_array(bool $raw = false)

Returns collection as array of models

string
to_json()

Returns collection as json of models

string
to_string()

Returns collection as string

string
to_xml(array|bool $property_filter = false)

Returns an XML of all model properties

mixed
unshift()

This function prepends passed elements to the front of the array.

boolean
usort(mixed $cmp_function)

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

Details

at line 168
mixed __call(mixed $method, mixed $args = array())

Handle find functions

Parameters

mixed $method
mixed $args

Return Value

mixed

at line 78
__construct(Model $model, array|ModelCollection|bool $model_array = null)

Create new Model Array

Parameters

Model $model Reference to Model
array|ModelCollection|bool $model_array Optional array of Models to initialize collection with

at line 680
__toString()

at line 115
ModelCollection _scope_by(mixed $fn, mixed $parameters)

Magic Function to add Scope (Used by Model)

Parameters

mixed $fn
mixed $parameters

Return Value

ModelCollection

at line 401
protected Model|ModelCollection|bool _search_by(string $query, array|bool $parameters = false, boolean $return_single = true)

returns model found by property => value

Parameters

string $query function_name_query (e.g.: title_and_user_id)
array|bool $parameters
boolean $return_single determines the result-type [FALSE] : Model or boolean false on fail [TRUE] : ModelCollection

Return Value

Model|ModelCollection|bool see also param-doc of "$return_single"

at line 667
add_formatted_property(string $property, string $format, array $options = array())

Apply lib->format multi_format on passed property. The result will be written to ->[property]_formatted

Parameters

string $property Property of models to format
string $format Format Type (e.g. money, date, ...)
array $options Additional format options

at line 101
ModelCollection add_scope_condition(string $new_condition)

Add condition to scope, e.g. customer_id=2

Parameters

string $new_condition Scope Condition String

Return Value

ModelCollection

at line 225
ModelCollection all(mixed $args = array())

Find Function to find models using the passed condition

Parameters

mixed $args Further query parameters (e.g. LIMIT) $params['limit'] --> Limit condition, e.g. limit=>'1,10' $params['order_by'] --> Order condition, e.g. order_by='id ASC'

Return Value

ModelCollection result

at line 762
append(mixed $value)

Adds an Object to the models-array.

It will be appended after the last position of array

Parameters

mixed $value

at line 365
attach(string $property, array $values, string $key_field = null)

Set property values to models from array

Parameters

string $property e.g. calculated_property
array $values ['id1'=>'CALCULATED for id1']
string $key_field Will default to table_primary_key

at line 125
clear_scope()

Resets the scope of this collection

at line 739
int count()

returns the number of containing models this function is called if the php function count(this_collection) is used

Return Value

int count of models

at line 1088
debug()

at line 909
void filter(mixed $callback = false)

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

Iterates over each value in the models-array passing them to the callback function. If the callback function returns true, the current value from input is returned into the result array. Array keys are preserved.

Parameters

mixed $callback If the callback function is not supplied, array_filter() will remove all the entries of input that are equal to FALSE, null or ''

Return Value

void

at line 1153
getIterator()

put your comment there.

..

at line 1084
ModelCollection get_clone()

Generates a Clone (useful for slicing an collection to lots of slices)

Return Value

ModelCollection

at line 1072
array|bool get_db_properties()

Return Value

array|bool

at line 1065
Model get_model()

Returns the Default-Model (-Type) for this Collection

Return Value

Model

at line 91
string get_model_class()

put your comment there.

..

Return Value

string ???

at line 135
array get_models()

Returns array with objects

Return Value

array

at line 254
array invoke(string $method)

Calls the passed method for each object

Parameters

string $method Method Name

Return Value

array [like pluck]

at line 144
boolean is_loaded()

Returns true if this collection has been filled

Return Value

boolean True if loaded

at line 952
Model|bool last()

Return the last element of the collection

Return Value

Model|bool

at line 814
void merge()

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array. If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended. If only one array is given and the array is numerically indexed, the keys get reindexed in a continuous way.

Return Value

void

at line 1122
bool offsetExists(mixed $offset)

put your comment there.

..

Parameters

mixed $offset

Return Value

bool

at line 1144
Model offsetGet(mixed $offset)

put your comment there.

..

Parameters

mixed $offset

Return Value

Model

at line 1110
offsetSet(mixed $offset, mixed $value)

put your comment there.

..

Parameters

mixed $offset
mixed $value

at line 1132
offsetUnset(mixed $offset)

put your comment there.

..

Parameters

mixed $offset

at line 1047
overwrite_models(ModelCollection|Model|Model[] $model_array)

This will overwrite the models-array with any value

Parameters

ModelCollection|Model|Model[] $model_array

at line 298
array([$key_field] pluck(string|string[] $property, string $key_field = null)

Returns the passed property of all objects in an array

Parameters

string|string[] $property [array ior], pass * to retrieve all properties, pass 'this' to retrieve models
string $key_field

Return Value

array([$key_field] => $property)

at line 347
array pluck_unique(mixed $property, mixed $key_field = false)

Returns the passed property of all objects in an array (unique and filtered)

Parameters

mixed $property
mixed $key_field

Return Value

array

at line 775
mixed pop()

this function returns the last value of the models-array, shortening the models-array by one element.

Will additionally produce a Warning when called on a non-array.

Return Value

mixed or NULL if models-array is empty or not an array

at line 789
int push($model1, $model2 = null)

this function treats models-array as a stack, and pushes the passed variables onto the end of array.

The length of array increases by the number of variables pushed.

Parameters

$model1
$model2

Return Value

int Count of Models after pushing-operation

at line 153
bool require_loading()

If the collection is not loaded yes the collection will use all() to be filled

Return Value

bool requires loading

at line 872
reverse(boolean $preserve_keys = false)

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

The models-array will be modified with the order of the elements reversed.

Parameters

boolean $preserve_keys

at line 29
Model search_by_id($id, $query_params = false)

Parameters

$id
$query_params

Return Value

Model

at line 29
search_by_transition_id(int $id)

Parameters

int $id

at line 840
mixed shift()

This function shifts the first value of the models-array off and returns it, shortening the array by one element and moving everything down.

All numerical array keys will be modified to start counting from zero while literal keys won't be touched.

Return Value

mixed Returns the shifted value, or NULL if models-array is empty or is not an array.

at line 944
slice(int $offset, int|bool $length = false, boolean $preserve_keys = false)

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

Parameters

int $offset If offset is non-negative, the sequence will start at that offset in the array . If offset is negative, the sequence will start that far from the end of the array .
int|bool $length If length is given and is positive, then the sequence will have that many elements in it. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array .
boolean $preserve_keys Note that array_slice() will reorder and reset the array indices by default. You can change this behaviour by setting preserve_keys to TRUE.

at line 979
sort_by(string $property, string $order_by = 'asc', int $type = XF_SORTTYPE_ALPHABETICAL)

Sorts the current Collection by given Property-Name

Parameters

string $property Field-Name of the Model-Property (e.g.: 'id', 'created_at', ...)
string $order_by sort-direction ['asc' | 'desc']
int $type which type should be sorted [XF_SORTTYPE_ALPHABETICAL(default) | XF_SORTTYPE_NUMERICAL ]

at line 275
mixed sum(string $property, string|bool $group_field = false)

Returns the sum of the passed property across all models

Parameters

string $property Property Field to sum up (e.g. price)
string|bool $group_field Optional Group Field to group sums

Return Value

mixed Returns array or value

at line 691
array|Model[] to_array(bool $raw = false)

Returns collection as array of models

Parameters

bool $raw If true calls get_properties on each model

Return Value

array|Model[]

at line 708
string to_json()

Returns collection as json of models

Return Value

string

at line 676
string to_string()

Returns collection as string

Return Value

string

at line 718
string to_xml(array|bool $property_filter = false)

Returns an XML of all model properties

Parameters

array|bool $property_filter property_filter array if given, only the properties in this array are added

Return Value

string

at line 852
mixed unshift()

This function prepends passed elements to the front of the array.

Note that the list of elements is prepended as a whole, so that the prepended elements stay in the same order. All numerical array keys will be modified to start counting from zero while literal keys won't be touched.

Return Value

mixed

at line 893
boolean usort(mixed $cmp_function)

** DESTRUCTIVE ** This will manipulate the models-list and doesn't return anything!

This function will sort the models-array by its values using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function.

Parameters

mixed $cmp_function The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

Return Value

boolean was sorting successful?