Documentation

CBaseModel extends CDB

Manages the data structure and verifies the correctness of the data.

Implementation the basic Model for all Modules.

This class defines the basis of the data model. Unlike other REST libraries, the model automatically reads the data structure from the DB and stores it. In most cases, it will not be necessary to create a template for each new form but it is still possible, for example to define a restriction on the type of input or define which data to display.

Table of Contents

Properties

$all_modules  : array<string|int, mixed>
$all_tables  : array<string|int, mixed>
$auto_creation_date  : bool
$auto_user  : bool
$available_modules  : array<string|int, mixed>
$cache  : ICache|null
$column_list  : array<string|int, mixed>|null
$connection_manager  : IConnectionManager|null
$current_module  : array<string|int, mixed>
$dbms  : IDBMS
$dbms_type  : string
$http_method  : string
$id  : int|null
$last_id  : int
$logger  : ILogger
$main_item_title  : string
$module_name  : string
$multi_language  : bool
$request  : CRequest
$response  : CResponse
$static_connection_manager  : IConnectionManager|null
$table  : string
$table_filter  : string
$table_to_modules  : array<string|int, mixed>
$user  : CUser

Methods

__construct()  : mixed
Constructor
__destruct()  : mixed
Destructor
BeginTransaction()  : void
Starts a DB transaction.
ChangeFilters()  : void
Set all conditions before read from db or delete into db
ChangeForMultilanguageValues()  : void
Change items values for multilanguage text before insert/update into db
ChangeItemValues()  : void
Change items values befor insert/update into db
ChangeStructureTable()  : void
Change any attributes of the field on OPTIONS request.
ChangeViewData()  : void
Possibly manipulate the data before it is sent for viewing
CheckValid()  : void
Check if the input values are valid
Commit()  : void
Commits the current transaction.
Connect()  : IConnectionManager
Static method to connect to database
ConnectionManager()  : IConnectionManager
Gets the connection manager instance.
ConvertDBType2BindType()  : string
Converts a generic DB data type into a driver-specific bind type.
Decrypt()  : string
Returns the DB instruction to decrypt a value.
Delete()  : bool
DeleteRecord()  : bool
Delete records from a DB table
Disconnect()  : void
Releases the resource to connect to the DB
DisconnectAll()  : void
Releases all the resources of the previously opened DBs
Encrypt()  : string
Returns the DB instruction to encrypt a value.
Execute()  : void
Executes a previously prepared statement.
ExistsField()  : bool
Check if the field_name exists in the current DB table
ExistsTable()  : bool
Check if the $table exists in the current DB
ExistsTableColumns()  : bool
Checks if a list of columns exists in a table.
GetAdditionalConditions()  : string
Return a string contains all additional conditions for a GET/PUT/PATCH requests
GetAffectedRows()  : int
Returns how many rows were affected by the last operation performed.
GetAllModules()  : array<string|int, mixed>
Returns a list of all modules, using cache.
GetAllTables()  : array<string|int, mixed>
Returns a list of all tables, using cache.
GetArrayByName()  : array<string|int, mixed>|null
Fetches a result set into a key-value array, using array_column for optimization.
GetArrayItemOfElements()  : array<string|int, mixed>|null
Given an array of records, returns a new array containing only the values of a specific field.
GetAttributesFromType()  : bool
Gets field attributes based on a DB data type.
GetAutoUser()  : bool
get the auto user: if true when a table contains RELATED_USER_ID value set to id of the current user
GetCache()  : ICache|null
Returns the cache object
GetCachedArrayByName()  : array<string|int, mixed>|null
Fetches a result set into a key-value array, using cache.
GetCachedDataTable()  : void
Fetches a full result set into an array, using cache.
GetCachedDataValue()  : string|null
Fetches a single data value from a query, using cache.
GetCachedFetchAssoc()  : array<string|int, mixed>|null
Fetches an associative array from a query, using cache.
GetCachedFetchRow()  : array<string|int, mixed>|null
Fetches an associative array from a query, using cache.
GetCachedIDsArray()  : array<string|int, mixed>
Fetches a single column from a result set into an array, using cache.
GetColumnNames()  : array<string|int, string>|null
Returns an array containing the names of all columns for the last query executed.
GetConnectionManager()  : IConnectionManager|null
GetConnectionManager( )
GetCurrentDate()  : string
Returns the current date.
GetCurrentDateTime()  : string
Returns the current date and time.
GetData()  : array<string|int, mixed>
get an Array contains all data for Read request (GET or HEAD)
GetDataTable()  : int|null
Fetches the entire result set of a query into an array.
GetDataValue()  : string|null
Returns a single value from a query result.
GetDbmsType()  : string
Get the name of DBMS used
GetDBResultAssoc()  : int
Returns the driver-specific value for an associative array fetch type.
GetDBResultBoth()  : int
Returns the driver-specific value for a fetch type that includes both associative and numeric arrays.
GetDBResultNum()  : int
Returns the driver-specific value for a numeric array fetch type.
GetDBTable()  : string
Returns the name of the current main table
GetDefaultItemOrder()  : string
Return the default item name order (the base is "id")
GetDefaultItemView()  : string|null
Set the field to display when it is a related table
GetDefaultVerseOrder()  : string
Return the default verse order ('DESC', or 'ASC'. The base is "DESC")
GetDisplayFieldFromFK()  : string
From a foreign key it gets the name of the field in the related table to display.
GetEditItems()  : array<string|int, string>
Return a list of column of current table in a Edit Mode
GetElements()  : array<string|int, mixed>
Get a contents
GetFetchArray()  : array<string|int, mixed>|null
Fetches a result row as an array (both numeric and associative).
GetFetchAssoc()  : array<string|int, mixed>|null
Fetches a result row as an associative array.
GetFetchRow()  : array<string|int, mixed>|null
Fetches a result row as a numeric array.
GetField()  : array<string|int, mixed>
Returns an array containing the attributes of a given field
GetFieldAttribute()  : string
Check if the field_name exists in the current DB table
GetFieldRule()  : string
Get a rule of field_name
GetIDsArray()  : array<string|int, mixed>
Fetches a single column from the last query result into an array.
GetItemsPerPage()  : int
Get the maximum of elements per page
GetLastDBErrorNumber()  : int
Gets any error number issued by the DB.
GetLastDBErrorString()  : string
Gets any error string issued by the DB.
GetLastID()  : int|null
Returns the ID of the last inserted item
GetNextID()  : int|null
Returns the next ID from a sequence or similar.
GetPicklistData()  : array<string|int, mixed>
Get picklist data for the current module's table (for dropdowns in forms) Returns [{id, name}, ...] respecting user permissions ((_module::tablefilter, _acl::only_owner)
GetQueryDataTable()  : int|null
Queries the DB and returns the result in a two-dimensional array.
GetQueryDataValue()  : string|null
Executes a query and fetches a single value.
GetQueryFetchAssoc()  : array<string|int, mixed>|null
Executes a query and fetches a single row as an associative array.
GetQueryFetchRow()  : array<string|int, mixed>|null
Executes a query and fetches a single row as an numeric index array.
GetQueryTable()  : CSqlComposer
Create a simple query on the current table or a left join to get the foreign key name
GetRelatedlistData()  : array<string|int, mixed>
Get related data for the current module's table (used for related table views) Returns [{id, name}, ...] respecting user permissions ((_module::tablefilter, _acl::only_owner)
GetRelatedTables()  : array<string|int, string>
Get list of tables that have a foreign key to this table (one-to-many relations)
GetStructure()  : array<string|int, mixed>
Provides the list of fields with all related attributes for the requested table
GetTableColumnNames()  : array<string|int, string>
Returns an array containing the names of all columns of a table.
GetTableStructureFilter()  : string
Get a basic conditions on select for the current main table
GetTotalColumns()  : int|bool
Returns the number of columns of a previously executed query.
GetTotalRows()  : int|bool
Reads the total number of rows from a previously executed query.
InitModel()  : void
Useful method for inheritors to inject constructor code after all its views
Insert()  : int
Make an entry in the DB
InsertRecord()  : bool
Make an entry in the DB
InsertRecordBatch()  : bool
Insert multiple records in a single batch operation
IsPicklist()  : mixed
IsRelatedlist()  : mixed
LoadAllTables()  : void
Loads the schema of all tables into an array.
Modify()  : bool
Make an update in the DB
Prepare()  : void
Prepares an SQL statement for execution.
Query()  : bool
Executes a query on the DB.
Rollback()  : void
Rolls back the current transaction.
SetAllAvailableTables()  : void
Import all table/modules avaiable
SetAllModules()  : void
Returns a list of all modules, using cache.
SetAllTables()  : array<string|int, mixed>
Returns a list of all tables, using cache.
SetAutoCommit()  : void
Sets the autocommit mode.
SetAutoCreationDate()  : void
Set the auto creation date: if true when a table contains creation_date (or equivalent) set to the current date/datetime for the name of item creation_date see CREATION_DATE definition on main config.php file
SetAutoUser()  : mixed
Set the auto user: if true when a table contains RELATED_USER_ID value set to id of the current user
SetData()  : void
Set all input's parameters before insert/update into db
SetDBColumns()  : void
Loads the schema of a table's columns into an array.
SetDBTable()  : void
Sets the name of the reference table for the instance.
SetMultiLanguage()  : void
Enables multilingual mode.
SetRequired()  : void
Method SetRequired
SetRequiredFloat()  : void
Method SetRequiredFloat
SetRequiredInt()  : void
Method SetRequiredInt
SetRequiredPattern()  : void
Method SetRequiredPattern
SetRule()  : void
Method SetRule
SetTableStructure()  : array<string|int, mixed>
Provides the list of fields with all related attributes for the requested table
SetTableStructureFilter()  : void
Set an additional conditions for all select
UpdateRecord()  : bool
Make an update in the DB
ApplyFilterConstraints()  : void
Apply filter constraints to structure fields.
FindMainItemTitle()  : string
Set the items to be presented for each single element of the current table
GetAutoCreationDate()  : bool
get the auto creation date: if true when a table contains id_creation_date (or equivalent) set to the current date/datetime for the name of item creation_date see CREATION_DATE definition on main config.php file
GetCachedData()  : mixed
Retrieves data from the cache.
GetCacheKey()  : string
Generates a unique cache key from a string.
GetConditions()  : string
Import all necessary conditions based on filters and any additional conditions
GetConditionsByFilters()  : string
Get the conditions according to the input filters
GetCurrentModule()  : mixed
GetMainItemTitle()  : string
Get the item to be presented for each single element of the current table
GetPageInfo()  : array<string|int, mixed>
GetReadDetailItems()  : array<string|int, string>
Return a list of column of current table in a ReadDetails Mode
GetReadListItems()  : array<string|int, string>
Return a list of column of current table in a Read Mode
GetRelatedItemName()  : string|null
Get the display name of a related item by its ID.
GetRelatedTableDefaultView()  : string|null
Get the default view field for a related table.
GetRelatedTablelistData()  : array<string|int, mixed>
Get related data for the current module's table (used for related table views) Returns [{id, name}, ...] respecting user permissions ((_module::tablefilter, _acl::only_owner)
GetTablenameFromItem()  : string
InvalidateRelatedCache()  : void
Invalidates the cache for a given table and its related tables.
ResolveRelatedTableNames()  : void
Resolve foreign key IDs to their display names
SetAvailableModules()  : mixed
SetAvailablePicklistModules()  : mixed
SetCachedData()  : void
Stores data in the cache.
SetCurrentModule()  : mixed
SetMainItemTitle()  : void
Set the items to be presented for each single element of the current table
SplitDataForDB()  : int
Separates the data into two arrays: value and type.

