You are here

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

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

* Return all user authorization ids (group x role) in form gid-rid such as 2-1. * regardless of it they were granted by this module, any authorization ids should be returned. * *

Parameters

user object $user: * @return array such as array('3-2','7-2')

File

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

Class

LdapAuthorizationConsumerOG

Code

public function usersAuthorizations(&$user) {
  $authorizations = array();
  if ($this->ogVersion == 1) {
    $groups = og_load_multiple(og_get_all_group());
    $authorizations = array();
    if (is_object($user) && is_array($groups)) {
      foreach ($groups as $gid => $discard) {
        $roles = og_get_user_roles($gid, $user->uid);
        foreach ($roles as $rid => $discard) {
          $authorizations[] = ldap_authorization_og_authorization_id($gid, $rid);
        }
      }
    }
  }
  else {

    // og 7.x-2.x
    $user_entities = entity_load('user', array(
      $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);
        }
      }
    }
  }
  return $authorizations;
}