Documentation

CNewsModel extends CBaseModel
in package

Manages the data structure and verifies the correctness of the data for News Module.

Tags

Table of Contents

REGEX_BIT  = '/^[0-1]+$/'
REGEX_DATE  = '/^\\d{4}\\-\\d{2}\\-\\d{2}$/'
REGEX_DATETIME  = '/\\d{4}\\-\\d{2}\\-\\d{2}\\s{1}\\d{2}:\\d{2}[:\\d{2}]?/'
REGEX_EMAIL  = '/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+)/i'
REGEX_INDEXES  = '/[\\d,]+/'
REGEX_INT  = '/^[-]?[\\d]+$/'
REGEX_NUMBER  = '/^\\-?\\d*\\.?\\d*$/'
REGEX_PHONE  = '/^[+][0-9\\s\\.]/'
REGEX_TIME  = '/^\\d{2}:\\d{2}[:\\d{2}]?$/'
REGEX_TIMESTAMP  = '/^[\\d]{10}$/'
REGEX_UINT  = '/^[\\d]+$/'
REGEX_URL  = '/^(http|https?:\\/\\/(?:www\\.|(?!www))[^\\s\\.]+\\.[^\\s]{2,3}|www\\.[^\\s]+\\.[^\\s]{2,3})$/'
REGEX_YEAR  = '/^\\d{4}$/'
$all_tables  : array<string|int, mixed>
$auto_creation_date  : bool
$auto_user  : bool
$cache  : CCache|null
$column_list  : array<string|int, mixed>|null
$module  : string
$multi_language  : bool
$table  : string
$user  : CUser|null
__construct()  : mixed
changeDataBeforeSend()  : void
Possibly manipulate the data before it is sent for viewing
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.
checkValid()  : void
Check if the input values are valid
existsField()  : bool
Check if the field_name exists in the current DB table
existsTable()  : bool
Check if the $table exists in the current DB
getAdditionalConditions()  : string
Return a string contains all additional conditions for a GET/PUT/PATCH requests
getAllAvailableTables()  : array<string|int, mixed>
Import all table/modules avaiable
getAutoUser()  : bool
get the auto user: if true when a table contains RELATED_USER_ID value set to id of the current user
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
getFields()  : array<string|int, mixed>
Provides the list of fields with all related attributes for the requested table
getListItems()  : array<string|int, string>
Return a list of column of current table
getListItemsByAdmin()  : array<string|int, string>
Return a list of column of current table for Admin users
separateMultiLanguageTexts()  : void
Transforms a multilingual text into a separated texts for every language
setAllAvailableTables()  : void
Import all table/modules avaiable
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
setExcludedControllers()  : void
Delete all controllers derived from DB tables
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
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

Constants

REGEX_DATE

public mixed REGEX_DATE = '/^\\d{4}\\-\\d{2}\\-\\d{2}$/'
Tags

REGEX_DATETIME

public mixed REGEX_DATETIME = '/\\d{4}\\-\\d{2}\\-\\d{2}\\s{1}\\d{2}:\\d{2}[:\\d{2}]?/'
Tags

REGEX_EMAIL

public mixed REGEX_EMAIL = '/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+)/i'
Tags

REGEX_URL

public mixed REGEX_URL = '/^(http|https?:\\/\\/(?:www\\.|(?!www))[^\\s\\.]+\\.[^\\s]{2,3}|www\\.[^\\s]+\\.[^\\s]{2,3})$/'
Tags

Properties

$column_list

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

Methods

__construct()

public __construct( $table, array<string|int, array<string|int, array<string|int, string>>> $all_tables[, CUser|null $user = null ][, CCache|null $cache = null ]) : mixed
Parameters
$table :

$table current table name

$all_tables : array<string|int, array<string|int, array<string|int, string>>>

[table][colums][attributes] list of all tables of current DB with column_list list

$user : CUser|null = null

object that manages user data

$cache : CCache|null = null

object that manages cached data

Tags
Return values
mixed

changeDataBeforeSend()

Possibly manipulate the data before it is sent for viewing

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

array with data

$html_frame : string = ''

name of html frame if exists

Tags
Return values
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

Tags
Return values
void

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

Tags
Return values
void

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')

Tags
Return values
void

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

Tags
Return values
void

checkValid()

Check if the input values are valid

public final checkValid([bool $all_required = true ]) : void
Parameters
$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

Return values
void

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

Tags
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

Tags
Return values
bool

true if exists the table name in the current DB

getAdditionalConditions()

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

public getAdditionalConditions() : string
Tags
Return values
string

list of column names of current table

getAllAvailableTables()

Import all table/modules avaiable

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

list of all table/modules avaiable

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
Tags
Return values
bool

the value of current auto user

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

Tags
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

Tags
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

Tags
Return values
string

return a string contains rule and other filter conditions

getFields()

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

public final getFields() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

the list of fields with related attributes

getListItems()

Return a list of column of current table

public getListItems() : array<string|int, string>
Tags
Return values
array<string|int, string>

list of column names of current table

getListItemsByAdmin()

Return a list of column of current table for Admin users

public getListItemsByAdmin() : array<string|int, string>
Tags
Return values
array<string|int, string>

list of column names of current table

separateMultiLanguageTexts()

Transforms a multilingual text into a separated texts for every language

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

array with data

Tags
Return values
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

Tags
Return values
void

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;

Tags
Return values
void

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;

Tags
Return values
mixed

setData()

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

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

all input's parameters

Tags
Return values
void

setExcludedControllers()

Delete all controllers derived from DB tables

public setExcludedControllers([array<string|int, mixed> $excluded_controllers = [] ]) : void
Parameters
$excluded_controllers : array<string|int, mixed> = []

list of controllers derived from the DB to be excluded

Tags
Return values
void

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

Tags
Return values
void

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

Return values
void

setRequiredFloat()

Method setRequiredFloat

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

$field_name database field name

$min : float = null

minimum value accepted

$max : float = null

maximum value accepted

Tags
Return values
void

setRequiredInt()

Method setRequiredInt

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

$field_name database field name

$min : int = null

minimum value accepted

$max : int = null

maximum value accepted

Tags
Return values
void

setRequiredPattern()

Method setRequiredPattern

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

database field name

$pattern : string

regular expression pattern

$options : string = 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

Return values
void

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

Return values
void

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
Tags
Return values
bool

the value of current auto user


        

Search results