class Model

Database Model

Properties

Core $mod
protected $model_name var string Name of this model e.g. category or document
protected $table_name var string Table name for this model
protected boolean $table_use_group_id
protected boolean $table_auto_properties
protected string $table_primary_key
protected array $model_scope_conditions
protected array $properties
protected array $properties_meta
protected array $markers
protected array $properties_null_values
static $method_exists_cache
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
boolean $loaded
boolean $saved
array $changed
array $cache_function_result
static array $_request_cache

Methods

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

No description

__construct(int|bool $id = false)

No description

mixed
__get(mixed $var)

No description

__isset($name)

No description

mixed
__set(mixed $var, mixed $value)

No description

null|string
__toString()

String Representation of this object (calls for render method)

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

_scope_by(mixed $fn, mixed $parameters)

put your comment there.

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(mixed $condition)

Adds a condition to scope the following find functions

clear_cached_functions(string|bool $function = false)

Clears the cache for all functions or a specific one

clear_properties()

No description

array
convert_array_to_conditions(array $params = array())

Convert Assoc Multidimensional Array to Model Conditional Array

int
count_all()

Returns the count of all models

string|void
debug(boolean $show_markers = false, int $mode = 0)

No description

boolean
delete()

No description

int
delete_by_TABLE_COL($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.

disable_table_group_id()

Disable the use of the group ID in all queries made

enable_table_group_id()

Enable the use of the group ID in all queries made

mixed
find(string $mode = 'all', mixed $conditions = false, mixed $query_params = false)

Find Function to find models using the passed condition

Model
find_by_TABLE_COL($COL_VALUE, $params = ['order_by'=>'COL1 ASC'])

Returns all models with a specific column value. Query params can be e.g. order_by

string
function_name_to_query(string $query, array $parameters)

Converts a find_by_* function name to SQL query.

string
get_created_at_formatted()

Return a Formatted DateTime

get_db_properties()

Returns all properties which are available as DB field (= can be used as find_by() properties)

bool|mixed
get_i18n_property(string $property)

Return the property translated property value if available

string
get_model_name()

Returns the SQL table of this model (if available)

string|bool
get_model_table_name(string|bool $table_name = false)

Returns the SQL table of this model (if available)

get_properties(bool $value_discovery = true)

No description

get_properties_meta(bool|string $field = false)

No description

get_property(string $property_id, bool $get_raw_value = false)

No description

static mixed|null
get_request_cache(string $key)

Return Cache Entry if it exists

string
get_table_name()

Returns the table name of this model.

string
get_table_primary_key()

No description

string
get_updated_at_formatted()

Return a Formatted DateTime

init(bool $auto_load = true)

Initializes the model

load()

No description

bool
load_from_db(string $table_name, array|bool $key_fields = false)

No description

populate_model_by_query(string $model_name, array|string $dbquery_result, string $population_mode = 'full', string $post_fill_function = 'update')

No description

array
process_find_query(mixed $select_field, mixed $query_params)

Execute Query of find() function. Can be modified by child class if necessary

reload_schema()

Reloads the schema of the model

bool
remove_from_db(string $table_name, array $key_fields = null)

No description

null
render()

Generic Renderer

save()

No description

int|bool
save_to_db(string $table_name, array $params = array())

No description

bool|array
schema_values(mixed $field_name)

Provides a list of all values allowed for enumerations.

array
search(string $query, array $field_list, mixed $query_params = false)

Search for passed search query in all passed fields, one match is enough

void
set_properties_from_array(array $input, array|bool $filter = false)

No description

set_property(string|array $property_id, string|bool $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.

set_render_params(mixed $params = array())

Sets parameter that will be passed to the XUI helpers

static 
set_request_cache(string $key, mixed $value)

Set Request Cache Entry

sort_down(int $steps = 1, array $params = array())

Decrease Sort Priority (Increases SORT value)

sort_up(int $steps = 1, array $params = array())

Increase Sort Priority (Decreases SORT value)

stop_temporary_group_id_overwrite()

Stops the temporary overwrite of the table_group_id

temporarily_disable_table_group_id()

Temporarily disable the use of the group ID in all queries made

temporarily_enable_table_group_id()

Temporarily enables the use of the group ID in all queries made

string
to_json()

Returns the model as JSON array

string
to_string()

Returns the model as STRING

string
to_xml(array|bool $property_filter = false, bool|DOMDocument $doc = false, DOMElement $parent_element = null)

Returns an XML of all model properties

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)

string|true
validate(array $fieldErrors)

No description

Details

at line 963
ModelCollection|Model|Model[]|int __call(string $method, array $args = array())

Parameters

string $method method-name
array $args params

Return Value

ModelCollection|Model|Model[]|int
  • Returns resource (find...) or affected rows (count..|deleted..)

at line 119
__construct(int|bool $id = false)

Parameters

int|bool $id Primary ID of the model which should be loaded

Exceptions

ReflectionException

at line 932
mixed __get(mixed $var)

Parameters

mixed $var

Return Value

mixed

at line 1570
__isset($name)

Parameters

$name

at line 945
mixed __set(mixed $var, mixed $value)

Parameters

mixed $var
mixed $value

Return Value

mixed

at line 1527
null|string __toString()

String Representation of this object (calls for render method)

Return Value

null|string

at line 998
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

Parameters

string $function method-name
array $args params

Return Value

mixed

at line 1240
protected ModelCollection _scope_by(mixed $fn, mixed $parameters)

put your comment there.

..

Parameters

mixed $fn
mixed $parameters

Return Value

ModelCollection

at line 810
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 1228
add_scope_condition(mixed $condition)

Adds a condition to scope the following find functions

Parameters

mixed $condition

at line 1017
clear_cached_functions(string|bool $function = false)

Clears the cache for all functions or a specific one

Parameters

string|bool $function

at line 486
clear_properties()

at line 1195
array convert_array_to_conditions(array $params = array())

Convert Assoc Multidimensional Array to Model Conditional Array

Parameters

array $params ['id'=>1,'type'=>'active']

Return Value

array ["id = 1","type = 'active'"]

at line 29
int count_all()

Returns the count of all models

Return Value

int

at line 796
string|void debug(boolean $show_markers = false, int $mode = 0)

Parameters

boolean $show_markers show markers as well?
int $mode (0 - print, 1 - return, 2 and 3 - Special PopUps)

Return Value

string|void

at line 331
boolean delete()

Return Value

boolean was delete successful?

at line 29
int delete_by_TABLE_COL($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.

Parameters

$COL_VALUE

Return Value

int

at line 1480
disable_table_group_id()

Disable the use of the group ID in all queries made

at line 1503
enable_table_group_id()

Enable the use of the group ID in all queries made

at line 1066
mixed find(string $mode = 'all', mixed $conditions = false, mixed $query_params = false)

Find Function to find models using the passed condition

Parameters

string $mode Find mode (all/first/count)
mixed $conditions Conditions passed as field query string (e.g. 'id=1 and name="TEST"') or as parameter array: First Element contains query, 2..n contain Parameters
mixed $query_params Further query parameters (e.g. limit, order_by, request_cache)

Return Value

mixed by_mode [ ALL: ModelCollection; FIRST: Model | boolean false on fail ]

at line 29
Model find_by_TABLE_COL($COL_VALUE, $params = ['order_by'=>'COL1 ASC'])

Returns all models with a specific column value. Query params can be e.g. order_by

Parameters

$COL_VALUE
$params

Return Value

Model

at line 1275
string function_name_to_query(string $query, array $parameters)

Converts a find_by_* function name to SQL query.

Parameters

string $query
array $parameters

Return Value

string Returns the where condition

at line 1462
string get_created_at_formatted()

Return a Formatted DateTime

Return Value

string

at line 404
get_db_properties()

Returns all properties which are available as DB field (= can be used as find_by() properties)

at line 1610
bool|mixed get_i18n_property(string $property)

Return the property translated property value if available

Parameters

string $property e.g. title_i18n

Return Value

bool|mixed

at line 278
string get_model_name()

Returns the SQL table of this model (if available)

Return Value

string Full qualified table name e.g. xmi_crm01_contact

at line 257
string|bool get_model_table_name(string|bool $table_name = false)

Returns the SQL table of this model (if available)

Parameters

string|bool $table_name Simple table without instance or system prefix

Return Value

string|bool Full qualified table name e.g. xmi_crm01_contact

at line 372
get_properties(bool $value_discovery = true)

Parameters

bool $value_discovery Retrieve all values by get_property access method

at line 393
get_properties_meta(bool|string $field = false)

Parameters

bool|string $field if given returns the meta for that field

at line 347
get_property(string $property_id, bool $get_raw_value = false)

Parameters

string $property_id Marker ID
bool $get_raw_value deactivate Marker-Function gets triggered

at line 1599
static mixed|null get_request_cache(string $key)

Return Cache Entry if it exists

Parameters

string $key Cache Key

Return Value

mixed|null

at line 140
string get_table_name()

Returns the table name of this model.

Return Value

string

at line 270
string get_table_primary_key()

Return Value

string Primary Key Field in DB

at line 1471
string get_updated_at_formatted()

Return a Formatted DateTime

Return Value

string

at line 175
init(bool $auto_load = true)

Initializes the model

Parameters

bool $auto_load If set to false the init will NOT TRIGGER load in case of a set primary key property

at line 311
load()

at line 594
protected bool load_from_db(string $table_name, array|bool $key_fields = false)

Parameters

string $table_name Table Name
array|bool $key_fields Key fields which should be used as WHERE condition

Return Value

bool

at line 826
ModelCollection|array populate_model_by_query(string $model_name, array|string $dbquery_result, string $population_mode = 'full', string $post_fill_function = 'update')

Parameters

string $model_name Model Name, eg.g. category
array|string $dbquery_result dbquery Result with one record per model OR SQL query
string $population_mode Population Mode (full or id) - If set to full all object data will be used to fill the objects, if set to id each model will be initialized with the corresponding record id as parameter
string $post_fill_function Post-Fill Function is triggered on the each model after an object has been filled with data

Return Value

ModelCollection|array empty array if none found and compatibility-mode on (xelos model_version < 1)

at line 1213
protected array process_find_query(mixed $select_field, mixed $query_params)

Execute Query of find() function. Can be modified by child class if necessary

Parameters

mixed $select_field
mixed $query_params

Return Value

array dbquery Result

at line 147
reload_schema()

Reloads the schema of the model

at line 673
protected bool remove_from_db(string $table_name, array $key_fields = null)

Parameters

string $table_name Table Name
array $key_fields Key fields which should be used as WHERE condition

Return Value

bool

at line 1553
null render()

Generic Renderer

Return Value

null

at line 288
save()

at line 503
protected int|bool save_to_db(string $table_name, array $params = array())

Parameters

string $table_name Table Name
array $params

Return Value

int|bool Integer represents ID of saved record, true for successful modifications (update, delete), false otherwise

Exceptions

DatabaseException

at line 1255
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

Parameters

mixed $field_name The name of the field to examine

Return Value

bool|array

Search for passed search query in all passed fields, one match is enough

Parameters

string $query
array $field_list
mixed $query_params

Return Value

array

at line 469
void set_properties_from_array(array $input, array|bool $filter = false)

Parameters

array $input Assoc array with field_id=>value
array|bool $filter Filter array with 1-dim field_id's, only these keys from input will be set

Return Value

void

at line 425
set_property(string|array $property_id, string|bool $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.

Parameters

string|array $property_id Marker ID (Can also be an Array)
string|bool $property_value Value
bool $no_change Value return void

at line 1543
set_render_params(mixed $params = array())

Sets parameter that will be passed to the XUI helpers

Parameters

mixed $params

at line 1583
static set_request_cache(string $key, mixed $value)

Set Request Cache Entry

Parameters

string $key
mixed $value

at line 713
sort_down(int $steps = 1, array $params = array())

Decrease Sort Priority (Increases SORT value)

Parameters

int $steps
array $params (e.g. filter, order_by)

at line 703
sort_up(int $steps = 1, array $params = array())

Increase Sort Priority (Decreases SORT value)

Parameters

int $steps
array $params (e.g. filter, order_by)

at line 1519
stop_temporary_group_id_overwrite()

Stops the temporary overwrite of the table_group_id

at line 1494
temporarily_disable_table_group_id()

Temporarily disable the use of the group ID in all queries made

at line 1511
temporarily_enable_table_group_id()

Temporarily enables the use of the group ID in all queries made

at line 1434
string to_json()

Returns the model as JSON array

Return Value

string Returns model string

at line 1445
string to_string()

Returns the model as STRING

Return Value

string Returns model as string

at line 1387
string to_xml(array|bool $property_filter = false, bool|DOMDocument $doc = false, DOMElement $parent_element = null)

Returns an XML of all model properties

Parameters

array|bool $property_filter if given, only the properties in this array are added
bool|DOMDocument $doc used from model_collection to add this model to an existing structure
DOMElement $parent_element to add this model as Child, necessary if doc is given

Return Value

string Returns formatted XML string

at line 727
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)

Parameters

mixed $id (The record ID you intend to move )
string $direction (The direction you want the record to move)
int $steps (The amount of steps you want the record to move)
array $params key 'filter' optional conditions passed as a key-value array. Key 'order_by' additional ORDER string append to ORDER BY sort

Return Value

int new Sort Value

at line 920
string|true validate(array $fieldErrors)

Parameters

array $fieldErrors Field Errors can be returned via reference as array(array('field'=>$field, 'err_msg'=>$error)) or array($field => $error)

Return Value

string|true TRUE if everything is correct, String for Error-Message