UserFieldsDb
extends BaseModel
in package
uses
MetaFieldsTrait
User fields DB model.
Tags
Table of Contents
Properties
- $rdbaUserFields : array<string|int, mixed>
- $builtCacheContent : array<string|int, mixed>|null
- $getFieldsNoData : bool
- $objectId : int
- $objectIdName : string
- $tableName : string
- $rdbaUserFields : array<string|int, mixed>
- Some of these fields must be remove on update user in `/Admin/Users/EditController->preventUpdateFields` property.
Methods
- __construct() : mixed
- {@inheritDoc}
- __get() : mixed
- Magic get.
- buildCacheContent() : string
- Get DB result and build cache content.
- delete() : bool
- Delete user field.
- deleteAllUserFields() : bool
- Delete all fields for specific user ID.
- generateKeyWithWaitTime() : array<string|int, mixed>
- Generate key with wait time.
- get() : mixed
- Get user fields data by name.
- listUsersFields() : array<string|int, mixed>
- List multiple users fields.
- update() : mixed
- Update user field.
- updateMultiple() : bool
- Update or insert multiple user fields at once.
- addFieldsData() : mixed
- Add a meta field data to meta `_fields` table.
- beginMetaFieldsTrait() : mixed
- Trait initialize method.
- deleteAllFieldsData() : bool
- Delete all fields for specific object ID.
- deleteFieldsData() : bool
- Delete a meta field data from meta `_fields` table.
- getFields() : mixed
- Get meta field(s) data by conditions.
- getFieldsNoCache() : mixed
- Get meta field(s) data by conditions but no cache.
- getFieldValueReformat() : mixed
- Get field value that will be re-formatted for insert, update, read.
- getStorageFileName() : string
- Get storage file name with .php extension.
- listObjectsFields() : array<string|int, mixed>
- List multiple objects and their fields.
- updateFieldsData() : mixed
- Update a meta field data to meta `_fields` table.
- updateFieldsMultipleData() : bool
- Update `_fields` table on multiple values.
- bindValuesForUpdateFieldsMultipleData() : mixed
- Call to `bindValue()` from `$Sth` argument.
- buildPlaceholdersAndBindValuesDescForUpdateFieldsMultipleData() : mixed
- Build/alter the variables for description column for use in `updateFieldsMultipleData()` method.
- buildPlaceholdersAndBindValuesForUpdateFieldsMultipleData() : mixed
- Build/alter the variables for use in `updateFieldsMultipleData()` method.
Properties
$rdbaUserFields read-only
public
array<string|int, mixed>
$rdbaUserFields
Registered fields data that come with this module.
$builtCacheContent
protected
array<string|int, mixed>|null
$builtCacheContent
The temporary result where the query was called to selected object ID. The result of DB queried will be array wether it is empty or not.
This property's value was set in listObjectsFields()
method.
This will be reset to null
once called buildCacheContent()
method and found that this is not null
.
Tags
$getFieldsNoData
protected
bool
$getFieldsNoData
= false
Indicate that getFields()
and getFieldsNoCache()
methods contain values or not. The result will be true
if no value or no data, but will be false
if there is at least a value or data.
Tags
$objectId
protected
int
$objectId
The object_id.
$objectIdName
protected
string
$objectIdName
The field name of object_id.
$tableName
protected
string
$tableName
Table fields name.
$rdbaUserFields
Some of these fields must be remove on update user in `/Admin/Users/EditController->preventUpdateFields` property.
private
array<string|int, mixed>
$rdbaUserFields
= ['rdbadmin_uf_adduser_waitactivation_since' => 'Add user and wait for activation since date/time.', 'rdbadmin_uf_admindashboardwidgets_order' => 'Admin dashboard widgets ordering.', 'rdbadmin_uf_changeemail_value' => 'New email will be here and wait for confirmation link clicked.', 'rdbadmin_uf_changeemail_key' => 'Change email confirmation key for send to user email and verify via the link.', 'rdbadmin_uf_changeemail_time' => 'Change email expire date/time for the specific key.', 'rdbadmin_uf_changeemail_history' => 'List of email that has been changed.', 'rdbadmin_uf_login2stepverification' => 'Login second step verification method.', 'rdbadmin_uf_login2stepverification_key' => 'Login second step verification key.', 'rdbadmin_uf_login2stepverification_time' => 'Login second step verification expire date/time.', 'rdbadmin_uf_login2stepverification_tmpdata' => 'Temporary data while waiting 2 step auth.', 'rdbadmin_uf_registerconfirm_key' => 'User register key for self confirm registration that send to user email and verify via the link.', 'rdbadmin_uf_resetpassword_key' => 'Reset password key for send to user email and verify via the link.', 'rdbadmin_uf_resetpassword_time' => 'Reset password expire date/time for the specific key.', 'rdbadmin_uf_securitysimultaneouslogin' => 'How to handle with simultaneous logins?', 'rdbadmin_uf_simultaneouslogin_reset_key' => 'Login key to use after there is simultaneous logins and get logged out.', 'rdbadmin_uf_simultaneouslogin_reset_time' => 'Login key expire date/time.', 'rdbadmin_uf_avatar' => 'User\'s profile picture (avatar).', 'rdbadmin_uf_avatar_type' => 'Avatar type (upload or gravatar).', 'rdbadmin_uf_website' => 'User\'s website.']
Register the fields data that come with this module.
Methods
__construct()
{@inheritDoc}
public
__construct(Container $Container) : mixed
Parameters
- $Container : Container
__get()
Magic get.
public
__get(string $name) : mixed
Parameters
- $name : string
-
Property name.
Return values
mixed —Return its value depend on property.
buildCacheContent()
Get DB result and build cache content.
public
buildCacheContent() : string
This method must be public to be able to called from other method/class.
Return values
string —Return generated data in php language that is ready to use as cache.
delete()
Delete user field.
public
delete(int $user_id, string $field_name) : bool
Parameters
- $user_id : int
-
The user ID.
- $field_name : string
-
Field name.
Return values
bool —Return true
on success, false
for otherwise.
deleteAllUserFields()
Delete all fields for specific user ID.
public
deleteAllUserFields(int $user_id) : bool
Parameters
- $user_id : int
-
The user ID.
Return values
bool —Return true
on success, false
for otherwise.
generateKeyWithWaitTime()
Generate key with wait time.
public
generateKeyWithWaitTime(int $user_id, string $keyFieldName, string $timeFieldName[, int $waitMinute = 10 ][, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
If the key was generated and still within wait time then it will be use the old one, otherwise it will be generate new.
This method did not create/update/delete the data in DB.
Parameters
- $user_id : int
-
User ID.
- $keyFieldName : string
-
Name of field that contain key in
field_value
. - $timeFieldName : string
-
Name of field that contain time in
field_value
. - $waitMinute : int = 10
-
Minutes to wait.
- $options : array<string|int, mixed> = []
-
The associative array options:
'keyLength' (int) The key length to generate. Default is 8.
'keyCharacters (string) The key string to generate. Default is empty string means 0-9, a-z.
Return values
array<string|int, mixed> —Return associative array with 'readableKey', 'encryptedKey', 'keyTime', 'regenerate' keys.
get()
Get user fields data by name.
public
get(int $user_id[, string $field_name = '' ]) : mixed
Parameters
- $user_id : int
-
The user ID.
- $field_name : string = ''
-
Meta field name. If this field is empty then it will get all fields that matched this user ID.
Return values
mixed —Return the row(s) of user fields data. If it was not found then return null.
The return value may be unserialize if it is not scalar and not null
.
listUsersFields()
List multiple users fields.
public
listUsersFields(array<string|int, mixed> $userIds[, string $field_name = '' ]) : array<string|int, mixed>
Parameters
- $userIds : array<string|int, mixed>
-
The multiple user IDs to search in.
- $field_name : string = ''
-
Meta field name. If this field is empty then it will get all fields that matched user IDs.
Tags
Return values
array<string|int, mixed> —Return associative array where key is each object ID in the $objectIds
and its result will be the same as we get from getFields()
method with $field_name
parameter.
update()
Update user field.
public
update(int $user_id, string $field_name, mixed $field_value[, string|false|true $field_description = false ][, mixed $previousValue = false ]) : mixed
If data is not exists then it will be call add data automatically.
Parameters
- $user_id : int
-
The user ID.
- $field_name : string
-
Field name.
- $field_value : mixed
-
Field value.
- $field_description : string|false|true = false
-
Field description. Set to
false
(default) to not change. Set totrue
to get it from registered fields data key and its description fromrdbaUserFields
property. - $previousValue : mixed = false
-
Previous field value to check that it must be matched, otherwise it will not be update and return
false
. Set this tofalse
to skip checking.
Return values
mixed —Return field ID if data is not exists then it will be use add()
method. Return true
if update success, false
for otherwise.
updateMultiple()
Update or insert multiple user fields at once.
public
updateMultiple(int $user_id, array<string|int, mixed> $data[, bool $updateFieldDescription = true ]) : bool
If data is not exists in DB then it will be insert.
Parameters
- $user_id : int
-
The user ID.
- $data : array<string|int, mixed>
-
Associative array where key is match
field_name
column and value is matchfield_value
column. Example:array( 'field_name1' => 'field value1', 'field_name2' => 'field value2', // ... )
- $updateFieldDescription : bool = true
-
Set to
true
to update/insert field description. Default istrue
.
Return values
bool —Return true
if update or insert completed, return false
for otherwise.
addFieldsData()
Add a meta field data to meta `_fields` table.
protected
addFieldsData(int $objectId, string $field_name, mixed $field_value[, string $field_description = false ]) : mixed
This method is not recommended to call it directly, please call to updateFieldsData()
method instead and if the data is not exists, it will be call this method automatically.
Parameters
- $objectId : int
-
Object ID.
- $field_name : string
-
Field name.
- $field_value : mixed
-
Field value. If it is no scalar then it will be serialize automatically.
- $field_description : string = false
-
Field description.
Return values
mixed —Return insert ID on success, or false
if failure.
beginMetaFieldsTrait()
Trait initialize method.
protected
beginMetaFieldsTrait(Container $Container) : mixed
This method must be called before it can be working.
Parameters
- $Container : Container
-
The DI container class.
deleteAllFieldsData()
Delete all fields for specific object ID.
protected
deleteAllFieldsData(int $objectId) : bool
Also delete cached data.
Parameters
- $objectId : int
-
Object ID.
Return values
bool —Return true
on success, false
for otherwise.
deleteFieldsData()
Delete a meta field data from meta `_fields` table.
protected
deleteFieldsData(int $objectId, string $field_name) : bool
Also delete cached data.
Parameters
- $objectId : int
-
Object ID.
- $field_name : string
-
Field name.
Return values
bool —Return true
on success, false
for otherwise.
getFields()
Get meta field(s) data by conditions.
protected
getFields(int $objectId[, string $field_name = '' ]) : mixed
Parameters
- $objectId : int
-
The object ID.
- $field_name : string = ''
-
The field name to search in. If this is empty then it will return all fields.
Return values
mixed —Return a single row of field or all rows depend on field name to search. If it was not found then return null.
The return value may be unserialize if it is not scalar and not null
.
You can call to property getFieldsNoData
(boolean) to check that are there any data or value from this method.
getFieldsNoCache()
Get meta field(s) data by conditions but no cache.
protected
getFieldsNoCache(int $objectId[, string $field_name = '' ]) : mixed
This method work the same as getFields()
method but connect to DB without cache to make very sure that data is really exists.
Parameters
- $objectId : int
-
The object ID.
- $field_name : string = ''
-
The field name to search in. If this is empty then it will return all fields.
Tags
Return values
mixed —Return a single row of field or all rows depend on field name to search. If it was not found then return null.
The return value may be unserialize if it is not scalar and not null
.
You can call to property getFieldsNoData
(boolean) to check that are there any data or value from this method.
getFieldValueReformat()
Get field value that will be re-formatted for insert, update, read.
protected
getFieldValueReformat(mixed $field_value[, srting $getFor = 'update' ]) : mixed
Parameters
- $field_value : mixed
-
The field value data that will be re-formatted.
- $getFor : srting = 'update'
-
Get field value that will be re-formatted for. Accepted value: 'insert', 'update', 'read'.
The 'insert' and 'update' value will use the same algorithm.
Tags
Return values
mixed —If 'insert', or 'update' value then the field value type scalar or null
will be return as is. Otherwise it will be serialize.
If 'read' value then it will be un-serialize the field value.
getStorageFileName()
Get storage file name with .php extension.
protected
getStorageFileName(int $objectId) : string
Parameters
- $objectId : int
-
The object ID.
Tags
Return values
string —Return storage file name. Example: object-id-311-user_fields.php
listObjectsFields()
List multiple objects and their fields.
protected
listObjectsFields(array<string|int, mixed> $objectIds[, string $field_name = '' ]) : array<string|int, mixed>
Parameters
- $objectIds : array<string|int, mixed>
-
The object IDs to search in.
- $field_name : string = ''
-
The field name to search in. If this is empty then it will return all.
Tags
Return values
array<string|int, mixed> —Return associative array where key is each object ID (int) in the $objectIds
and its result will be the same as we get from getFields()
method with $field_name
parameter.
updateFieldsData()
Update a meta field data to meta `_fields` table.
protected
updateFieldsData(int $objectId, string $field_name, mixed $field_value[, string|false $field_description = false ][, mixed $previousValue = false ]) : mixed
This will be add if the data is not exists.
Parameters
- $objectId : int
-
Object ID.
- $field_name : string
-
Field name.
- $field_value : mixed
-
Field value. If field value is not scalar then it will be serialize automatically.
- $field_description : string|false = false
-
Field description. Set to
false
to not change. - $previousValue : mixed = false
-
Previous field value to check that it must be matched, otherwise it will not be update and return
false
. Set this tofalse
to skip checking.
Return values
mixed —Return meta field ID if it use add method, return true
if update success, false
for otherwise.
updateFieldsMultipleData()
Update `_fields` table on multiple values.
protected
updateFieldsMultipleData(int $objectId, array<string|int, mixed> $data[, array<string|int, mixed> $dataDesc = [] ]) : bool
It will be update if data exists, or it will be insert if data is not exists.
Parameters
- $objectId : int
-
The object ID.
- $data : array<string|int, mixed>
-
Associative array where key is match
field_name
column and value is matchfield_value
column. - $dataDesc : array<string|int, mixed> = []
-
Associative array of field description where array key is the
field_name
column and its value is matchfield_description
column.
Tags
Return values
bool —Return true
if all data have been updated, false
for otherwise.
bindValuesForUpdateFieldsMultipleData()
Call to `bindValue()` from `$Sth` argument.
private
bindValuesForUpdateFieldsMultipleData(PDOStatement $Sth, array<string|int, mixed> $bindValues) : mixed
This is for work with updateFieldsMultipleData()
method.
Parameters
- $Sth : PDOStatement
- $bindValues : array<string|int, mixed>
-
The array of bind values where key is placeholder and value is its value.
Tags
buildPlaceholdersAndBindValuesDescForUpdateFieldsMultipleData()
Build/alter the variables for description column for use in `updateFieldsMultipleData()` method.
private
buildPlaceholdersAndBindValuesDescForUpdateFieldsMultipleData(array<string|int, mixed> $dataDesc, array<string|int, mixed> $fieldNamesToCheck, array<string|int, mixed> &$descPlaceholders, array<string|int, mixed> &$descBindValues) : mixed
Parameters
- $dataDesc : array<string|int, mixed>
-
The input data description.
- $fieldNamesToCheck : array<string|int, mixed>
-
The list of field names to check input name (field name) that must be matched. For example field for check with exists (will update), or not exists (will insert).
- $descPlaceholders : array<string|int, mixed>
-
The field description placeholders to be altered.
- $descBindValues : array<string|int, mixed>
-
The field description for use with bind values to be altered.
Tags
buildPlaceholdersAndBindValuesForUpdateFieldsMultipleData()
Build/alter the variables for use in `updateFieldsMultipleData()` method.
private
buildPlaceholdersAndBindValuesForUpdateFieldsMultipleData(array<string|int, mixed> $data, array<string|int, mixed> $fieldNamesToCheck, array<string|int, mixed> &$namePlaceholders, array<string|int, mixed> &$nameBindValues, array<string|int, mixed> &$valuePlaceholders, array<string|int, mixed> &$valueBindValues) : mixed
Parameters
- $data : array<string|int, mixed>
-
The input data.
- $fieldNamesToCheck : array<string|int, mixed>
-
The list of field names to check input name (field name) that must be matched. For example field for check with exists (will update), or not exists (will insert).
- $namePlaceholders : array<string|int, mixed>
-
The field name placeholders to be altered.
- $nameBindValues : array<string|int, mixed>
-
The field name for use with bind values to be altered.
- $valuePlaceholders : array<string|int, mixed>
-
The field value placeholders to be altered.
- $valueBindValues : array<string|int, mixed>
-
The field value for use with bind values to be altered.