You are here

public function LdapAuthorizationConsumerOG::usersAuthorizations in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php \LdapAuthorizationConsumerOG::usersAuthorizations()
  2. 7 ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php \LdapAuthorizationConsumerOG::usersAuthorizations()

Overrides LdapAuthorizationConsumerAbstract::usersAuthorizations

See also

ldapAuthorizationConsumerAbstract::usersAuthorizations

2 calls to LdapAuthorizationConsumerOG::usersAuthorizations()
LdapAuthorizationConsumerOG::flushRelatedCaches in ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php
Attempt to flush related caches. This will be something like og_invalidate_cache($gids)
LdapAuthorizationConsumerOG::grantsAndRevokes in ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php

File

ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php, line 512

Class

LdapAuthorizationConsumerOG

Code

public function usersAuthorizations(&$user, $reset = FALSE, $return_data = TRUE) {
  static $users;
  if (!is_array($users)) {

    // No cache exists, create static array.
    $users = [];
  }
  elseif ($reset && isset($users[$user->uid])) {

    // Clear users cache.
    unset($users[$user->uid]);
  }
  elseif (!$return_data) {

    // Simply clearing cache.
    return NULL;
  }
  elseif (!empty($users[$user->uid])) {

    // Return cached data.
    return $users[$user->uid];
  }
  $authorizations = [];
  $user_entities = entity_load('user', [
    $user->uid,
  ]);
  $memberships = og_get_entity_groups('user', $user_entities[$user->uid]);
  foreach ($memberships as $entity_type => $entity_memberships) {
    foreach ($entity_memberships as $og_membership_id => $gid) {
      $roles = og_get_user_roles($entity_type, $gid, $user->uid);
      foreach ($roles as $rid => $discard) {
        $authorizations[] = ldap_authorization_og_authorization_id($gid, $rid, $entity_type);
      }
    }
  }
  $users[$user->uid] = $authorizations;
  return $authorizations;
}