Properties

$all_modules

protected array<string|int, mixed> $all_modules = []

list of all modules with column_list list

$all_tables

protected array<string|int, mixed> $all_tables = []

list of all tables of current DB with column_list list

$auto_creation_date

protected bool $auto_creation_date = true

if true when a table contains creation_date (or equivalent) set to the current date/datetime

$auto_user

protected bool $auto_user = true

if true when a table contains RELATED_USER_ID value set to id of the current user

$available_modules

protected array<string|int, mixed> $available_modules = []

list of all modules available

$cache

protected ICache|null $cache = null

The cache instance

$column_list

protected array<string|int, mixed>|null $column_list = []

list of column of current table

$connection_manager

protected IConnectionManager|null $connection_manager = null

The connection manager instance

$current_module

protected array<string|int, mixed> $current_module = []

Current module information

$dbms

protected IDBMS $dbms

The actual DB driver instance

$dbms_type

protected string $dbms_type = ''

name of DBMS for this connection (mysql, oracle, postgresql)

$http_method

protected string $http_method = ''

current HTTP method

$id

protected int|null $id = null

current id from request

$last_id

protected int $last_id = 0

The last inserted ID

$logger

protected ILogger $logger = null

the object dedicated to track info/warning/error

$main_item_title

protected string $main_item_title = ''

