diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-03-15 06:03:28 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-04-23 13:35:00 +0200 |
commit | f93ab1105f044b098395d099646747992ef565cb (patch) | |
tree | d62078182475d65b956b66bb24a549b58382c75f | |
parent | 637aa5619798b09d54dd4642214e72079272c243 (diff) | |
download | nextcloud-server-f93ab1105f044b098395d099646747992ef565cb.tar.gz nextcloud-server-f93ab1105f044b098395d099646747992ef565cb.zip |
implement getDisplayNames in group manager
-rw-r--r-- | lib/private/group.php | 12 | ||||
-rw-r--r-- | lib/private/group/manager.php | 33 | ||||
-rw-r--r-- | lib/private/user/manager.php | 4 |
3 files changed, 36 insertions, 13 deletions
diff --git a/lib/private/group.php b/lib/private/group.php index 444788c97f1..b45855c9215 100644 --- a/lib/private/group.php +++ b/lib/private/group.php @@ -263,17 +263,7 @@ class OC_Group { * @returns array with display names (value) and user ids(key) */ public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { - $group = self::getManager()->get($gid); - if ($group) { - $users = $group->searchDisplayName($search, $limit, $offset); - $displayNames = array(); - foreach ($users as $user) { - $displayNames[$user->getUID()] = $user->getDisplayName(); - } - return $displayNames; - } else { - return array(); - } + return self::getManager()->displayNamesInGroup($gid, $search, $limit, $offset); } /** diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index 454e2b63b47..611af0a40fb 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -160,4 +160,37 @@ class Manager extends PublicEmitter { } return array_values($groups); } + + /** + * @brief get a list of all display names in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with display names (value) and user ids (key) + */ + public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { + $group = $this->get($gid); + if(is_null($group)) { + return array(); + } + // only user backends have the capability to do a complex search for users + $groupUsers = $group->searchUsers('', $limit, $offset); + if(!empty(trim($search))) { + //TODO: for OC 7 earliest: user backend should get a method to check selected users against a pattern + $filteredUsers = $this->userManager->search($search); + $testUsers = true; + } else { + $filteredUsers = array(); + $testUsers = false; + } + + $matchingUsers = array(); + foreach($groupUsers as $user) { + if(!$testUsers || isset($filteredUsers[$user->getUID()])) { + $matchingUsers[$user->getUID()] = $user->getDisplayName(); + } + } + return $matchingUsers; + } } diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php index 61abb00f995..d23ef381bec 100644 --- a/lib/private/user/manager.php +++ b/lib/private/user/manager.php @@ -174,12 +174,12 @@ class Manager extends PublicEmitter { $backendUsers = $backend->getUsers($pattern, $limit, $offset); if (is_array($backendUsers)) { foreach ($backendUsers as $uid) { - $users[] = $this->getUserObject($uid, $backend); + $users[$uid] = $this->getUserObject($uid, $backend); } } } - usort($users, function ($a, $b) { + uasort($users, function ($a, $b) { /** * @var \OC\User\User $a * @var \OC\User\User $b |