You are here

public function LdapServer::groupMembershipsFromUser in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/LdapServer.class.php \LdapServer::groupMembershipsFromUser()

Get list of all groups that a user is a member of.

If $nested = TRUE, list will include all parent group. That is if user is a member of "programmer" group and "programmer" group is a member of "it" group, user is a member of both "programmer" and "it" groups.

If $nested = FALSE, list will only include groups user is in directly.

Parameters

mixed:

  • drupal user object (stdClass Object)

    • ldap entry of user (array) (with top level keys of 'dn', 'mail', 'sid' and 'attr' )
    • ldap dn of user (array)
    • drupal username of user (string)

mixed $return: = 'group_dns'.

bool $nested: if groups should be recursed or not.

Return value

array of groups dns in mixed case or FALSE on error

1 call to LdapServer::groupMembershipsFromUser()
LdapServer::groupIsMember in ldap_servers/LdapServer.class.php
Is a user a member of group?

File

ldap_servers/LdapServer.class.php, line 1758
Defines server classes and related functions.

Class

LdapServer
LDAP Server Class.

Code

public function groupMembershipsFromUser($user, $return = 'group_dns', $nested = NULL) {
  $group_dns = FALSE;
  $user_ldap_entry = @$this
    ->userUserToExistingLdapEntry($user);
  if (!$user_ldap_entry || $this->groupFunctionalityUnused) {
    return FALSE;
  }
  if ($nested === NULL) {
    $nested = $this->groupNested;
  }

  // Preferred method.
  if ($this->groupUserMembershipsConfigured) {
    $group_dns = $this
      ->groupUserMembershipsFromUserAttr($user_ldap_entry, $nested);
  }
  elseif ($this->groupGroupEntryMembershipsConfigured) {
    $group_dns = $this
      ->groupUserMembershipsFromEntry($user_ldap_entry, $nested);
  }
  else {
    watchdog('ldap_servers', 'groupMembershipsFromUser: Group memberships for server have not been configured.', [], WATCHDOG_WARNING);
    return FALSE;
  }
  if ($return == 'group_dns') {
    return $group_dns;
  }
}