list of items to view in Read

$module_name

protected string $module_name = ''

name of current module

$multi_language

protected bool $multi_language = false

this flag is true if the app is multi language

$static_connection_manager

protected static IConnectionManager|null $static_connection_manager = null

Static connection manager for backward compatibility

$table

protected string $table = ''

The default table name for operations

$table_filter

protected string $table_filter = ''

basic condition for the current table

$table_to_modules

protected array<string|int, mixed> $table_to_modules = []

mapping table name to module name

$user

protected CUser $user = null

the object dedicated to the user profilation

Methods

__construct()

Constructor

public __construct(CRequest $request, CResponse $response, CUser $user, ILogger $logger[, ICache|null $cache = null ][, IConnectionManager|null $connection_manager = null ]) : mixed
Parameters
$request : CRequest

the input object

$response : CResponse

the output object

$user : CUser

name of the default db table (it can be emtpy)

$logger : ILogger

the logger object for errors, warning, info, ...

$cache : ICache|null = null

Optional cache instance for dependency injection

$connection_manager : IConnectionManager|null = null

Optional connection manager for dependency injection

Tags
throws
Exception

if the module not exists

__destruct()

Destructor

public __destruct() : mixed

BeginTransaction()

Starts a DB transaction.

public BeginTransaction() : void

ChangeFilters()

Set all conditions before read from db or delete into db

public ChangeFilters(array<string|int, array<string|int, mixed>>|null &$filters) : void
Parameters
$filters : array<string|int, array<string|int, mixed>>|null

all input's parameters

ChangeForMultilanguageValues()

Change items values for multilanguage text before insert/update into db

public ChangeForMultilanguageValues(array<string|int, string> &$values) : void
Parameters
$values : array<string|int, string>

all $values of table to change

ChangeItemValues()

Change items values befor insert/update into db

public ChangeItemValues(array<string|int, string> &$values, string $operation) : void
Parameters
$values : array<string|int, string>

all $values of table

$operation : string

type of operation ('insert' or 'modify')

ChangeStructureTable()

Change any attributes of the field on OPTIONS request.

public ChangeStructureTable(array<string|int, array<string|int, string>> &$columns) : void

This method can change the default attributes of the table fields, for example a "select" type field can become a "hidden" type field

Parameters
$columns : array<string|int, array<string|int, string>>

array list of field properties

ChangeViewData()

Possibly manipulate the data before it is sent for viewing

public ChangeViewData(array<string|int, mixed> &$data) : void
Parameters
$data : array<string|int, mixed>

array with data

CheckValid()

Check if the input values are valid

public final CheckValid(array<string|int, mixed> &$data[, bool $all_required = true ]) : void
Parameters
$data : array<string|int, mixed>

$all items to check (popolated from the structure of DB)

$all_required : bool = true

if true check all fields of DB table according to its type

Tags
throws
Exception

if a least one field value is not valid

Commit()

Commits the current transaction.

public Commit() : void

Connect()

Static method to connect to database

public static Connect(string $dbname, string $username, string $pwd[, string|null $type = null ][, string|null $hostname = null ][, int|string|null $port = null ]) : IConnectionManager
Parameters
$dbname : string

name of the database

$username : string

database username

$pwd : string

database password

$type : string|null = null

DBMS type

$hostname : string|null = null

server hostname

$port : int|string|null = null

communication port

Tags
throws
CConnectionException

If invalid database type

Return values
IConnectionManager —

The connection manager instance

ConvertDBType2BindType()

Converts a generic DB data type into a driver-specific bind type.

public ConvertDBType2BindType(string|null $db_type) : string
Parameters
$db_type : string|null

The DB data type.

Return values
string —

The corresponding variable type for parameter binding.

Decrypt()

Returns the DB instruction to decrypt a value.

public Decrypt(string $val[, string $name = '' ]) : string
Parameters
$val : string

value or field name to decrypt

$name : string = ''

alias for the returned field

Return values
string —

DB instruction to decrypt $val

Delete()

public Delete(array<string, mixed> $items) : bool
Parameters
$items : array<string, mixed>

associative array containing FIELD_NAME => FIELD_VALUE of the table

Return values
bool —

result of the operation, true if successful

DeleteRecord()

Delete records from a DB table

