implement getDisplayNames in group manager

remotes/origin/stable6
Arthur Schiwon 13 years ago
parent 637aa56197
commit f93ab1105f
  1. 12
      lib/private/group.php
  2. 33
      lib/private/group/manager.php
  3. 4
      lib/private/user/manager.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);
}
/**

@ -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;
}
}

@ -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

Loading…
Cancel
Save