diff options
author | Bart Visscher <bartv@thisnet.nl> | 2014-05-07 19:54:38 +0400 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2014-05-07 19:54:38 +0400 |
commit | f569c721a64486d0e7c7e307ed77ac0caed2dc2d (patch) | |
tree | df7b3399a858ffdae6bd6e66616746efbcee24bc /lib/private/group | |
parent | 47d70da2f5cb55ad47023b061b68062dd8b8d8e2 (diff) | |
parent | 254fa5eb22efa5ba572702064377a6ad9eec9a53 (diff) |
Merge branch 'master' into optimize-startup-queries
Conflicts:
apps/files_sharing/lib/sharedstorage.php
tests/lib/group/manager.php
removed hasFilesSharedWith from lib/public/share.php and
sharedstorage.php to fix merge
Diffstat (limited to 'lib/private/group')
-rw-r--r-- | lib/private/group/backend.php | 24 | ||||
-rw-r--r-- | lib/private/group/database.php | 23 | ||||
-rw-r--r-- | lib/private/group/dummy.php | 10 | ||||
-rw-r--r-- | lib/private/group/group.php | 39 | ||||
-rw-r--r-- | lib/private/group/manager.php | 40 |
5 files changed, 75 insertions, 61 deletions
diff --git a/lib/private/group/backend.php b/lib/private/group/backend.php index 2e17b5d0b7f..cc61fce1615 100644 --- a/lib/private/group/backend.php +++ b/lib/private/group/backend.php @@ -33,7 +33,8 @@ define('OC_GROUP_BACKEND_CREATE_GROUP', 0x00000001); define('OC_GROUP_BACKEND_DELETE_GROUP', 0x00000010); define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00000100); define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00001000); -define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); +define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); //OBSOLETE +define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000); /** * Abstract base class for user management @@ -44,7 +45,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface { OC_GROUP_BACKEND_DELETE_GROUP => 'deleteGroup', OC_GROUP_BACKEND_ADD_TO_GROUP => 'addToGroup', OC_GROUP_BACKEND_REMOVE_FROM_GOUP => 'removeFromGroup', - OC_GROUP_BACKEND_GET_DISPLAYNAME => 'displayNamesInGroup', + OC_GROUP_BACKEND_COUNT_USERS => 'countUsersInGroup', ); /** @@ -135,23 +136,4 @@ abstract class OC_Group_Backend implements OC_Group_Interface { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { return array(); } - - /** - * @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) { - $displayNames = array(); - $users = $this->usersInGroup($gid, $search, $limit, $offset); - foreach ($users as $user) { - $displayNames[$user] = $user; - } - - return $displayNames; - } - } diff --git a/lib/private/group/database.php b/lib/private/group/database.php index d0974685ff6..df0d84d0d2a 100644 --- a/lib/private/group/database.php +++ b/lib/private/group/database.php @@ -212,28 +212,17 @@ class OC_Group_Database extends OC_Group_Backend { } /** - * @brief get a list of all display names in a group + * @brief get the number of all users matching the search string 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) + * @return int | false */ - public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { - $displayNames = array(); - - $stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname`' - .' FROM `*PREFIX*users`' - .' INNER JOIN `*PREFIX*group_user` ON `*PREFIX*group_user`.`uid` = `*PREFIX*users`.`uid`' - .' WHERE `gid` = ? AND `*PREFIX*group_user`.`uid` LIKE ?', - $limit, - $offset); + public function countUsersInGroup($gid, $search = '') { + $stmt = OC_DB::prepare('SELECT COUNT(`uid`) AS `count` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?'); $result = $stmt->execute(array($gid, $search.'%')); - $users = array(); - while ($row = $result->fetchRow()) { - $displayName = trim($row['displayname'], ' '); - $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName; - } - return $displayNames; + return $result->fetchOne(); } + } diff --git a/lib/private/group/dummy.php b/lib/private/group/dummy.php index da26e1b910e..94cbb607ad1 100644 --- a/lib/private/group/dummy.php +++ b/lib/private/group/dummy.php @@ -157,4 +157,14 @@ class OC_Group_Dummy extends OC_Group_Backend { } } + /** + * @brief get the number of all users in a group + * @returns int | bool + */ + public function countUsersInGroup($gid, $search = '', $limit = -1, $offset = 0) { + if(isset($this->groups[$gid])) { + return count($this->groups[$gid]); + } + } + } diff --git a/lib/private/group/group.php b/lib/private/group/group.php index 8d2aa87a788..7593bb68d1a 100644 --- a/lib/private/group/group.php +++ b/lib/private/group/group.php @@ -172,12 +172,6 @@ class Group { $users = array(); foreach ($this->backends as $backend) { $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); - if (!is_null($limit)) { - $limit -= count($userIds); - } - if (!is_null($offset)) { - $offset -= count($userIds); - } $users += $this->getVerifiedUsers($userIds); if (!is_null($limit) and $limit <= 0) { return array_values($users); @@ -187,6 +181,27 @@ class Group { } /** + * returns the number of users matching the search string + * + * @param string $search + * @return int | bool + */ + public function count($search) { + $users = false; + foreach ($this->backends as $backend) { + if($backend->implementsActions(OC_GROUP_BACKEND_COUNT_USERS)) { + if($users === false) { + //we could directly add to a bool variable, but this would + //be ugly + $users = 0; + } + $users += $backend->countUsersInGroup($this->gid, $search); + } + } + return $users; + } + + /** * search for users in the group by displayname * * @param string $search @@ -197,17 +212,7 @@ class Group { public function searchDisplayName($search, $limit = null, $offset = null) { $users = array(); foreach ($this->backends as $backend) { - if ($backend->implementsActions(OC_GROUP_BACKEND_GET_DISPLAYNAME)) { - $userIds = array_keys($backend->displayNamesInGroup($this->gid, $search, $limit, $offset)); - } else { - $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); - } - if (!is_null($limit)) { - $limit -= count($userIds); - } - if (!is_null($offset)) { - $offset -= count($userIds); - } + $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); $users = $this->getVerifiedUsers($userIds); if (!is_null($limit) and $limit <= 0) { return array_values($users); diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index 151b185dbf7..40c6074b2ac 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -153,12 +153,6 @@ class Manager extends PublicEmitter { $groups = array(); foreach ($this->backends as $backend) { $groupIds = $backend->getGroups($search, $limit, $offset); - if (!is_null($limit)) { - $limit -= count($groupIds); - } - if (!is_null($offset)) { - $offset -= count($groupIds); - } foreach ($groupIds as $groupId) { $groups[$groupId] = $this->get($groupId); } @@ -188,4 +182,38 @@ class Manager extends PublicEmitter { $this->cachedUserGroups[$uid] = array_values($groups); return $this->cachedUserGroups[$uid]; } + + /** + * @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); + $search = trim($search); + if(!empty($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; + } } |