Member
extends BaseModel
in package
implements
Authable
Default member class.
Table of Contents
Interfaces
Constants
Properties
- $ai_field : string
- Autoincrement field
- $db : mixed
- $deletedField : string
- field to store deletion date.
- $except_fields : string
- Fields excluded from query, comma separated without space
- $only_fields : string
- Only retrieve these fields, comma separated without space
- $postCreate : closure|null
- function to execute after create record
- $postDelete : closure|null
- function to execute after delete record
- $postRetrieve : closure|null
- Function to modify record after retrieved, e.g. to add thumbnail property
- $postUpdate : closure|null
- function to execute after update record
- $postView : closure|null
- Do something after retrieving 1 record, usually increase view
- $preCreate : closure|null
- function to execute before create record
- $preDelete : closure|null
- function to execute before delete record
- $preProcess : closure|null
- Process record before validation, usually for data cleaning
- $preUpdate : closure|null
- function to execute before update record
- $softDelete : bool
- If true, instead of deleting record, mark it with deletion date.
- $validation : array<string|int, mixed>
- Validation rules with Rakit\Validation
- $dbprefix : string
- Table prefix in database, e.g. *ff_* .
- $keys : string
- PK
Methods
- __construct() : mixed
- BaseModel class should be created with m() function, not from new object.
- authenticate() : array<string|int, mixed>
- The function authenticate() checks if a user with a given token exists, is active, and returns user information if authenticated.
- codeValue() : null|string
- code-value pair.
- copyExcept() : void
- Copy data exluding certain fields.
- copyOnly() : void
- Save data only for certain fields.
- erase() : void
- Delete record by key.
- fieldFilter() : array<string|int, mixed>
- Get records filter by field.
- FSQL() : array<string|int, mixed>
- Flat SQL array result. The order of the field is important.
- FSQL1() : string
- Single value SQL result.
- FSQLC() : array<string|int, mixed>
- Flat SQL array result Column.
- FSQLR() : array<string|int, mixed>
- Flat SQL array result Row.
- getKey() : string
- If $value is exists in $field, return id.
- getValue() : string
- Get current value of record.
- lastInsertId() : int
- Last insert ID.
- login() : array<string|int, mixed>|null
- Login
- page() : array<string|int, mixed>
- Paging function.
- pk() : array<string|int, mixed>
- Primary key.
- pkValues() : array<string|int, mixed>
- Return values of primary keys.
- profile() : array<string|int, mixed>|null
- retrieve() : array<string|int, mixed>|false
- Retrieve record by keys value.
- saveFromData() : void
- Save data to database.
- saveFromRequest() : void
- Save variables from Request to database.
- softdeleteCond() : string
- Return SQL condition for softdelete.
- SQL() : mixed
- Execute SQL, if select operation return result in associative array.
- SQLBI() : void
- Bulk Insert.
- SQLBU() : void
- Bulk Update, only single pk is allowed.
- SQLR() : array<string|int, mixed>
- Execute SQL, return first row from result.
- tableName() : string
- Returns the table name.
- unique() : bool
- Check if value is unique.
- validate() : Validation
- existsInTable() : object
- RakitVal rule, $value exists in $table.
- inexistsInTable() : object
- RakitVal rule, $value inexists in $table.
- uniqueRule() : object
- unique rule for RakitVal, checking if a $value is unique in $field.
Constants
ACTIVE
public
mixed
ACTIVE
= 1
INACTIVE
public
mixed
INACTIVE
= 0
REG_ADD
public
mixed
REG_ADD
= '/add|create/'
REG_DEL
public
mixed
REG_DEL
= '/del|remove/'
REG_EDIT
public
mixed
REG_EDIT
= '/edit/'
Properties
$ai_field
Autoincrement field
public
string
$ai_field
= ""
$db
public
mixed
$db
= null
$deletedField
field to store deletion date.
public
string
$deletedField
= ""
$except_fields
Fields excluded from query, comma separated without space
public
string
$except_fields
= ""
$only_fields
Only retrieve these fields, comma separated without space
public
string
$only_fields
= ""
$postCreate
function to execute after create record
public
closure|null
$postCreate
= null
$postDelete
function to execute after delete record
public
closure|null
$postDelete
= null
$postRetrieve
Function to modify record after retrieved, e.g. to add thumbnail property
public
closure|null
$postRetrieve
= null
$postUpdate
function to execute after update record
public
closure|null
$postUpdate
= null
$postView
Do something after retrieving 1 record, usually increase view
public
closure|null
$postView
= null
$preCreate
function to execute before create record
public
closure|null
$preCreate
= null
$preDelete
function to execute before delete record
public
closure|null
$preDelete
= null
$preProcess
Process record before validation, usually for data cleaning
public
closure|null
$preProcess
= null
$preUpdate
function to execute before update record
public
closure|null
$preUpdate
= null
$softDelete
If true, instead of deleting record, mark it with deletion date.
public
bool
$softDelete
= false
$validation
Validation rules with Rakit\Validation
public
array<string|int, mixed>
$validation
= []
$dbprefix
Table prefix in database, e.g. *ff_* .
protected
string
$dbprefix
= ""
$keys
PK
protected
string
$keys
= ""
Methods
__construct()
BaseModel class should be created with m() function, not from new object.
public
__construct(Db $db) : mixed
Parameters
- $db : Db
authenticate()
The function authenticate() checks if a user with a given token exists, is active, and returns user information if authenticated.
public
authenticate(mixed $token) : array<string|int, mixed>
The function checks if a user with the provided token exists in the database. If the user is found and is active, it retrieves user information such as username, fullname, role, admin status, permissions, and user
Parameters
- $token : mixed
Return values
array<string|int, mixed> —An array is being returned. If the user is authenticated successfully, the array will contain user information such as username, fullname, role, admin status, permissions, and user. If error, return array contains error_msg.
codeValue()
code-value pair.
public
codeValue(string $codeField, string $valueField[, string|bool $blank = true ][, string $filter = "" ]) : null|string
Parameters
- $codeField : string
- $valueField : string
- $blank : string|bool = true
- $filter : string = ""
Return values
null|stringcopyExcept()
Copy data exluding certain fields.
public
copyExcept(string $afields[, string|array<string|int, mixed> $data = 'REQUEST' ]) : void
Parameters
- $afields : string
- $data : string|array<string|int, mixed> = 'REQUEST'
copyOnly()
Save data only for certain fields.
public
copyOnly(string $afields[, string|array<string|int, mixed> $data = 'REQUEST' ]) : void
Parameters
- $afields : string
-
fields to include
- $data : string|array<string|int, mixed> = 'REQUEST'
-
data taken from
erase()
Delete record by key.
public
erase([mixed $filter = NULL ][, mixed $quick = TRUE ]) : void
Parameters
- $filter : mixed = NULL
- $quick : mixed = TRUE
fieldFilter()
Get records filter by field.
public
fieldFilter(string $field, string|int $value, int $limit[, string $order = "" ]) : array<string|int, mixed>
Parameters
- $field : string
- $value : string|int
- $limit : int
- $order : string = ""
Return values
array<string|int, mixed>FSQL()
Flat SQL array result. The order of the field is important.
public
FSQL() : array<string|int, mixed>
Return values
array<string|int, mixed>FSQL1()
Single value SQL result.
public
FSQL1() : string
Return values
string —value of the query with 1 row, 1 column (e.g. SELECT COUNT(1))
FSQLC()
Flat SQL array result Column.
public
FSQLC() : array<string|int, mixed>
Return values
array<string|int, mixed>FSQLR()
Flat SQL array result Row.
public
FSQLR() : array<string|int, mixed>
Return values
array<string|int, mixed> —result that only needed only the first record
getKey()
If $value is exists in $field, return id.
public
getKey(string $field, string|int $value) : string
Parameters
- $field : string
- $value : string|int
Return values
stringgetValue()
Get current value of record.
public
getValue(string $field, string $keyValue) : string
Parameters
- $field : string
-
field value to return
- $keyValue : string
-
value of the key/id
Return values
stringlastInsertId()
Last insert ID.
public
lastInsertId() : int
Return values
intlogin()
Login
public
login(string $login, string $pass) : array<string|int, mixed>|null
Parameters
- $login : string
- $pass : string
Return values
array<string|int, mixed>|nullpage()
Paging function.
public
page(int $pos, int $size[, string $queryFields = "*" ][, string $order = "" ][, string $cond = "" ]) : array<string|int, mixed>
Parameters
- $pos : int
- $size : int
- $queryFields : string = "*"
- $order : string = ""
- $cond : string = ""
Return values
array<string|int, mixed>pk()
Primary key.
public
pk() : array<string|int, mixed>
Return values
array<string|int, mixed>pkValues()
Return values of primary keys.
public
pkValues() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of values corresponding to the primary key fields of the object.
profile()
public
profile() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullretrieve()
Retrieve record by keys value.
public
retrieve(array<string|int, mixed> $key_values) : array<string|int, mixed>|false
Parameters
- $key_values : array<string|int, mixed>
Return values
array<string|int, mixed>|falsesaveFromData()
Save data to database.
public
saveFromData(array<string|int, mixed>|string $data) : void
Parameters
- $data : array<string|int, mixed>|string
-
array or HIVE variable (e.g REQUEST)
saveFromRequest()
Save variables from Request to database.
public
saveFromRequest() : void
softdeleteCond()
Return SQL condition for softdelete.
public
softdeleteCond() : string
Return values
stringSQL()
Execute SQL, if select operation return result in associative array.
public
SQL() : mixed
Return values
mixed —result in associative array
SQLBI()
Bulk Insert.
public
SQLBI(string $sql, array<string|int, mixed> $values[, int $chunk_size = 100 ]) : void
Parameters
- $sql : string
- $values : array<string|int, mixed>
- $chunk_size : int = 100
-
(optional)
SQLBU()
Bulk Update, only single pk is allowed.
public
SQLBU(string $sql, string $pk, array<string|int, mixed> $values[, int $chunk_size = 100 ]) : void
Parameters
- $sql : string
- $pk : string
- $values : array<string|int, mixed>
- $chunk_size : int = 100
-
(optional)
SQLR()
Execute SQL, return first row from result.
public
SQLR() : array<string|int, mixed>
Return values
array<string|int, mixed>tableName()
Returns the table name.
public
tableName() : string
Return values
string —The tableName() function is returning the value of the ->table property.
unique()
Check if value is unique.
public
unique(string $field, string|int $value) : bool
Parameters
- $field : string
- $value : string|int
Return values
boolvalidate()
public
validate(string $action, array<string|int, mixed> $data) : Validation
Parameters
- $action : string
- $data : array<string|int, mixed>
Return values
ValidationexistsInTable()
RakitVal rule, $value exists in $table.
protected
existsInTable() : object
Return values
objectinexistsInTable()
RakitVal rule, $value inexists in $table.
protected
inexistsInTable() : object
Return values
objectuniqueRule()
unique rule for RakitVal, checking if a $value is unique in $field.
protected
uniqueRule() : object