From 8a4e5e8bce5a11defc9072d6d3e2c7033cc96d12 Mon Sep 17 00:00:00 2001 From: atme Date: Wed, 24 Sep 2014 18:02:17 +0800 Subject: [PATCH] add method "removeAllUsers" Now we can remove all users from any group --- lib/adLDAP/classes/adLDAPGroups.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/adLDAP/classes/adLDAPGroups.php b/lib/adLDAP/classes/adLDAPGroups.php index 5faa9c1..71830aa 100644 --- a/lib/adLDAP/classes/adLDAPGroups.php +++ b/lib/adLDAP/classes/adLDAPGroups.php @@ -298,6 +298,32 @@ public function removeUser($group, $user, $isGUID = false) { } return true; } + + /** + * Remove all users from a group + * + * @param string $group The group to remove users from + * @return bool + */ + public function removeAllUsers($group) { + // Find parent and user distinguished names + $groupInfo = $this->info($group, array("member")); + if ($groupInfo[0]["dn"] === NULL || $groupInfo[0]["member"] === NULL) { + return false; + } + + $groupDn = $groupInfo[0]["dn"]; + + unset($groupInfo[0]['member']['count']); + + foreach ($groupInfo[0]["member"] as $member) { + $result = @ldap_mod_del($this->adldap->getLdapConnection(), $groupDn, array('member'=>$member)); + if ($result == false) { + return false; + } + } + return true; + } /** * Remove a contact from a group