ModelCollection
class ModelCollection implements ArrayAccess, IteratorAggregate, Countable mixin ScopesTrait
Constants
| SORT_ALPHABETICAL |
|
| SORT_NUMERICAL |
|
| SORT_ASC |
|
| SORT_DESC |
|
| EVENT_AFTER_LOAD |
|
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!) |
|
| bool | $canBeScoped | ModelCollection cannot be scoped anymore if manual changes have been made |
Methods
Handle find functions
Called after cloning a collection and makes sure that model reference is cloned as well
Create new Model Array
No description
returns model found by property => value
Apply lib->format multi_format on passed property. The result will be written to ->[property]_formatted
Find Function to find models using the passed condition
Set property values to models from array
Runs the passed function batched for the passed amount of models to reduce memory issues while creating too many model objects at once This function should be called on an unloaded Collection to be most effective This method is ignoring any limits which might have been set on the scopeQuery!
Returns the number of containing models Attention: This will load all models of the collection Use $model_collection->count_all() for this case to determine count without loading all models Note: this function is called if the php function count(this_collection) is used
Return the maximum number of items in this collection, will return the count of all items in the database if the collection is a scoped collection and ignore limits set. Will return local count for manual collections
Use for debugging
DESTRUCTIVE This will manipulate the models-list and doesn't return anything!
Get first model of collection, without shifting
Prefetch and returns document index objects for all items of this collection.
foreach($collection) .
Returns a DocumentIndexCollection which is NOT loaded
No description
put your comment there.
Returns array with objects
Calls the passed method for each object
Returns true if the collection has no manual modifications yet
Returns true if this collection has been filled
Return the last element of the collection, not popping
Limit the visible articles.
DESTRUCTIVE This will manipulate the models-list and doesn't return anything!
isset($collection[0])
$collections[0] = $entry
unset($collection[0])
No description
Returns the passed property of all objects in an array
Returns the passed property. In contrast to pluck() this function does not use the loaded models but uses a SQL query to retrieve the values Attention: This returns the RAW database values
Returns the passed property of all objects in an array (unique and filtered)
this function returns the last value of the models-array, shortening the models-array by one element.
If the collection is not loaded yet the collection will use all() to be filled
Resets the loaded collection by clearing all loaded models and marking the collection as not being loaded.
DESTRUCTIVE This will manipulate the models-list and doesn't return anything!
No description
No description
No description
No description
No description
Set this ModelCollection as loaded and empty collection
Setting model manually in a collection will set the collection prefilled/not scopable
No description
This function shifts the first value of the models-array off and returns it, shortening the array by one element and moving everything down.
DESTRUCTIVE This will manipulate the models-list and doesn't return anything!
Sorts the current Collection by given Property-Name
Returns the sum of the passed property across all models
Returns collection as json of models
Returns collection as string
Returns an XML of all model properties
This function prepends passed elements to the front of the array.
No description
DESTRUCTIVE This will manipulate the models-list and doesn't return anything!
Details
at line 254
mixed
__call(mixed $method, mixed $args = array())
Handle find functions
at line 1507
__clone()
Called after cloning a collection and makes sure that model reference is cloned as well
at line 101
__construct(Model $model, array|ModelCollection $model_array = null, bool $useModelClone = true)
Create new Model Array
at line 967
__toString()
No description
at line 666
protected Model|ModelCollection|null
_search_by(string $query, array|bool $parameters = false, bool $return_single = true)
returns model found by property => value
at line 954
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
at line 371
ModelCollection
all(array $args = array())
Find Function to find models using the passed condition
at line 1049
void
append(Model $model)
Adds an Object to the models-array.
It will be appended after the last position of array
at line 631
attach(string $property, array $values, string $key_field = null)
Set property values to models from array
at line 483
batchProcess(int $batchSize, callable $callback)
Runs the passed function batched for the passed amount of models to reduce memory issues while creating too many model objects at once This function should be called on an unloaded Collection to be most effective This method is ignoring any limits which might have been set on the scopeQuery!
at line 1028
int
count()
Returns the number of containing models Attention: This will load all models of the collection Use $model_collection->count_all() for this case to determine count without loading all models Note: this function is called if the php function count(this_collection) is used
at line 1543
int
countAll()
Return the maximum number of items in this collection, will return the count of all items in the database if the collection is a scoped collection and ignore limits set. Will return local count for manual collections
at line 1555
int
count_all()
deprecated
deprecated
No description
at line 1416
array
debug()
Use for debugging
at line 1195
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.
at line 1260
Model|null
first()
Get first model of collection, without shifting
at line 195
DocumentIndexCollection
getDocumentIndexes()
Prefetch and returns document index objects for all items of this collection.
at line 1492
T>
getIterator()
foreach($collection) .
..
at line 219
DocumentIndexCollection
getRelatedDocumentIndexCollection()
Returns a DocumentIndexCollection which is NOT loaded
at line 1404
array|bool
get_db_properties()
No description
at line 1397
Model
get_model()
Returns the Default-Model (-Type) for this Collection
at line 120
string
get_model_class()
put your comment there.
..
at line 128
array|Model[]
get_models()
Returns array with objects
at line 460
array
invoke(string $method)
| internal | param mixed $args Additional Parameters |
Calls the passed method for each object
at line 1535
bool
isScopeable()
Returns true if the collection has no manual modifications yet
at line 136
bool
is_loaded()
Returns true if this collection has been filled
at line 1251
Model|null
last()
Return the last element of the collection, not popping
at line 1273
final ModelCollection
limit(int $limit, int $offset = 0)
Limit the visible articles.
at line 1096
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.
at line 1456
bool
offsetExists(mixed $offset)
isset($collection[0])
at line 1480
Model
offsetGet(mixed $offset)
$collection[0]
at line 1439
offsetSet(mixed $offset, mixed $value)
$collections[0] = $entry
at line 1467
offsetUnset(mixed $offset)
unset($collection[0])
at line 1289
final ModelCollection
orderBy(string $field, string $sortDirection = ModelCollection::SORT_ASC)
No description
at line 543
pluck(string|string[] $property, string $key_field = null)
Returns the passed property of all objects in an array
at line 612
array
pluckWithScopeQuery(string $property, string|null $key_field = null)
Returns the passed property. In contrast to pluck() this function does not use the loaded models but uses a SQL query to retrieve the values Attention: This returns the RAW database values
at line 594
array
pluck_unique(mixed $property, mixed $key_field = false)
Returns the passed property of all objects in an array (unique and filtered)
at line 1062
Model|null
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.
at line 1075
int
push(Model ...$models)
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.
at line 182
bool
require_loading()
If the collection is not loaded yet the collection will use all() to be filled
at line 1214
reset()
Resets the loaded collection by clearing all loaded models and marking the collection as not being loaded.
Will not reset scope.
at line 1157
reverse(bool $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.
at line 426
ModelCollection
save(bool $silent = false)
No description
at line 27
ModelCollection
scope_by_COL(mixed $value)
No description
at line 27
Model[]
search_all_by_id(mixed $id, mixed $query_params)
No description
at line 27
Model|null
search_by_id(mixed $id, mixed $query_params)
No description
at line 1526
ModelCollection
setCanBeScoped(bool $canBeScoped = true)
No description
at line 171
ModelCollection
setEmpty()
Set this ModelCollection as loaded and empty collection
at line 148
ModelCollection
setModels(Model[]|ModelCollection $models)
Setting model manually in a collection will set the collection prefilled/not scopable
at line 408
ModelCollection
setProperty(string $key, mixed $value)
No description
at line 1123
Model|null
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.
at line 1241
slice(int $offset, int|bool $length = false, bool $preserve_keys = false)
deprecated
deprecated
DESTRUCTIVE This will manipulate the models-list and doesn't return anything!
at line 1340
ModelCollection
sortByQuery(Query $query = null)
Mimics the SQL sorting on the ModelCollection
at line 1322
ModelCollection
sort_by(string $property, string $order_by = 'asc')
deprecated
deprecated
Sorts the current Collection by given Property-Name
at line 520
mixed
sum(string $property, string|bool $group_field = false)
Returns the sum of the passed property across all models
at line 978
array|Model[]
to_array(bool $raw = false)
Returns collection as array of models
at line 995
string
to_json()
Returns collection as json of models
at line 963
string
to_string()
Returns collection as string
at line 1005
string
to_xml(array|bool $property_filter = false)
Returns an XML of all model properties
at line 1136
int
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.
at line 443
ModelCollection
updateDocumentIndexes()
No description
at line 1179
bool
usort(callable $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.