You are here

public function Server::groupAllMembers in Lightweight Directory Access Protocol (LDAP) 8.3

Get all members of a group.

Currently not in use.

@TODO: Split return functionality or throw an error.

Parameters

string $group_dn: Group DN as LDAP DN.

Return value

bool|array FALSE on error, otherwise array of group members (could be users or groups).

1 call to Server::groupAllMembers()
Server::groupRemoveGroup in ldap_servers/src/Entity/Server.php
Remove a group entry.

File

ldap_servers/src/Entity/Server.php, line 1977

Class

Server
Defines the Server entity.

Namespace

Drupal\ldap_servers\Entity

Code

public function groupAllMembers($group_dn) {
  if (!$this
    ->groupGroupEntryMembershipsConfigured()) {
    return FALSE;
  }
  $attributes = [
    $this
      ->groupMembershipsAttr(),
    'cn',
    'objectclass',
  ];
  $group_entry = $this
    ->checkDnExistsIncludeData($group_dn, $attributes);
  if (!$group_entry) {
    return FALSE;
  }
  else {

    // If attributes weren't returned, don't give false  empty group.
    if (empty($group_entry['cn'])) {
      return FALSE;
    }
    if (empty($group_entry[$this
      ->groupMembershipsAttr()])) {

      // If no attribute returned, no members.
      return [];
    }
    $members = $group_entry[$this
      ->groupMembershipsAttr()];
    if (isset($members['count'])) {
      unset($members['count']);
    }
    $result = $this
      ->groupMembersRecursive([
      $group_entry,
    ], $members, [], 0, self::LDAP_SERVER_LDAP_QUERY_RECURSION_LIMIT);

    // Remove the DN of the source group.
    if (($key = array_search($group_dn, $members)) !== FALSE) {
      unset($members[$key]);
    }
  }
  if ($result !== FALSE) {
    return $members;
  }
  else {
    return FALSE;
  }
}