Role_model

Provides access and utility methods for handling role storage in the database.

Extends

MY_Model

Package

Roles

Summary
Role_modelProvides access and utility methods for handling role storage in the database.
Functions
__construct()Class constructor.
find()Returns a single role, with an array of permissions.
find_by_name()Locates a role based on the role name.
update()A simple update of the role.
can_delete_role()Verifies that a role can be deleted.
delete()Deletes a role.
default_role_id()Returns the id of the default role.
get_role_permissions()Finds the permissions and role_permissions array for a single role.

Functions

__construct()

public function __construct()

Class constructor.  Will load the permission_model, if it’s not already loaded.

find()

public function find($id = null)

Returns a single role, with an array of permissions.

Parameters

$idAn int that matches the role_id of the role in question.

Returns

An array of information about the role, along with a sub-array that contains the role’s applicable permissions.

find_by_name()

public function find_by_name($name = null)

Locates a role based on the role name.  Case doesn’t matter.

Parameters

$nameA string with the name of the role.

Returns

An object with the role and it’s permissions.

update()

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

A simple update of the role.  This does, however, clean things up when setting this role as the default role for new users.

Parameters

$idAn int, being the role_id
$dataAn array of key/value pairs to update the db with.

Returns

true/false

can_delete_role()

public function can_delete_role($role_id = )

Verifies that a role can be deleted.

Parameters

$role_idThe role to verify.

Returns

true/false

delete()

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

Deletes a role.  By default, it will perform a soft_delete and leave the permissions untouched.  However, if $purge == TRUE, then all permissions related to this role are also deleted.

Parameters

$idAn integer with the role_id to delete.
$purgeIf false, will perform a soft_delete.  If true, will remove the role and related permissions from db.

Returns

true/false

default_role_id()

public function default_role_id()

Returns the id of the default role.

Return

An int with the default role_id, or false if none found.

get_role_permissions()

public function get_role_permissions(&$role)

Finds the permissions and role_permissions array for a single role.

Parameters

$roleA reference to an existing role object.  This object is modified directly.

Returns

void

Access

Private

public function __construct()
Class constructor.
public function find($id = null)
Returns a single role, with an array of permissions.
public function find_by_name($name = null)
Locates a role based on the role name.
public function update($id = null,
$data = null)
A simple update of the role.
public function can_delete_role($role_id = )
Verifies that a role can be deleted.
function delete($id = 0,
$purge = false)
Deletes a role.
public function default_role_id()
Returns the id of the default role.
public function get_role_permissions(&$role)
Finds the permissions and role_permissions array for a single role.
Close