Model_Role

class Nos\User\Model_Role

Extend Nos\Orm\Model.

Relations

property Nos\User\Model_Role::$users

Methods

Nos\User\Model_Role::checkPermission($permission_name, $category_key = null, $allow_empty = false)

Check whether a permissions exists with the given category.

Parameters:
  • $permission_name (string) – Name of the permission to check against
  • $category_key (string) – (optional) If the permission has categories, the category key to check against
  • $allow_empty (bool) – Should we grant access when nothing is configured?
Returns bool:

true or false

Nos\User\Model_Role::listPermissionCategories($permission_name)

List all the categories of a given permission name. Returns an array of string or false when the role has not access, or the permission name does not exists.

Parameters:
  • $permission_name (string) – The name of the permission to retrieve categories from
  • $category_key (string) – (optional) If the permission has categories, the category key to check against
Returns:

array|false An array containing the list of categories (values) for the request permission name

Nos\User\Model_Role::checkPermissionOrEmpty($permission_name, $category_key = null)

Alias to Nos\User\Model_Role::checkPermission with $allow_empty = true.

Nos\User\Model_Role::checkPermissionExists($permission_name, $category_key = null, $allow_empty = false)

Alias to Nos\User\Model_Role::checkPermission.

Nos\User\Model_Role::checkPermissionExistsOrEmpty($permission_name, $category_key = null, $allow_empty = false)

Alias to Nos\User\Model_Role::checkPermission with $allow_empty = true.

static Nos\User\Model_Role::checkPermissionIsAllowed($permission_name, $allow_empty = false)

Check against a binary permission (without categories).

Parameters:
  • $permission_name (string) – Name of the permission
  • $allow_empty (bool) – Should we grant access when nothing is configured?
Returns bool:

true or false

Nos\User\Model_Role::checkPermissionAtLeast($permission_name, $threshold, $value_when_empty = 0)

Check against a numeric / range permission.

You can use string for the 2nd and 3rd parameters, they will be casted to (int). i.e. '2_write' === 2.

Parameters:
  • $permission_name (string) – Name of the permission
  • $threshold (int) – Minimum value to grant access
  • $value_when_empty (int) – Default value to compare with when nothing is configured
Returns bool:

true or false

Nos\User\Model_Role::checkPermissionAtMost($permission_name, $threshold, $value_when_empty = 0)

Check against a numeric / range permission.

You can use string for the 2nd and 3rd parameters, they will be casted to (int). i.e. '2_write' === 2.

Parameters:
  • $permission_name (string) – Name of the permission
  • $threshold (int) – Maximum value to grant access
  • $value_when_empty (int) – Default value to compare with when nothing is configured
Returns bool:

true or false

Nos\User\Model_Role::getPermissionValue($permission_name, $default = 0)

Retrieve the value of a given permission.

Parameters:
  • $permission_name (string) – Name of the permission
  • $default (mixed) – Default value to return when the permission does not exists
Returns string: