User_model

The central way to access and perform CRUD on users.

Summary
User_modelThe central way to access and perform CRUD on users.
Functions
insert()Creates a new user in the database.
update()
find()Finds an individual user record.
find_all()Returns all user records, and their associated role information.
find_by()Locates a single user based on a field/value match, with their role information.
count_by_roles()Returns the number of users that belong to each role.
count_all()Counts all users in the system.
delete()Performs a standard delete, but also allows for purging of a record.
hash_password()Generates a new salt and password hash for the given password.
get_login_attempts()Returns the most recent login attempts and their description.

Functions

insert()

public function insert($data = array())

Creates a new user in the database.

Required parameters sent in the $data array

  • password
  • A unique email address

If no role id is passed in the $data array, it will assign the default role from Roles model.

Parameters

$dataAn array of user information.

Returns

$idThe ID of the new user.

update()

public function update($id = null,
$data = array())

Updates an existing user.  Before saving, it will

  • generate a new password/salt combo if both password and pass_confirm are passed in.
  • store the country code

Parameters

$idAn INT with the user’s ID.
$dataAn array of key/value pairs to update for the user.

Returns

true/false

find()

public function find($id = null)

Finds an individual user record.  Also returns role information for the user.

Parameters

$idAn INT with the user’s ID.

Returns

An object with the user’s information.

find_all()

public function find_all($show_deleted = false)

Returns all user records, and their associated role information.

Parameters

$show_deletedIf false, will only return non-deleted users.  If true, will return both deleted and non-deleted users.

Returns

An array of objects with each user’s information.

find_by()

public function find_by($field = null,
$value = null)

Locates a single user based on a field/value match, with their role information.  If the $field string is ‘both’, then it will attempt to find the user where their $value field matches either the username or email on record.

Parameters

$fieldA string with the field to match.
$valueA string with the value to search for.

Returns

An object with the user’s info, or false on failure.

count_by_roles()

public function count_by_roles()

Returns the number of users that belong to each role.

Returns

An array of objects representing the number in each role.

count_all()

public function count_all($get_deleted =  false)

Counts all users in the system.

Parameters

$get_deletedIf false, will only return active users.  If true, will return both deleted and active users.

Returns

An INT with the number of users found.

delete()

public function delete($id = 0,
$purge = false)

Performs a standard delete, but also allows for purging of a record.

Parameters

$idAn INT with the record ID to delete.
$purgeIf false, will perform a soft-delete.  If true, will permenantly delete the record.

Returns

true/false

hash_password()

public function hash_password($old = '')

Generates a new salt and password hash for the given password.

Parameters

$oldThe password to hash.

Returns

An array with the hashed password and new salt.

get_login_attempts()

public function get_login_attempts($limit = 15)

Returns the most recent login attempts and their description.

Parameters

$limitAn INT which is the number of results to return.

Returns

An array of objects with the login information.

public function insert($data = array())
Creates a new user in the database.
public function update($id = null,
$data = array())
public function find($id = null)
Finds an individual user record.
public function find_all($show_deleted = false)
Returns all user records, and their associated role information.
public function find_by($field = null,
$value = null)
Locates a single user based on a field/value match, with their role information.
public function count_by_roles()
Returns the number of users that belong to each role.
public function count_all($get_deleted =  false)
Counts all users in the system.
public function delete($id = 0,
$purge = false)
Performs a standard delete, but also allows for purging of a record.
public function hash_password($old = '')
Generates a new salt and password hash for the given password.
public function get_login_attempts($limit = 15)
Returns the most recent login attempts and their description.
The Roles Module provides a simple, yet flexible Role-Based Access Control (RBAC) system for your applications.
Close