CAdminController
extends CBaseController
in package
Manages and delegates all operations relating to the Admin module.
Table of Contents
Properties
- $model : mixed
- $all_db_modules : array<string|int, mixed>|null
- $all_modules : array<string|int, mixed>
- $all_tables : array<string|int, mixed>
- $cache : ICache|null
- $connection_manager : IConnectionManager|null
- $dbms : IDBMS
- $dbms_type : string
- $http_method : string
- $last_id : int
- $logger : ILogger
- $module_name : string
- $request : CRequest
- $response : CResponse
- $static_connection_manager : IConnectionManager|null
- $table : string
- $user : CUser
Methods
- __construct() : mixed
- Constructor
- __destruct() : mixed
- Destructor
- AddItemRequired() : void
- For POST, PUT, PATCH methods add some limitations as min or max value or a specific rule with regular expression
- BeginTransaction() : void
- Starts a DB transaction.
- 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.
- 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.
- Exec() : string
- Call the appropriate method (GET,POST,PUT,PATCH,DELETE,...) e return the results
- ExecDELETE() : array<string|int, mixed>
- Manager of HTTP Method DELETE
- ExecGET() : array<string|int, mixed>|null
- Manager of HTTP Method GET (Read data)
- ExecHEAD() : array<string|int, mixed>
- Manager of HTTP Method HEAD (as GET but without body)
- ExecOPTIONS() : array<string|int, mixed>
- Manager of HTTP Method OPTIONS
- ExecPATCH() : array<string|int, mixed>
- Manager of HTTP Method PATCH (update without full data required) Update of one or more records of the table
- ExecPUT() : array<string|int, mixed>
- Manager of HTTP Method PUT (update with full data required) Update of one or more records of the table
- Execute() : void
- Executes a previously prepared statement.
- ExistsTable() : bool
- Checks if a table exists in the database.
- ExistsTableColumns() : bool
- Checks if a list of columns exists in a table.
- 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.
- 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( )
- GetControllerName() : string
- Include the Controller class more appropriated and return the fullname
- GetCurrentDate() : string
- Returns the current date.
- GetCurrentDateTime() : string
- Returns the current date and time.
- GetCurrentModel() : mixed
- Get the current Model Object (CBaseModel or sons)
- 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
- 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.
- GetIDsArray() : array<string|int, mixed>
- Fetches a single column from the last query result into an array.
- 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
- GetModelName() : string
- Include the Model class more appropriated and return the fullname
- GetModuleElement() : string
- Return the fullname of the class more appropriated
- GetNextID() : int|null
- Returns the next ID from a sequence or similar.
- 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.
- GetTableColumnNames() : array<string|int, string>
- Returns an array containing the names of all columns of a 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.
- InitController() : void
- Useful method for inheritors to inject constructor code after all its views
- InsertRecord() : bool
- Make an entry in the DB
- InsertRecordBatch() : bool
- Insert multiple records in a single batch operation
- LoadAllTables() : void
- Loads the schema of all tables into an array.
- Prepare() : void
- Prepares an SQL statement for execution.
- Query() : bool
- Executes a query on the DB.
- Rollback() : void
- Rolls back the current transaction.
- 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.
- 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.
- SetRequiredItems() : void
- For POST, PUT, PATCH methods add some limitations as min or max value or a specific rule with regular expression
- SetUser() : void
- Set a user manager object (CUser or childs)
- UpdateRecord() : bool
- Make an update in the DB
- ChangeResult() : mixed
- Change data and/or execute code before send data You can use: $this->http_method for distinguish the method used $this->request->SetMethod(string $method) for change the html output file $this->request->getAttributes() for know other specific values from url
- Delete() : array<string|int, mixed>
- Delete a record into a DB table
- DoAfterDelete() : void
- After an Delay derived classes can use this method to perform additional operations
- DoAfterInsert() : void
- After an Insert derived classes can use this method to perform additional operations
- DoAfterModify() : void
- After an Modify derived classes can use this method to perform additional operations
- DoAfterOperation() : void
- After an Insert, Modify or Delete, derived classes can use this method to perform additional operations
- ExecPOST() : array<string|int, mixed>
- Manager of HTTP Method POST (insert)
- GetCachedData() : mixed
- Retrieves data from the cache.
- GetCacheKey() : string
- Generates a unique cache key from a string.
- GetPicklist() : array<string|int, mixed>
- Get picklist data for the current module's table (used for dropdowns) URL format: /module/picklist Respects user permissions (_module::tablefilter, _acl::only_owner)
- GetRelatedlist() : array<string|int, mixed>
- Get related data for the current module's table (used for related table views) URL format: /module/relatedlist Respects user permissions (_module::tablefilter, _acl::only_owner)
- Insert() : array<string|int, mixed>
- Insert a new record into a DB table
- InvalidateRelatedCache() : void
- Invalidates the cache for a given table and its related tables.
- Modify() : array<string|int, mixed>
- Modify a record into a DB table
- SetAutoRedirect() : void
- set the redirect by method and message on results
- SetCachedData() : void
- Stores data in the cache.
Properties
$model
public
mixed
$model
The model instance (CBaseModel or derived class)
$all_db_modules
protected
array<string|int, mixed>|null
$all_db_modules
= []
List of all database modules
$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
$cache
protected
ICache|null
$cache
= null
The cache instance
$connection_manager
protected
IConnectionManager|null
$connection_manager
= null
The connection manager instance
$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
= 'GET'
HTTP method (GET, PUT, PATCH, POST, OPTIONS, HEAD, DELETE)
$last_id
protected
int
$last_id
= 0
The last inserted ID
$logger
protected
ILogger
$logger
= null
the object dedicated to track info/warning/error
$module_name
protected
string
$module_name
= ''
Name of the current module
$request
protected
CRequest
$request
= null
the object dedicated to the input
$response
protected
CResponse
$response
= null
$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
$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
__destruct()
Destructor
public
__destruct() : mixed
AddItemRequired()
For POST, PUT, PATCH methods add some limitations as min or max value or a specific rule with regular expression
public
AddItemRequired(string $name, array<string|int, mixed> $options[, string|null $table = null ]) : void
Parameters
- $name : string
-
name of item to add
- $options : array<string|int, mixed>
-
array contains min,max,rule values
- $table : string|null = null
-
table of DB or Controller (if the value is null or not declared, the table name is the table request)
Tags
BeginTransaction()
Starts a DB transaction.
public
BeginTransaction() : void
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
Return values
IConnectionManager —The connection manager instance
ConnectionManager()
Gets the connection manager instance.
public
ConnectionManager() : IConnectionManager
Tags
Return values
IConnectionManager —The connection manager
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
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
Exec()
Call the appropriate method (GET,POST,PUT,PATCH,DELETE,...) e return the results
public
Exec() : string
Tags
Return values
string —all data results
ExecDELETE()
Manager of HTTP Method DELETE
public
ExecDELETE() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —message result of delete operation
ExecGET()
Manager of HTTP Method GET (Read data)
public
ExecGET() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —results of query
ExecHEAD()
Manager of HTTP Method HEAD (as GET but without body)
public
ExecHEAD() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —result of the operation
ExecOPTIONS()
Manager of HTTP Method OPTIONS
public
ExecOPTIONS() : array<string|int, mixed>
Return values
array<string|int, mixed> —structure for specific table, or list of tables if no table specified
ExecPATCH()
Manager of HTTP Method PATCH (update without full data required) Update of one or more records of the table
public
ExecPATCH() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —message result of update operation
ExecPUT()
Manager of HTTP Method PUT (update with full data required) Update of one or more records of the table
public
ExecPUT() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —message result of update operation
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> = []
ExistsTable()
Checks if a table exists in the database.
public
ExistsTable(string $table) : bool
Parameters
- $table : string
-
name of the table
Return values
bool —true if it exists, false if it does not
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
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
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
GetConnectionManager()
GetConnectionManager( )
public
GetConnectionManager() : IConnectionManager|null
Return values
IConnectionManager|null —The Connection Manager
GetControllerName()
Include the Controller class more appropriated and return the fullname
public
static GetControllerName() : string
Return values
string —the fullname of class Controller required
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.
GetCurrentModel()
Get the current Model Object (CBaseModel or sons)
public
GetCurrentModel() : mixed
Return values
mixed —the current model (is a CBaseModel object or an his derived)
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
intGetDBResultBoth()
Returns the driver-specific value for a fetch type that includes both associative and numeric arrays.
public
GetDBResultBoth() : int
Return values
intGetDBResultNum()
Returns the driver-specific value for a numeric array fetch type.
public
GetDBResultNum() : int
Return values
intGetDBTable()
Returns the name of the current main table
public
GetDBTable() : string
Return values
string —name of the main reference table
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
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.
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.
GetModelName()
Include the Model class more appropriated and return the fullname
public
static GetModelName() : string
Return values
string —the fullname of class Model required
GetModuleElement()
Return the fullname of the class more appropriated
public
static GetModuleElement(string $class_type) : string
Parameters
- $class_type : string
-
class type (normally 'Controller' or 'Model')
Return values
string —the fullname of class required
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
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.
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
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
InitController()
Useful method for inheritors to inject constructor code after all its views
public
InitController() : void
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
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
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
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
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.
SetRequiredItems()
For POST, PUT, PATCH methods add some limitations as min or max value or a specific rule with regular expression
public
SetRequiredItems(array<string|int, mixed> $list) : void
Parameters
- $list : array<string|int, mixed>
-
array contains per each table the relative limitations of single items
Tags
SetUser()
Set a user manager object (CUser or childs)
public
SetUser(CUser $user) : void
Parameters
- $user : CUser
-
the user object
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
ChangeResult()
Change data and/or execute code before send data You can use: $this->http_method for distinguish the method used $this->request->SetMethod(string $method) for change the html output file $this->request->getAttributes() for know other specific values from url
protected
ChangeResult(array<string|int, mixed> &$result) : mixed
Parameters
- $result : array<string|int, mixed>
-
final data before sending
Delete()
Delete a record into a DB table
protected
Delete() : array<string|int, mixed>
Return values
array<string|int, mixed> —['result'=>true|false] if the operation was successful, false in all other cases
DoAfterDelete()
After an Delay derived classes can use this method to perform additional operations
protected
DoAfterDelete(int $id) : void
Parameters
- $id : int
-
id of executed delete operation
DoAfterInsert()
After an Insert derived classes can use this method to perform additional operations
protected
DoAfterInsert(int $id) : void
Parameters
- $id : int
-
the new id inserted
DoAfterModify()
After an Modify derived classes can use this method to perform additional operations
protected
DoAfterModify(int $id) : void
Parameters
- $id : int
-
id of executed modify operation
DoAfterOperation()
After an Insert, Modify or Delete, derived classes can use this method to perform additional operations
protected
DoAfterOperation(string $operation, int $id) : void
Parameters
- $operation : string
-
type of operation ('insert', 'modify' or 'delete')
- $id : int
-
id of executed operation
ExecPOST()
Manager of HTTP Method POST (insert)
protected
ExecPOST() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —message result of insert operation
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.
GetPicklist()
Get picklist data for the current module's table (used for dropdowns) URL format: /module/picklist Respects user permissions (_module::tablefilter, _acl::only_owner)
protected
GetPicklist() : array<string|int, mixed>
Return values
array<string|int, mixed> —list of items [{id, name}, ...]
GetRelatedlist()
Get related data for the current module's table (used for related table views) URL format: /module/relatedlist Respects user permissions (_module::tablefilter, _acl::only_owner)
protected
GetRelatedlist() : array<string|int, mixed>
Return values
array<string|int, mixed> —list of items [{id, name}, ...]
Insert()
Insert a new record into a DB table
protected
Insert() : array<string|int, mixed>
Return values
array<string|int, mixed> —['result'=>true|false] if the operation was successful, false in all other cases
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.
Modify()
Modify a record into a DB table
protected
Modify([bool $all_params_required = true ]) : array<string|int, mixed>
Parameters
- $all_params_required : bool = true
-
to update the data it is necessary that all the parameters of the table are present and valid
Return values
array<string|int, mixed> —['result'=>true|false] if the operation was successful, false in all other cases
SetAutoRedirect()
set the redirect by method and message on results
protected
SetAutoRedirect(string $http_method) : void
Parameters
- $http_method : string
-
type of method (GET,POST,PUT,PATCH,DELETE,...)
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.