\Admins_Model

Admins_Model Class

Handles the database actions for admin users management.

Data Structure:

 'fist_name'
 'last_name' (required)
 'email' (required)
 'mobile_number'
 'phone_number' (required)
 'address'
 'city'
 'state'
 'zip_code'
 'notes'
 'id_roles'
 'settings' >>> array that contains user settings (username, password etc)

Summary

Methods
Properties
Constants
__construct()
add()
exists()
insert()
update()
find_record_id()
validate()
delete()
get_row()
get_value()
get_batch()
get_admin_role_id()
validate_username()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct() 

Class Constructor

add()

add(array  $admin) : integer

Add (insert or update) an admin user record into database.

Parameters

array $admin

Contains the admin user data.

Throws

\Exception

When the admin data are invalid (see validate() method).

Returns

integer —

Returns the record id.

exists()

exists(array  $admin) : boolean

Check whether a particular admin record exists in the database.

Parameters

array $admin

Contains the admin data. The 'email' value is required to be present at the moment.

Throws

\Exception

When the 'email' value is not present on the $admin argument.

Returns

boolean —

Returns whether the record exists or not.

insert()

insert(array  $admin) : integer

Insert a new admin record into the database.

Parameters

array $admin

Contains the admin data.

Throws

\Exception

When the insert operation fails.

Returns

integer —

Returns the new record id.

update()

update(array  $admin) : integer

Update an existing admin record in the database.

Parameters

array $admin

Contains the admin record data.

Throws

\Exception

When the update operation fails.

Returns

integer —

Retuns the record id.

find_record_id()

find_record_id(array  $admin) : integer

Find the database record id of an admin user.

Parameters

array $admin

Contains the admin data. The 'email' value is required in order to find the record id.

Throws

\Exception

When the 'email' value is not present on the $admin array.

Returns

integer —

Returns the record id

validate()

validate(array  $admin) : boolean

Validate admin user data before add() operation is executed.

Parameters

array $admin

Contains the admin user data.

Throws

\Exception

When data are invalid.

Returns

boolean —

Returns the validation result.

delete()

delete(\numeric  $admin_id) : boolean

Delete an existing admin record from the database.

Parameters

\numeric $admin_id

The admin record id to be deleted.

Throws

\Exception

When the $admin_id is not a valid numeric value.

\Exception

When the record to be deleted is the only one admin user left on the system.

Returns

boolean —

Returns the delete operation result.

get_row()

get_row(\numeric  $admin_id) : array

Get a specific admin record from the database.

Parameters

\numeric $admin_id

The id of the record to be returned.

Throws

\Exception

When the $admin_id is not a valid numeric value.

Returns

array —

Returns an array with the admin user data.

get_value()

get_value(string  $field_name, \numeric  $admin_id) : string

Get a specific field value from the database.

Parameters

string $field_name

The field name of the value to be returned.

\numeric $admin_id

Record id of the value to be returned.

Throws

\Exception

When the $field_name argument is not a valid string.

\Exception

When the $admin_id is not a valid numeric.

\Exception

When the admin record does not exist in the database.

\Exception

When the selected field value is not present on database.

Returns

string —

Returns the selected record value from the database.

get_batch()

get_batch(string|array  $where_clause = '') : array

Get all, or specific admin records from database.

Parameters

string|array $where_clause

(OPTIONAL) The WHERE clause of the query to be executed. Use this to get specific admin records.

Returns

array —

Returns an array with admin records.

get_admin_role_id()

get_admin_role_id() : integer

Get the admin users role id.

Returns

integer —

Returns the role record id.

validate_username()

validate_username(string  $username, \numeric  $user_id) : boolean

Validate Records Username

Parameters

string $username

The provider records username.

\numeric $user_id

The user record id.

Returns

boolean —

Returns the validation result.