ModelSet
in package
uses
BaseTraits
Defines a ModelSet object that acts as a container for multiple Model objects. This can be used to represent a set of Model objects at once. Additionally, ModelSets can be further filtered using queries.
Table of Contents
Properties
- $model_objects : array<string|int, mixed>
Methods
- __construct() : mixed
- Creates a ModelSet object that contains multiple Model objects.
- count() : int
- Returns the number of Model objects in this ModelSet.
- delete() : ModelSet
- Deletes all Model objects within this ModelSet.
- exists() : bool
- Checks if Model objects exist in this ModelSet. This helpful when determining if an API query found matches.
- first() : Model
- Returns the first Model object in the ModelSet. This is helpful when locating the first Model object that matched a query.
- get_class_fqn() : string
- Obtains the fully qualified name of the called class.
- get_class_shortname() : string
- Obtains the shortname of the called class.
- get_classes_in_namespace() : array<string|int, mixed>
- Obtains all classes associated with this class's current namespace.
- log_error() : void
- Logs an error to the syslog.
- query() : ModelSet
- Filters the ModelSet to only include Model objects that match a specific query.
- reverse() : ModelSet
- Reverse the order of the Model objects in this ModelSet.
- sort() : ModelSet
- Sorts the Model objects in this ModelSet by a specific field and order.
- to_internal() : array<string|int, mixed>
- Runs the to_internal() method for each model object within the model set and returns them all in an array.
- to_representation() : array<string|int, mixed>
- Runs the to_representation() method for each model object within the model set and returns them all in an array.
- get_query_options() : array<string|int, mixed>
- Checks for query target options. Query target options allow for more specific queries by limiting the scope to values that match a specific filter.
- run_model_method() : array<string|int, mixed>
- Runs a specified Model object method for each model object within this ModelSet.
Properties
$model_objects
public
array<string|int, mixed>
$model_objects
An array of Model objects contained by this ModelSet.
Methods
__construct()
Creates a ModelSet object that contains multiple Model objects.
public
__construct([array<string|int, mixed> $model_objects = [] ]) : mixed
Parameters
- $model_objects : array<string|int, mixed> = []
-
An array of model objects to include in this model set
count()
Returns the number of Model objects in this ModelSet.
public
count() : int
Return values
int —The number of Model objects in this ModelSet.
delete()
Deletes all Model objects within this ModelSet.
public
delete() : ModelSet
Return values
ModelSet —The ModelSet object with all Model objects that were deleted.
exists()
Checks if Model objects exist in this ModelSet. This helpful when determining if an API query found matches.
public
exists() : bool
Return values
bool —true if Model objects exist in this ModelSet, false if they do not.
first()
Returns the first Model object in the ModelSet. This is helpful when locating the first Model object that matched a query.
public
first() : Model
Return values
Modelget_class_fqn()
Obtains the fully qualified name of the called class.
public
get_class_fqn() : string
Return values
string —The FQN for this object's class.
get_class_shortname()
Obtains the shortname of the called class.
public
get_class_shortname() : string
Return values
string —The shortname for this object's class.
get_classes_in_namespace()
Obtains all classes associated with this class's current namespace.
public
get_classes_in_namespace([bool $shortnames = false ]) : array<string|int, mixed>
Parameters
- $shortnames : bool = false
Return values
array<string|int, mixed> —An array of classes currently in this object's namespace
log_error()
Logs an error to the syslog.
public
static log_error(string $message) : void
Parameters
- $message : string
-
The error message to write to the syslog
query()
Filters the ModelSet to only include Model objects that match a specific query.
public
query([array<string|int, mixed> $query_params = [] ][, array<string|int, mixed> $excluded = [] ], mixed ...$vl_query_params) : ModelSet
Parameters
- $query_params : array<string|int, mixed> = []
-
An associative array of query targets and values. The array key will be the query target and the array value will be the query value.
- $excluded : array<string|int, mixed> = []
-
An array of field names to exclude from the query. This is helpful when query data may have extra values that you do not want to include in the query.
- $vl_query_params : mixed
-
Qyery parameters that are passed in using variable-length arguments https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list
Return values
ModelSet —The filtered ModelSet object containing only Model objects that matched the query.
reverse()
Reverse the order of the Model objects in this ModelSet.
public
reverse() : ModelSet
Return values
ModelSet —A new ModelSet object with the Model objects in reverse order.
sort()
Sorts the Model objects in this ModelSet by a specific field and order.
public
sort(string|array<string|int, mixed> $fields[, int $order = SORT_ASC ][, bool $retain_ids = false ]) : ModelSet
Parameters
- $fields : string|array<string|int, mixed>
-
The field(s) to sort the Model objects by.
- $order : int = SORT_ASC
-
The order to sort the Model objects by. This must be a PHP sort order constant.
- $retain_ids : bool = false
-
Retain the original Model object IDs when sorting.
Return values
ModelSet —A new ModelSet object with the Model objects sorted by the specified field and order.
to_internal()
Runs the to_internal() method for each model object within the model set and returns them all in an array.
public
to_internal() : array<string|int, mixed>
Return values
array<string|int, mixed> —The internal configu values of all model objects within this model set.
to_representation()
Runs the to_representation() method for each model object within the model set and returns them all in an array.
public
to_representation() : array<string|int, mixed>
Return values
array<string|int, mixed> —A serializable representation of all model objects within this model set.
get_query_options()
Checks for query target options. Query target options allow for more specific queries by limiting the scope to values that match a specific filter.
private
get_query_options(string $query_target) : array<string|int, mixed>
Parameters
- $query_target : string
-
The query target string (e.g.
field_name
,field_name__contains
)
Return values
array<string|int, mixed> —An array of query target options found in the $query_target string.
run_model_method()
Runs a specified Model object method for each model object within this ModelSet.
private
run_model_method(string $method_name[, bool $use_id_as_key = false ][, bool $reverse = false ]) : array<string|int, mixed>
Parameters
- $method_name : string
-
The name of the Model method to run for each model object in this model set.
- $use_id_as_key : bool = false
-
Use each Model object's
id
property value as the return array keys. - $reverse : bool = false
-
Reverse the order of which the model objects are processed.
Return values
array<string|int, mixed> —The return value of method call for each model object. Results are stored in the same order as the model objects were passed in during construction.