From f93ab1105f044b098395d099646747992ef565cb Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 15 Mar 2014 06:03:28 +0100 Subject: implement getDisplayNames in group manager --- lib/private/group.php | 12 +----------- lib/private/group/manager.php | 33 +++++++++++++++++++++++++++++++++ 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 -- cgit v1.2.3