reformat code for @skjnldsv <3

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
pull/17896/head
Arthur Schiwon 2019-10-09 19:15:43 +07:00
parent 7ff15c9756
commit f0ff8b0307
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
1 changed files with 22 additions and 16 deletions

@ -93,8 +93,8 @@ class Manager extends PublicEmitter implements IGroupManager {
$this->dispatcher = $dispatcher; $this->dispatcher = $dispatcher;
$this->logger = $logger; $this->logger = $logger;
$cachedGroups = & $this->cachedGroups; $cachedGroups = &$this->cachedGroups;
$cachedUserGroups = & $this->cachedUserGroups; $cachedUserGroups = &$this->cachedUserGroups;
$this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) { $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) {
/** /**
* @var \OC\Group\Group $group * @var \OC\Group\Group $group
@ -149,6 +149,7 @@ class Manager extends PublicEmitter implements IGroupManager {
/** /**
* Get the active backends * Get the active backends
*
* @return \OCP\GroupInterface[] * @return \OCP\GroupInterface[]
*/ */
public function getBackends() { public function getBackends() {
@ -221,7 +222,7 @@ class Manager extends PublicEmitter implements IGroupManager {
$this->emit('\OC\Group', 'preCreate', [$gid]); $this->emit('\OC\Group', 'preCreate', [$gid]);
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(Backend::CREATE_GROUP)) { if ($backend->implementsActions(Backend::CREATE_GROUP)) {
if($backend->createGroup($gid)) { if ($backend->createGroup($gid)) {
$group = $this->getGroupObject($gid); $group = $this->getGroupObject($gid);
$this->emit('\OC\Group', 'postCreate', [$group]); $this->emit('\OC\Group', 'postCreate', [$group]);
return $group; return $group;
@ -261,7 +262,7 @@ class Manager extends PublicEmitter implements IGroupManager {
* @param IUser|null $user * @param IUser|null $user
* @return \OC\Group\Group[] * @return \OC\Group\Group[]
*/ */
public function getUserGroups(IUser $user= null) { public function getUserGroups(IUser $user = null) {
if (!$user instanceof IUser) { if (!$user instanceof IUser) {
return []; return [];
} }
@ -296,6 +297,7 @@ class Manager extends PublicEmitter implements IGroupManager {
/** /**
* Checks if a userId is in the admin group * Checks if a userId is in the admin group
*
* @param string $userId * @param string $userId
* @return bool if admin * @return bool if admin
*/ */
@ -310,6 +312,7 @@ class Manager extends PublicEmitter implements IGroupManager {
/** /**
* Checks if a userId is in a group * Checks if a userId is in a group
*
* @param string $userId * @param string $userId
* @param string $group * @param string $group
* @return bool if in group * @return bool if in group
@ -320,28 +323,31 @@ class Manager extends PublicEmitter implements IGroupManager {
/** /**
* get a list of group ids for a user * get a list of group ids for a user
*
* @param IUser $user * @param IUser $user
* @return array with group ids * @return array with group ids
*/ */
public function getUserGroupIds(IUser $user) { public function getUserGroupIds(IUser $user) {
return array_map(function($value) { return array_map(function ($value) {
return (string) $value; return (string)$value;
}, array_keys($this->getUserGroups($user))); }, array_keys($this->getUserGroups($user)));
} }
/** /**
* get an array of groupid and displayName for a user * get an array of groupid and displayName for a user
*
* @param IUser $user * @param IUser $user
* @return array ['displayName' => displayname] * @return array ['displayName' => displayname]
*/ */
public function getUserGroupNames(IUser $user) { public function getUserGroupNames(IUser $user) {
return array_map(function($group) { return array_map(function ($group) {
return array('displayName' => $group->getDisplayName()); return array('displayName' => $group->getDisplayName());
}, $this->getUserGroups($user)); }, $this->getUserGroups($user));
} }
/** /**
* get a list of all display names in a group * get a list of all display names in a group
*
* @param string $gid * @param string $gid
* @param string $search * @param string $search
* @param int $limit * @param int $limit
@ -350,32 +356,32 @@ class Manager extends PublicEmitter implements IGroupManager {
*/ */
public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$group = $this->get($gid); $group = $this->get($gid);
if(is_null($group)) { if (is_null($group)) {
return []; return [];
} }
$search = trim($search); $search = trim($search);
$groupUsers = []; $groupUsers = [];
if(!empty($search)) { if (!empty($search)) {
// only user backends have the capability to do a complex search for users // only user backends have the capability to do a complex search for users
$searchOffset = 0; $searchOffset = 0;
$searchLimit = $limit * 100; $searchLimit = $limit * 100;
if($limit === -1) { if ($limit === -1) {
$searchLimit = 500; $searchLimit = 500;
} }
do { do {
$filteredUsers = $this->userManager->searchDisplayName($search, $searchLimit, $searchOffset); $filteredUsers = $this->userManager->searchDisplayName($search, $searchLimit, $searchOffset);
foreach($filteredUsers as $filteredUser) { foreach ($filteredUsers as $filteredUser) {
if($group->inGroup($filteredUser)) { if ($group->inGroup($filteredUser)) {
$groupUsers[]= $filteredUser; $groupUsers[] = $filteredUser;
} }
} }
$searchOffset += $searchLimit; $searchOffset += $searchLimit;
} while(count($groupUsers) < $searchLimit+$offset && count($filteredUsers) >= $searchLimit); } while (count($groupUsers) < $searchLimit + $offset && count($filteredUsers) >= $searchLimit);
if($limit === -1) { if ($limit === -1) {
$groupUsers = array_slice($groupUsers, $offset); $groupUsers = array_slice($groupUsers, $offset);
} else { } else {
$groupUsers = array_slice($groupUsers, $offset, $limit); $groupUsers = array_slice($groupUsers, $offset, $limit);
@ -385,7 +391,7 @@ class Manager extends PublicEmitter implements IGroupManager {
} }
$matchingUsers = []; $matchingUsers = [];
foreach($groupUsers as $groupUser) { foreach ($groupUsers as $groupUser) {
$matchingUsers[$groupUser->getUID()] = $groupUser->getDisplayName(); $matchingUsers[$groupUser->getUID()] = $groupUser->getDisplayName();
} }
return $matchingUsers; return $matchingUsers;