public function LdapAuthorizationConsumerOG::usersAuthorizations in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 7.2 ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php \LdapAuthorizationConsumerOG::usersAuthorizations()
- 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 713
Class
Code
public function usersAuthorizations(&$user, $reset = FALSE, $return_data = TRUE) {
static $users;
if (!is_array($users)) {
$users = array();
// no cache exists, create static array
}
elseif ($reset && isset($users[$user->uid])) {
unset($users[$user->uid]);
// clear users cache
}
elseif (!$return_data) {
return NULL;
// simply clearing cache
}
elseif (!empty($users[$user->uid])) {
return $users[$user->uid];
// return cached data
}
$authorizations = array();
if ($this->ogVersion == 1) {
$gids = og_get_groups_by_user($user);
foreach ($gids as $i => $gid) {
$roles = og_get_user_roles($gid, $user->uid);
if (!empty($roles[$this->defaultMembershipRid])) {
// if you aren't a member, doesn't matter what roles you have in og 1.5
if (isset($roles[$this->anonymousRid])) {
unset($roles[$this->anonymousRid]);
}
// ignore anonymous role
$rids = array_values($roles);
asort($rids, SORT_NUMERIC);
// go low to high to get default memberships first
foreach ($rids as $rid) {
$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);
}
}
}
}
$users[$user->uid] = $authorizations;
return $authorizations;
}