You are here

function access_grant_load_by_condition in Access Control Kit 7

Loads all access grants that match a set of conditions.

Parameters

array $conditions: An array of search conditions. Valid conditions are:

  • 'scheme': a scheme machine name.
  • 'uid': a user ID.
  • 'rid': a role ID.
  • 'realms': an array of realm field values. Ignored if 'scheme' is omitted.

bool $reset: (optional) Whether to reset the internal cache. Defaults to FALSE.

Return value

array An array of access grants that match the given conditions.

5 calls to access_grant_load_by_condition()
AccessGrantFunctionTest::testGrantCRUD in ./access.test
Test basic create, read, update, and delete functions.
access_grant_delete_confirm in ./access_grants.admin.inc
Form constructor for the access grant delete confirmation form.
access_grant_form in ./access_grants.admin.inc
Form constructor for the access grant add/edit form.
access_grant_form_validate in ./access_grants.admin.inc
Form validation handler for access_grant_form().
access_user_roles in ./access.module
Returns a list of a user's realm-level role memberships.

File

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

Code

function access_grant_load_by_condition($conditions = array(), $reset = FALSE) {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'access_grant');
  if (isset($conditions['scheme'])) {
    $query
      ->entityCondition('bundle', $conditions['scheme']);
    if (isset($conditions['realms'])) {

      // Make sure that the referenced scheme actually exists.
      $scheme = access_scheme_machine_name_load($conditions['scheme']);
      if ($scheme) {
        $query
          ->fieldCondition($scheme->realm_field['field_name'], 'value', $conditions['realms']);
      }
      else {
        return array();
      }
    }
  }
  if (isset($conditions['uid'])) {
    $query
      ->propertyCondition('uid', $conditions['uid']);
  }
  if (isset($conditions['rid'])) {
    $query
      ->propertyCondition('rid', $conditions['rid']);
  }
  $result = $query
    ->execute();
  if (empty($result)) {
    return array();
  }
  $gids = array_keys($result['access_grant']);
  return access_grant_load_multiple($gids, $reset);
}