You are here

function access_user_permission_realms in Access Control Kit 7

Returns a list of realms in which the user has a given permission.

Parameters

string $string: The permission string (e.g., edit any page).

object $account: (optional) The account to check. Defaults to the currently logged in user.

array $schemes: (optional) An array of access schemes, used to limit the list of returned realms. If omitted, the returned list will include realms for all schemes.

Return value

array An array indexed by scheme machine name where each value is an array of realm values. If the user does not have the permission for any realm in a scheme, the value returned for that scheme will be array().

4 calls to access_user_permission_realms()
access_user_object_access in ./access.module
Determines whether a user has a permission on an object via an access grant.
ack_menu_realm_access in ack_menu/ack_menu.module
Access callback for managing realm links.
ack_node_form_node_form_alter in ack_node/ack_node.module
Implements hook_form_BASE_FORM_ID_alter().
ack_node_node_access in ack_node/ack_node.module
Implements hook_node_access().

File

./access.module, line 884
The access control kit module.

Code

function access_user_permission_realms($string, $account = NULL, $schemes = NULL) {
  global $user;
  if (!isset($account)) {
    $account = $user;
  }
  if (!isset($schemes)) {
    $schemes = access_scheme_load_multiple();
  }

  // Get the user's realm-level role memberships.
  $roles = access_user_roles($account);

  // Filter out any roles that do not include the permission we're looking for.
  foreach (user_role_permissions($roles) as $rid => $permissions) {
    if (empty($permissions[$string])) {
      unset($roles[$rid]);
    }
  }

  // Find the accessible realms for each scheme.
  $realms = array();
  foreach ($schemes as $scheme) {
    $scheme_realms = array();
    foreach ($roles as $access) {
      if (!empty($access[$scheme->machine_name])) {
        $scheme_realms += $access[$scheme->machine_name];
      }
    }
    $realms[$scheme->machine_name] = array_keys($scheme_realms);
  }
  return $realms;
}