public DeleteRecord(string|null $table, string $conditions, array<string|int, mixed> $conditions_values, array<string|int, mixed> $types) : bool
Parameters
$table : string|null

name of the table

$conditions : string

of the where clause

$conditions_values : array<string|int, mixed>

values present in the WHERE condition

$types : array<string|int, mixed>

of DB table fields

Return values
bool —

result of the operation, true if successful

Disconnect()

Releases the resource to connect to the DB

public static Disconnect([string|null $dbkey = null ]) : void
Parameters
$dbkey : string|null = null

key of db to disconnect (optional)

DisconnectAll()

Releases all the resources of the previously opened DBs

public static DisconnectAll() : void

Encrypt()

Returns the DB instruction to encrypt a value.

public Encrypt(string $val[, string $name = '' ]) : string
Parameters
$val : string

value or field name to be encrypted

$name : string = ''

alias for the returned field

Return values
string —

DB instruction to encrypt $val

Execute()

Executes a previously prepared statement.

public Execute([array<string|int, mixed> $bind_param_values = [] ][, array<string|int, mixed> $bind_param_types = [] ]) : void
Parameters
$bind_param_values : array<string|int, mixed> = []
$bind_param_types : array<string|int, mixed> = []

ExistsField()

Check if the field_name exists in the current DB table

public ExistsField(string $field_name) : bool
Parameters
$field_name : string

database field name

Return values
bool —

true if exists the field in the current DB

ExistsTable()

Check if the $table exists in the current DB

public ExistsTable(string $table) : bool
Parameters
$table : string

name of table to check

Return values
bool —

true if exists the table name in the current DB

ExistsTableColumns()

Checks if a list of columns exists in a table.

public ExistsTableColumns(string|null $table, array<string|int, mixed> $names) : bool
Parameters
$table : string|null

name of table

$names : array<string|int, mixed>

list of field names to check

Return values
bool —

true if all fields exist

GetAdditionalConditions()

Return a string contains all additional conditions for a GET/PUT/PATCH requests

public GetAdditionalConditions() : string
Return values
string —

list of column names of current table

GetAffectedRows()

Returns how many rows were affected by the last operation performed.

public GetAffectedRows() : int
Return values
int —

total of rows affected by the last operation

GetAllModules()

Returns a list of all modules, using cache.

public GetAllModules() : array<string|int, mixed>
Return values
array<string|int, mixed>

GetAllTables()

Returns a list of all tables, using cache.

public GetAllTables() : array<string|int, mixed>
Return values
array<string|int, mixed> —

list of all tables

GetArrayByName()

Fetches a result set into a key-value array, using array_column for optimization.

public GetArrayByName([string|int $name = 'name' ][, string|null $fieldname_value = null ]) : array<string|int, mixed>|null
Parameters
$name : string|int = 'name'

The column to use as the key.

$fieldname_value : string|null = null

The column to use as the value. If null, the rest of the row is used.

Return values
array<string|int, mixed>|null —

The resulting key-value array.

GetArrayItemOfElements()

Given an array of records, returns a new array containing only the values of a specific field.

public GetArrayItemOfElements(array<string|int, mixed> &$elements, string $fieldname) : array<string|int, mixed>|null
Parameters
$elements : array<string|int, mixed>

The source array of records.

$fieldname : string

The field name to extract.

Return values
array<string|int, mixed>|null —

An array containing the extracted values.

GetAttributesFromType()

Gets field attributes based on a DB data type.

public GetAttributesFromType(string $type, array<string|int, mixed> &$values) : bool
Parameters
$type : string

the db type to check (e.g., INT, VARCHAR)

$values : array<string|int, mixed>

container for the attributes

Return values
bool —

true if attributes were found

GetAutoUser()

get the auto user: if true when a table contains RELATED_USER_ID value set to id of the current user

public GetAutoUser() : bool
Return values
bool —

the value of current auto user

GetCache()

Returns the cache object

public GetCache() : ICache|null
Return values
ICache|null —

the cache object if exists

GetCachedArrayByName()

Fetches a result set into a key-value array, using cache.

public GetCachedArrayByName(ISqlComposer $sql[, string|int $name = 'name' ][, string|null $fieldname_value = null ]) : array<string|int, mixed>|null
Parameters
$sql : ISqlComposer

The SQL query object.

$name : string|int = 'name'

The column to use as the key.

$fieldname_value : string|null = null

The column to use as the value.

Return values
array<string|int, mixed>|null —

The resulting key-value array.

GetCachedDataTable()

Fetches a full result set into an array, using cache.

public GetCachedDataTable(mixed &$data, ISqlComposer $sql[, int|null $type = null ][, string|null $with_index = null ]) : void
Parameters
$data : mixed

The array to populate.

$sql : ISqlComposer

The SQL query object.

$type : int|null = null

The generic fetch type (IDBMS::DB_ASSOC, etc.).

$with_index : string|null = null

The field to use as an index for the result array.

GetCachedDataValue()

Fetches a single data value from a query, using cache.

public GetCachedDataValue(ISqlComposer $sql[, int|string $name_col = '0' ][, int|null $pos_row = null ]) : string|null
Parameters
$sql : ISqlComposer

The SQL query object.

$name_col : int|string = '0'

The column name or index.

$pos_row : int|null = null

The row number.

Return values
string|null —

The fetched value or null.

GetCachedFetchAssoc()

Fetches an associative array from a query, using cache.

