Model
class Model
Database Model
Traits
Constants
| EVENT_MODEL_AFTER_SAVE |
|
| EVENT_MODEL_BEFORE_SAVE |
|
| EVENT_MODEL_BEFORE_DELETE |
|
| EVENT_MODEL_AFTER_DELETE |
|
| FIELD_IS_NULL |
$this->find_by_field(Model::IS_NULL) |
Properties
| Core|null | $mod | ||
| protected string|null | $model_name | ||
| protected string|null | $table_name | ||
| protected bool | $table_use_group_id | ||
| protected bool | $table_auto_properties | ||
| protected string | $table_primary_key | ||
| protected array | $table_primary_compound_key | ||
| protected array | $properties | ||
| protected array | $properties_meta | ||
| protected array | $markers | ||
| bool|string | $class_name | ||
| string | $render_type | ||
| protected int | $model_version | Hint your model version, this parameter might affect certain outcomes and behaviours This version string is added for backwards compatibility |
|
| protected string | $model_default_render_xui | Defines a XUI helper which can be used to display this model in the render() function e.g. use 'thread' to use this xui helper "XELOS\Modules\Forum\UI\Thread" of the models parent module |
|
| protected array | $render_params | Parameters that will be consigned to the XUI helper |
|
| static string | $find_by_separators | ||
| bool | $loaded | ||
| bool | $saved | ||
| protected array | $changed | ||
| array | $cache_function_result | ||
| static array | $_request_cache |
Methods
No description
Magic Function Object Cloning Make sure object references are cleaned up as each object requires a clean and separate reference
No description
No description
No description
String Representation of this object (calls for render method)
Calls the passed function only if it is not cached yet, otherwise the previous cached result will be returned
Global named scope scopeAll to use on models to return an unscoped unloaded collection
Called for scopeby Magic Function Creates a new ModelCollection and applies the passed scope
Called for scope_ Magic Function Creates a new ModelCollection and applies the passed custom scope function
Apply lib->format multi_format on passed property. The result will be written to ->[property]_formatted
Adds a condition to scope the following find functions
Return all models
Clears the cache for all functions or a specific one
No description
No description
Returns the count of all models with the specific column value
No description
No description
on the desired collection.
Disable the use of the group ID in all queries made
Enable the use of the group ID in all queries made
Find Function to find models using the passed condition
Returns loaded ModelCollection
Returns all models with a specific column value. Query params can be e.g. order_by
Converts a findby* function name to SQL query.
Return properties which have been changed after model was initialized/loaded We know these values have been changed locally, but these changes are NOT necessarily reflecting the DB diff
No description
Get DB Schema if available
Returns a list of all property name variants for all languages, e.g. "title_i18n" -> "title_i18n, title_DE_DE, title_EN_EN"
Gets an I18nToken for a model property (e.g. title_i18n)
Return a new unscoped model collection for further processing
Get the primary id (post_id) for this model
Return properties and markers
Returns the Query object which is being used for building the query The function creates a new Query object if required to enable lazy loading
Return properties which have been touched/set after model was initialized/loaded We know these values have been set, but they might not have changed
Return a Formatted DateTime
Returns all properties which are available as DB field (= can be used as find_by() properties) with its currently known raw value Please note that smartTimeFields (updated_at, created_at) are not converted to mysql-date format
Return the property translated property value if available
Returns the SQL table of this model (if available)
Returns the SQL table of this model (if available)
Returns the complete properties array
No description
No description
Return Cache Entry if it exists
Returns the table name of this model.
No description
Return a Formatted DateTime
No description
Does this model represent an existing database record? (can be updated)
Returns true if at least one property is marked as changed
Initializes the model
No description
No description
No description
Registers the passed scope as default scope A default scope is present when the model is being loaded and can be removed using the unscope() function if required The passed scope must be defined in a scope[SCOPE_NAME] function e.g. scopeGroupId
Reloads the schema of the model
No description
Generic Renderer
No description
No description
Provides a list of all values allowed for enumerations.
No description
Returns unloaded ModelCollection
No description
No description
Set a Property. If $property_id is an array and $property_value is false, set_property is called for each element in the array with the array key and value as params.
Sets parameter that will be passed to the XUI helpers
Set Request Cache Entry
Sort this element to a specific position
Decrease Sort Priority (Increases SORT value)
Increase Sort Priority (Decreases SORT value)
Stops the temporary overwrite of the table_group_id
Temporarily disable the use of the group ID in all queries made
Returns the model as JSON array
Returns the model as STRING
Returns an XML of all model properties
No description
Returns an unscoped Collection
Update the sort property for a given table (Move a record up/down)
No description
Details
at line 1117
ModelCollection|Model|Model[]|int
__call(string $method, array $args = array())
No description
at line 1684
__clone()
Magic Function Object Cloning Make sure object references are cleaned up as each object requires a clean and separate reference
at line 146
__construct(int|bool $id = false)
No description
at line 1093
mixed
__get(mixed $var)
No description
at line 1743
__isset($name)
No description
at line 1105
Model
__set(mixed $var, mixed $value)
No description
at line 1695
string
__toString()
String Representation of this object (calls for render method)
at line 1155
mixed
_call_cached_function(string $function, array $args)
Calls the passed function only if it is not cached yet, otherwise the previous cached result will be returned
in
ScopesTrait at line 100
Query
_scopeAll(Query $Query)
Global named scope scopeAll to use on models to return an unscoped unloaded collection
in
ScopesTrait at line 111
Query
_scopeDefault(Query $Query)
Load default scopes
in
ScopesTrait at line 143
protected ModelCollection
_scope_by(string $fn, array $parameters)
Called for scopeby Magic Function Creates a new ModelCollection and applies the passed scope
in
ScopesTrait at line 159
protected ModelCollection
_scope_custom(string $scopeName, Query|null $Query = null)
Called for scope_ Magic Function Creates a new ModelCollection and applies the passed custom scope function
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
in
ScopesTrait at line 34
ModelCollection
add_scope_condition(Condition|ConditionGroup|Query|string $new_condition)
Adds a condition to scope the following find functions
at line 40
Model[]
all(mixed $params = ['order_by'=>'COL1)
Return all models
at line 1174
clear_cached_functions(string|bool $function = false)
Clears the cache for all functions or a specific one
at line 616
clear_properties()
No description
at line 40
int
count_all() $eturns the count of all models, see $this->find('count')
No description
at line 40
int
count_by_TABLE_COL_and_TABLE_COL2(mixed $COL1_VALUE, mixed $COL2_VALUE)
Returns the count of all models with the specific column value
at line 939
string|void
debug(bool $show_markers = false, int $mode = 0)
No description
at line 410
bool
delete()
No description
at line 40
int
delete_by_TABLE_COL(mixed $COL_VALUE) Delete rows specified by condition and returns the affected rows. NOTE: This does not trigger a delete() function of the model. If required use pluck('delete')
on the desired collection.
at line 1642
void
disable_table_group_id()
Disable the use of the group ID in all queries made
at line 1667
void
enable_table_group_id()
Enable the use of the group ID in all queries made
at line 1218
ModelCollection|Model|int|null
find(string $mode = 'all', Condition|ConditionGroup|Query|string|array $conditions = false, array|null $query_params = null)
Find Function to find models using the passed condition
at line 40
ModelCollection|Model[]
find_all_by_TABLE_COL_and_TABLE_COL2($COL1_VALUE, $COL2_VALUE, $params=['order_by'=>'COL1, 5]] $)
Returns loaded ModelCollection
at line 40
Model
find_by_TABLE_COL(mixed $COL_VALUE, mixed $params = ['order_by'=>'COL1)
Returns all models with a specific column value. Query params can be e.g. order_by
at line 1402
protected Query
functionNameToQuery(string $query, array $parameters)
Converts a findby* function name to SQL query.
at line 1857
array
getChangedProperties(bool $returnOldValues = false)
Return properties which have been changed after model was initialized/loaded We know these values have been changed locally, but these changes are NOT necessarily reflecting the DB diff
at line 970
ModelCollection
getCollectionByQuery(string $model_name, array|string $dbquery_result, string $population_mode = 'full', string $post_fill_function = 'update')
No description
at line 191
array
getDBSchema(string $field = null)
Get DB Schema if available
at line 1806
string[]
getI18nPropertyVariants($propertyName, $localeAsKey = false)
Returns a list of all property name variants for all languages, e.g. "title_i18n" -> "title_i18n, title_DE_DE, title_EN_EN"
at line 1914
I18nTokenHelper
getI18nTokenForProperty(string $i18nProperty, int|null $limitString = null)
Gets an I18nToken for a model property (e.g. title_i18n)
at line 1189
ModelCollection
getModelCollection()
Return a new unscoped model collection for further processing
at line 334
int|null
getPrimaryKeyValue()
Get the primary id (post_id) for this model
at line 492
array
getPropertyMarkers(bool $value_discovery = true)
Return properties and markers
in
ScopesTrait at line 217
Query
getScopeQuery(bool $applyDefaultScopes = true)
Returns the Query object which is being used for building the query The function creates a new Query object if required to enable lazy loading
at line 1827
array
getTouchedProperties(bool $returnOldValues = false)
Return properties which have been touched/set after model was initialized/loaded We know these values have been set, but they might not have changed
at line 1611
string
get_created_at_formatted()
Return a Formatted DateTime
at line 520
array
get_db_properties()
Returns all properties which are available as DB field (= can be used as find_by() properties) with its currently known raw value Please note that smartTimeFields (updated_at, created_at) are not converted to mysql-date format
at line 1784
bool|mixed
get_i18n_property(string $property, string $force_language = false)
Return the property translated property value if available
at line 351
string|null
get_model_name()
Returns the SQL table of this model (if available)
at line 312
string|bool
get_model_table_name(string $table_name = null)
Returns the SQL table of this model (if available)
at line 474
array
get_properties(bool $value_discovery = true)
Returns the complete properties array
at line 508
array
get_properties_meta(?string $field = null)
No description
at line 434
mixed
get_property(string|null $property_id, bool $get_raw_value = false)
No description
at line 1772
static mixed|null
get_request_cache(string $key)
Return Cache Entry if it exists
at line 303
string|null
get_table_name()
Returns the table name of this model.
at line 325
string|null
get_table_primary_key()
No description
at line 1620
string
get_updated_at_formatted()
Return a Formatted DateTime
at line 1868
bool
hasChangedProperties()
No description
at line 807
bool
hasExistingDatabaseRecord()
Does this model represent an existing database record? (can be updated)
at line 1835
bool
hasTouchedProperties()
Returns true if at least one property is marked as changed
at line 210
init(bool $auto_load = true)
Initializes the model
at line 390
load()
No description
at line 837
protected bool
load_from_db(string $table_name = null, array $key_fields = [])
No description
at line 1062
ModelCollection|Model[]
populate_model_by_query(string $model_name, array|string $dbquery_result, string $population_mode = 'full', string $post_fill_function = 'update')
deprecated
deprecated
No description
in
ScopesTrait at line 127
protected void
registerDefaultScope($scopeName)
Registers the passed scope as default scope A default scope is present when the model is being loaded and can be removed using the unscope() function if required The passed scope must be defined in a scope[SCOPE_NAME] function e.g. scopeGroupId
at line 161
reload_schema()
Reloads the schema of the model
at line 904
protected bool
remove_from_db(string $table_name, array $key_fields = null)
No description
at line 1726
string|null
render()
Generic Renderer
in
ScopesTrait at line 231
void
resetScopeQuery()
Reset Scope to null
at line 359
int|bool
save()
No description
at line 633
protected int|bool
save_to_db(string $table_name, array $params = array())
No description
at line 1381
bool|array
schema_values(mixed $field_name)
Provides a list of all values allowed for enumerations.
Returns FALSE if the field in question does not exist Returns TRUE for non enum fields Returns an array for enum fields with all available values
in
ScopesTrait at line 81
ModelCollection
scope(string $scopeName, Query|null $scopeQuery = null)
No description
in
ScopesTrait at line 16
ModelCollection
scopeAll()
No description
at line 40
Model[]
scope_by_TABLE_COL_and_TABLE_COL2(mixed $COL1_VALUE, mixed $COL2_VALUE)
Returns unloaded ModelCollection
in
ScopesTrait at line 16
ModelCollection
scope_by_id(int|array $id)
No description
at line 40
void
self() $this find_by_id($id)
No description
in
ScopesTrait at line 88
void
setModelCollectionReference(ModelCollection $modelCollectionReference)
No description
at line 599
void
set_properties_from_array(array $input, array|bool $filter = false)
No description
at line 540
set_property(string|array $property_id, mixed $property_value = false, bool $no_change = false)
Set a Property. If $property_id is an array and $property_value is false, set_property is called for each element in the array with the array key and value as params.
at line 1716
set_render_params(mixed $params = array())
Sets parameter that will be passed to the XUI helpers
at line 1756
static
set_request_cache(string $key, mixed $value)
Set Request Cache Entry
in
SortTrait at line 116
void
sortMoveTo(int $id, int $sortTo, array|null $conditions = [])
Sort this element to a specific position
in
SortTrait at line 28
sort_down(int $steps = 1, $params = array())
Decrease Sort Priority (Increases SORT value)
in
SortTrait at line 17
sort_up(int $steps = 1, $params = array())
Increase Sort Priority (Decreases SORT value)
at line 1675
stop_temporary_group_id_overwrite()
Stops the temporary overwrite of the table_group_id
at line 1657
void
temporarily_disable_table_group_id()
Temporarily disable the use of the group ID in all queries made
at line 1583
string
to_json()
Returns the model as JSON array
at line 1594
string
to_string()
Returns the model as STRING
at line 1536
string
to_xml(array|bool $property_filter = false, bool|DOMDocument $doc = false, DOMElement $parent_element = null)
Returns an XML of all model properties
at line 1843
void
touchProperty($propertyName)
No description
in
ScopesTrait at line 56
ModelCollection
unscope(string $scopeName = null, Query|null $scopeQuery = null)
Returns an unscoped Collection
in
SortTrait at line 43
protected int
update_sort(mixed $id = false, string $direction = 'up', int $steps = 1, array $params = array())
Update the sort property for a given table (Move a record up/down)
at line 1081
string|true
validate(array $fieldErrors)
No description