You are here

public function SimpleLdapRole::deleteUser in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_role/SimpleLdapRole.class.php \SimpleLdapRole::deleteUser()

Remove an LDAP user from the LDAP group.

File

simple_ldap_role/SimpleLdapRole.class.php, line 316
SimpleLdapRole class file.

Class

SimpleLdapRole
@file SimpleLdapRole class file.

Code

public function deleteUser($user) {

  // Make sure the user is a SimpleLdapUser object.
  if (is_string($user)) {
    $user = SimpleLdapUser::singleton($user);
  }

  // Get the module configuration.
  $user_attribute_name = simple_ldap_user_variable_get('simple_ldap_user_attribute_name');
  $attribute_member = simple_ldap_role_variable_get('simple_ldap_role_attribute_member');
  $attribute_member_format = simple_ldap_role_variable_get('simple_ldap_role_attribute_member_format');

  // Determine the member attribute format.
  if ($attribute_member_format == 'dn') {
    $member = $user->dn;
  }
  else {
    $member = $user->{$user_attribute_name}[0];
  }

  // Remove the user from this group.
  if (is_array($this->attributes[$attribute_member])) {
    $key = array_search($member, $this->attributes[$attribute_member]);
    if ($key !== FALSE) {
      unset($this->attributes[$attribute_member][$key]);
      if (isset($this->attributes[$attribute_member]['count'])) {
        unset($this->attributes[$attribute_member]['count']);
      }
      $this->attributes[$attribute_member] = array_values($this->attributes[$attribute_member]);
      $this->attributes[$attribute_member]['count'] = count($this->attributes[$attribute_member]);
      $this->dirty = TRUE;
    }
  }
}