public GetCachedFetchAssoc(ISqlComposer $sql[, int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
$sql : ISqlComposer

The SQL query object.

$pos_row : int|null = null

The row number to fetch.

Return values
array<string|int, mixed>|null —

The fetched row or null.

GetCachedFetchRow()

Fetches an associative array from a query, using cache.

public GetCachedFetchRow(ISqlComposer $sql[, int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
$sql : ISqlComposer

The SQL query object.

$pos_row : int|null = null

The row number to fetch.

Return values
array<string|int, mixed>|null —

The fetched row or null.

GetCachedIDsArray()

Fetches a single column from a result set into an array, using cache.

public GetCachedIDsArray(ISqlComposer $sql[, int|string $item = 0 ][, int|string|null $idx = null ]) : array<string|int, mixed>
Parameters
$sql : ISqlComposer

The SQL query object.

$item : int|string = 0

The column index or name to fetch.

$idx : int|string|null = null

The column index or name to use as the array key.

Return values
array<string|int, mixed> —

An array of values.

GetColumnNames()

Returns an array containing the names of all columns for the last query executed.

public GetColumnNames() : array<string|int, string>|null
Return values
array<string|int, string>|null —

the associative array of column names

GetCurrentDate()

Returns the current date.

public static GetCurrentDate() : string
Return values
string —

The current date in 'Y-m-d' format.

GetCurrentDateTime()

Returns the current date and time.

public static GetCurrentDateTime() : string
Return values
string —

The current date and time in 'Y-m-d H:i:s' format.

GetData()

get an Array contains all data for Read request (GET or HEAD)

public GetData() : array<string|int, mixed>
Return values
array<string|int, mixed>

GetDataTable()

Fetches the entire result set of a query into an array.

public GetDataTable(array<string|int, mixed> &$data[, int|null $type = null ][, string|null $with_index = null ]) : int|null
Parameters
$data : array<string|int, mixed>

array containing the records found

$type : int|null = null

the fetch type (e.g., IDBMS::DB_ASSOC)

$with_index : string|null = null

field name to use as the index of the main array

Return values
int|null —

the total of records found or null on error

GetDataValue()

Returns a single value from a query result.

public GetDataValue([int|string $name_col = '0' ][, int|null $pos_row = null ]) : string|null
Parameters
$name_col : int|string = '0'

column name or numeric index

$pos_row : int|null = null

position of the row

Return values
string|null —

value of the indicated cell, or null if it does not exist

GetDbmsType()

Get the name of DBMS used

public GetDbmsType() : string
Return values
string —

the name of DBMS used. i.e.: mysql, oracle, postgresql (the convention is all in lowercase)

GetDBResultAssoc()

Returns the driver-specific value for an associative array fetch type.

public GetDBResultAssoc() : int
Return values
int

GetDBResultBoth()

Returns the driver-specific value for a fetch type that includes both associative and numeric arrays.

public GetDBResultBoth() : int
Return values
int

GetDBResultNum()

Returns the driver-specific value for a numeric array fetch type.

public GetDBResultNum() : int
Return values
int

GetDBTable()

Returns the name of the current main table

public GetDBTable() : string
Return values
string —

name of the main reference table

GetDefaultItemOrder()

Return the default item name order (the base is "id")

public GetDefaultItemOrder() : string
Return values
string —

the default item name order

GetDefaultItemView()

Set the field to display when it is a related table

public static GetDefaultItemView() : string|null
Return values
string|null

GetDefaultVerseOrder()

Return the default verse order ('DESC', or 'ASC'. The base is "DESC")

public GetDefaultVerseOrder() : string
Return values
string —

the default item name order

GetDisplayFieldFromFK()

From a foreign key it gets the name of the field in the related table to display.

public GetDisplayFieldFromFK(string $foreign_key, string &$table_name) : string
Parameters
$foreign_key : string

table name of the external table.

$table_name : string

table name of the external table.

Return values
string —

name of the field to display from the external table

GetEditItems()

Return a list of column of current table in a Edit Mode

public GetEditItems() : array<string|int, string>
Return values
array<string|int, string> —

list of column names of current table

GetElements()

Get a contents

public GetElements(string $conditions[, array<string|int, mixed> $values = [] ][, array<string|int, mixed> $types = [] ]) : array<string|int, mixed>
Parameters
$conditions : string

conditions for select elements from the table

$values : array<string|int, mixed> = []

list of parameter for binging in the query

$types : array<string|int, mixed> = []

list of types for binging in the query

Return values
array<string|int, mixed> —

results of query or [] (emtpy array) if there is no data

GetFetchArray()

Fetches a result row as an array (both numeric and associative).

public GetFetchArray([int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
$pos_row : int|null = null

position of the row to read

Return values
array<string|int, mixed>|null —

the fetched row

GetFetchAssoc()

Fetches a result row as an associative array.

public GetFetchAssoc([int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
$pos_row : int|null = null

position of the row to read

Return values
array<string|int, mixed>|null —

the fetched row

GetFetchRow()

Fetches a result row as a numeric array.

public GetFetchRow([int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
$pos_row : int|null = null

position of the row to read

Return values
array<string|int, mixed>|null —

the fetched row

GetField()

Returns an array containing the attributes of a given field

public GetField(string $field_name) : array<string|int, mixed>
Parameters
$field_name : string

field name

Return values
array<string|int, mixed> —

an array containing the attributes of a given field

GetFieldAttribute()

Check if the field_name exists in the current DB table

public GetFieldAttribute(string $field_name, string $attr) : string
Parameters
$field_name : string

field name

$attr : string

attribute'name of field

Return values
string —

the value of attribute

GetFieldRule()

Get a rule of field_name

public GetFieldRule(string $field_name) : string
Parameters
$field_name : string

database field name

Return values
string —

return a string contains rule and other filter conditions

GetIDsArray()

Fetches a single column from the last query result into an array.

public GetIDsArray([int|string $item = 0 ][, int|string|null $idx = null ]) : array<string|int, mixed>
Parameters
$item : int|string = 0

The column index or name to fetch.

$idx : int|string|null = null

The column index or name to use as the array key.

Return values
array<string|int, mixed> —

An array of values.

GetItemsPerPage()

Get the maximum of elements per page

public GetItemsPerPage() : int
Return values
int —

The maximum of elements per page

GetLastDBErrorNumber()

Gets any error number issued by the DB.

public static GetLastDBErrorNumber() : int
Return values
int —

integer value containing the error issued by the DB

GetLastDBErrorString()

Gets any error string issued by the DB.

public static GetLastDBErrorString() : string
Return values
string —

containing the error issued by the DB

GetLastID()

Returns the ID of the last inserted item

public GetLastID() : int|null
Return values
int|null —

The ID of the last inserted element, or null on failure.

GetNextID()

Returns the next ID from a sequence or similar.

public GetNextID([string $table = '' ]) : int|null
Parameters
$table : string = ''

the name of counter associated to SEQUENCE

Return values
int|null —

the next ID of the table

GetPicklistData()

Get picklist data for the current module's table (for dropdowns in forms) Returns [{id, name}, ...] respecting user permissions ((_module::tablefilter, _acl::only_owner)

public GetPicklistData() : array<string|int, mixed>
Return values
array<string|int, mixed> —

list of items for dropdown

GetQueryDataTable()

Queries the DB and returns the result in a two-dimensional array.

public GetQueryDataTable(array<string|int, mixed> &$data, CSqlComposer $sql[, int|null $type = null ][, string|null $with_index = null ]) : int|null
Parameters
$data : array<string|int, mixed>

array containing the records found

$sql : CSqlComposer

the query to execute

$type : int|null = null

fetch type using generic constants (IDBMS::DB_ASSOC, etc.)

$with_index : string|null = null

field name to use as the index of the main array

Return values
int|null —

the total of records found or null on error

GetQueryDataValue()

Executes a query and fetches a single value.

public GetQueryDataValue(CSqlComposer $sql[, string $name_col = '0' ][, int|null $pos_row = null ]) : string|null
Parameters
$sql : CSqlComposer

The SQL query string.

$name_col : string = '0'

The column name or index.

$pos_row : int|null = null

The row number.

Return values
string|null —

The fetched value or null.

GetQueryFetchAssoc()

Executes a query and fetches a single row as an associative array.

public GetQueryFetchAssoc(CSqlComposer $sql[, int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
$sql : CSqlComposer

The SQL query string.

$pos_row : int|null = null

The row number to fetch.

Return values
array<string|int, mixed>|null —

The fetched row or null.

GetQueryFetchRow()

Executes a query and fetches a single row as an numeric index array.

public GetQueryFetchRow(CSqlComposer $sql[, int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
$sql : CSqlComposer

The SQL query string.

$pos_row : int|null = null

The row number to fetch.

Return values
array<string|int, mixed>|null —

The fetched row or null.

GetQueryTable()

Create a simple query on the current table or a left join to get the foreign key name

public GetQueryTable(string $conditions) : CSqlComposer
Parameters
$conditions : string
Return values
CSqlComposer —

an object ready to execute a query

GetRelatedlistData()

Get related data for the current module's table (used for related table views) Returns [{id, name}, ...] respecting user permissions ((_module::tablefilter, _acl::only_owner)

public GetRelatedlistData() : array<string|int, mixed>
Return values
array<string|int, mixed> —

list of items for dropdown

GetRelatedTables()

Get list of tables that have a foreign key to this table (one-to-many relations)

public GetRelatedTables() : array<string|int, string>
Return values
array<string|int, string> —

list of related table names

GetStructure()

Provides the list of fields with all related attributes for the requested table

public final GetStructure() : array<string|int, mixed>
Return values
array<string|int, mixed> —

the list of fields with related attributes

GetTableColumnNames()

Returns an array containing the names of all columns of a table.

public GetTableColumnNames(string $tablename) : array<string|int, string>
Parameters
$tablename : string

name of table

Return values
array<string|int, string> —

an array with all field names

GetTableStructureFilter()

Get a basic conditions on select for the current main table

public GetTableStructureFilter() : string
Return values
string —

the current table name relative to the modudle

GetTotalColumns()

Returns the number of columns of a previously executed query.

public GetTotalColumns() : int|bool
Return values
int|bool —

total of the columns or false on error

GetTotalRows()

Reads the total number of rows from a previously executed query.

public GetTotalRows() : int|bool
Return values
int|bool —

total number of rows or false on error

InitModel()

Useful method for inheritors to inject constructor code after all its views

public InitModel() : void

Insert()

Make an entry in the DB

public Insert(array<string, mixed> $items) : int
Parameters
$items : array<string, mixed>

associative array containing FIELD_NAME => FIELD_VALUE of the table

Return values
int —

the id of new record if the insertion has been done, null otherwise

InsertRecord()

Make an entry in the DB

public InsertRecord(string|null $table, array<string|int, mixed> $items, array<string|int, mixed> $types) : bool
Parameters
$table : string|null

name of the table

$items : array<string|int, mixed>

associative array FIELD_NAME => FIELD_VALUE

$types : array<string|int, mixed>

of DB table fields

Return values
bool —

true if the insertion has been made

InsertRecordBatch()

Insert multiple records in a single batch operation

public InsertRecordBatch(string|null $table, array<string|int, mixed> $items, array<string|int, mixed> $batch_data, array<string|int, mixed> $types) : bool
Parameters
$table : string|null

name of the table (if null uses the default table)

$items : array<string|int, mixed>

associative array with field names as keys for the first record

$batch_data : array<string|int, mixed>

array of arrays, each containing values for one record

$types : array<string|int, mixed>

list of types mapped one to one with fields

Return values
bool —

true if successful, false otherwise

LoadAllTables()

Loads the schema of all tables into an array.

public LoadAllTables(array<string|int, mixed> &$db_tables) : void
Parameters
$db_tables : array<string|int, mixed>

list of tables to be returned

Modify()

Make an update in the DB

public Modify(array<string, mixed> $items[, bool $all_params_required = false ]) : bool
Parameters
$items : array<string, mixed>

associative array containing FIELD_NAME => FIELD_ATTRIBUTES of the table

$all_params_required : bool = false

to update the data it is necessary that all the parameters of the table are present and valid

Return values
bool —

true if the insertion has been made

Prepare()

Prepares an SQL statement for execution.

public Prepare(string $sql) : void
Parameters
$sql : string

string containing the query to prepare

Query()

Executes a query on the DB.

public Query(string $sql[, array<string|int, mixed> $bind_param_values = [] ][, array<string|int, mixed> $bind_param_types = [] ]) : bool
Parameters
$sql : string

string containing the query to execute

$bind_param_values : array<string|int, mixed> = []

deferred values for the query

$bind_param_types : array<string|int, mixed> = []

DB data types

Return values
bool —

true if the query was successful

Rollback()

Rolls back the current transaction.

public Rollback() : void

SetAllAvailableTables()

Import all table/modules avaiable

public SetAllAvailableTables(array<string|int, mixed> $tables) : void
Parameters
$tables : array<string|int, mixed>

list of all table/modules avaiable

SetAllModules()

Returns a list of all modules, using cache.

public SetAllModules() : void

SetAllTables()

Returns a list of all tables, using cache.

public SetAllTables() : array<string|int, mixed>
Tags
throws
Exception

if no tables are found

Return values
array<string|int, mixed> —

list of all tables

SetAutoCommit()

Sets the autocommit mode.

public SetAutoCommit([bool $bool = true ]) : void
Parameters
$bool : bool = true

if is true the autocommit is running

SetAutoCreationDate()

Set the auto creation date: if true when a table contains creation_date (or equivalent) set to the current date/datetime for the name of item creation_date see CREATION_DATE definition on main config.php file

public SetAutoCreationDate([bool $value = true ]) : void
Parameters
$value : bool = true

the value to be set;

SetAutoUser()

Set the auto user: if true when a table contains RELATED_USER_ID value set to id of the current user

public SetAutoUser([bool $value = true ]) : mixed
Parameters
$value : bool = true

the value to be set;

SetData()

Set all input's parameters before insert/update into db

public SetData(array<string|int, mixed> &$data[, string $operation = '' ]) : void
Parameters
$data : array<string|int, mixed>

all input's parameters

$operation : string = ''

the current operation (insert, update or delete)

SetDBColumns()

Loads the schema of a table's columns into an array.

public SetDBColumns(array<string|int, mixed> &$db_cols[, string|null $table = null ]) : void
Parameters
$db_cols : array<string|int, mixed>

the results to be returned

$table : string|null = null

the table to be sampled

SetDBTable()

Sets the name of the reference table for the instance.

public SetDBTable(string $table) : void
Parameters
$table : string

The name of the main table to set.

SetMultiLanguage()

Enables multilingual mode.

public SetMultiLanguage([bool $active = false ]) : void

Leave it disabled (default) if the service is not multilingual, as it places an additional workload that would be unnecessary.

N.B.: This method was called in CBaseController than it is not necessary to call it explicitly but its declaration in the derived class is sufficient with "$active = true" as a parameter

Parameters
$active : bool = false

true if is active for this module

SetRequired()

Method SetRequired

public final SetRequired(string $field_name, bool $required[, int $min_length = null ][, int $max_length = null ]) : void
Parameters
$field_name : string

database field name

$required : bool

true is required

$min_length : int = null

minimum length of value

$max_length : int = null

maximum length of value

Tags
throws
Exception

if field_name does not match the name of a column in the current table

SetRequiredFloat()

Method SetRequiredFloat

public final SetRequiredFloat(string $field_name[, float|null $min = null ][, float|null $max = null ]) : void
Parameters
$field_name : string

$field_name database field name

$min : float|null = null
$max : float|null = null

SetRequiredInt()

Method SetRequiredInt

public final SetRequiredInt(string $field_name[, int|null $min = null ][, int|null $max = null ]) : void
Parameters
$field_name : string

$field_name database field name

$min : int|null = null

minimum value accepted

$max : int|null = null

maximum value accepted

SetRequiredPattern()

Method SetRequiredPattern

public final SetRequiredPattern(string $field_name, string $pattern[, string|null $options = null ]) : void
Parameters
$field_name : string

database field name

$pattern : string

regular expression pattern

$options : string|null = null

fixed and acceptable values separated by "|" (for example 'daily|weekly|monthly')

Tags
throws
Exception

if field_name does not match the name of a column in the current table

SetRule()

Method SetRule

public final SetRule(string $field_name, string $pattern) : void
Parameters
$field_name : string

$field_name database field name

$pattern : string

regular expression pattern

Tags
throws
Exception

if field_name does not match the name of a column in the current table

SetTableStructure()

Provides the list of fields with all related attributes for the requested table

public final SetTableStructure() : array<string|int, mixed>
Return values
array<string|int, mixed> —

the list of fields with related attributes

SetTableStructureFilter()

Set an additional conditions for all select

public SetTableStructureFilter(string $table_filter) : void
Parameters
$table_filter : string

a basic conditions on select

UpdateRecord()

Make an update in the DB

public UpdateRecord(string|null $table, string $conditions, array<string|int, mixed> $items, array<string|int, mixed> $conditions_values, array<string|int, mixed> $types) : bool
Parameters
$table : string|null

name of the table

$conditions : string

of the update

$items : array<string|int, mixed>

associative array FIELD_NAME => FIELD_VALUE

$conditions_values : array<string|int, mixed>

values of the conditions

$types : array<string|int, mixed>

of DB table fields

Return values
bool —

true if the update has been made

ApplyFilterConstraints()

Apply filter constraints to structure fields.

protected ApplyFilterConstraints(array<string, array<string, mixed>> &$structure) : void

When a field has a value set via URL filter (e.g., /insert-form/id_cmspage=1), change its html_type to 'fixed' so it displays as read-only.

Parameters
$structure : array<string, array<string, mixed>>

Reference to structure array to modify

FindMainItemTitle()

Set the items to be presented for each single element of the current table

protected FindMainItemTitle([mixed $table = null ]) : string
Parameters
$table : mixed = null

name of table where keep the item name

Return values
string —

the display name of the table element

GetAutoCreationDate()

get the auto creation date: if true when a table contains id_creation_date (or equivalent) set to the current date/datetime for the name of item creation_date see CREATION_DATE definition on main config.php file

protected GetAutoCreationDate() : bool
Return values
bool —

the value of current auto user

GetCachedData()

Retrieves data from the cache.

protected GetCachedData(string $cache_key[, string|null $table = null ][, bool $is_global = false ]) : mixed
Parameters
$cache_key : string

The key for the cache entry.

$table : string|null = null

The cache area (usually the table name).

$is_global : bool = false

Whether the cache is global or user-specific.

Return values
mixed —

The cached data or null if not found.

GetCacheKey()

Generates a unique cache key from a string.

protected GetCacheKey(string $key) : string
Parameters
$key : string

The input string.

Return values
string —

The hashed cache key.

GetConditions()

Import all necessary conditions based on filters and any additional conditions

protected GetConditions(array<string|int, mixed> &$values, array<string|int, mixed> &$types[, string $table_alias = '' ]) : string
Parameters
$values : array<string|int, mixed>

list of parameter for binging in the query

$types : array<string|int, mixed>

list of types for binging in the query

$table_alias : string = ''

alias of table, i.e.: 'a'

Return values
string —

string containing the conditions of an SQL query created with input filters and any other additional conditions

GetConditionsByFilters()

Get the conditions according to the input filters

protected GetConditionsByFilters(array<string|int, mixed> &$values, array<string|int, mixed> &$types[, string $table_alias = '' ]) : string
Parameters
$values : array<string|int, mixed>

list of parameter for binging in the query

$types : array<string|int, mixed>

list of types for binging in the query

$table_alias : string = ''

alias of table, i.e.: 'a'

Return values
string —

string containing the conditions of an SQL query created with input filters

GetCurrentModule()

protected GetCurrentModule() : mixed

GetMainItemTitle()

Get the item to be presented for each single element of the current table

protected GetMainItemTitle() : string
Return values
string

GetPageInfo()

protected GetPageInfo() : array<string|int, mixed>
Tags
Set

informations about paging

Return values
array<string|int, mixed> —

pages info

GetReadDetailItems()

Return a list of column of current table in a ReadDetails Mode

protected GetReadDetailItems() : array<string|int, string>
Return values
array<string|int, string> —

list of column names of current table in ReadDetails Mode

GetReadListItems()

Return a list of column of current table in a Read Mode

protected GetReadListItems() : array<string|int, string>
Return values
array<string|int, string> —

list of column names of current table

GetRelatedItemName()

Get the display name of a related item by its ID.

protected GetRelatedItemName(string $module, mixed $id) : string|null
Parameters
$module : string

Module name for the related table

$id : mixed

ID of the related item

Return values
string|null —

Display name or null if not found

GetRelatedTableDefaultView()

Get the default view field for a related table.

protected GetRelatedTableDefaultView(string $table) : string|null
Parameters
$table : string

Table name

Return values
string|null —

Default view field name or null

GetRelatedTablelistData()

Get related data for the current module's table (used for related table views) Returns [{id, name}, ...] respecting user permissions ((_module::tablefilter, _acl::only_owner)

protected GetRelatedTablelistData(array<string|int, mixed> &$elements) : array<string|int, mixed>
Parameters
$elements : array<string|int, mixed>
Return values
array<string|int, mixed> —

list of items

GetTablenameFromItem()

protected GetTablenameFromItem(string $item) : string
Parameters
$item : string
Return values
string

InvalidateRelatedCache()

Invalidates the cache for a given table and its related tables.

protected InvalidateRelatedCache(string|null $table) : void
Parameters
$table : string|null

The table name to invalidate. Defaults to the current table.

ResolveRelatedTableNames()

Resolve foreign key IDs to their display names

protected ResolveRelatedTableNames(array<string|int, mixed> &$data) : void

Analyzes data from GetData(), identifies all foreign key fields, retrieves the corresponding names from related tables using GetMainItemTitle() logic, and replaces the IDs with the resolved names

Parameters
$data : array<string|int, mixed>

array with data from GetData()

SetAvailableModules()

protected SetAvailableModules() : mixed

SetAvailablePicklistModules()

protected SetAvailablePicklistModules() : mixed

SetCachedData()

Stores data in the cache.

protected SetCachedData(string $cache_key, mixed $data[, string|null $table = null ][, bool $is_global = false ]) : void
Parameters
$cache_key : string

The key for the cache entry.

$data : mixed

The data to store.

$table : string|null = null

The cache area (usually the table name).

$is_global : bool = false

Whether the cache is global or user-specific.

SetCurrentModule()

protected SetCurrentModule() : mixed

SetMainItemTitle()

Set the items to be presented for each single element of the current table

protected SetMainItemTitle() : void

SplitDataForDB()

Separates the data into two arrays: value and type.

protected SplitDataForDB(array<string|int, mixed> $items, array<string|int, mixed> &$values, array<string|int, mixed> &$types) : int

It is used for inserting, modifying and deleting a record of a DB table

Parameters
$items : array<string|int, mixed>
$values : array<string|int, mixed>

list of parameter for binging in the query

$types : array<string|int, mixed>

list of types for binging in the query

Return values
int —

the id of new record if the insertion has been done, null otherwise


        
On this page

Search results