diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-04-04 20:56:14 +0400 |
---|---|---|
committer | Simon Vocella <voxsim@gmail.com> | 2014-09-25 00:23:13 +0400 |
commit | 01ce97f85f00fafd7641dcb459e20b4a827f2364 (patch) | |
tree | c0339d8fe2efbab70ae47e46d6cad6d9103c9fc8 /lib | |
parent | 03694be08a95d2a213cd97f39f860a87d7139fb9 (diff) |
add optional countUsersInGroup method to group backends
Conflicts:
lib/private/group/backend.php
lib/private/group/database.php
lib/private/group/dummy.php
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/group/backend.php | 5 | ||||
-rw-r--r-- | lib/private/group/database.php | 39 | ||||
-rw-r--r-- | lib/private/group/dummy.php | 10 | ||||
-rw-r--r-- | lib/private/group/group.php | 21 |
4 files changed, 73 insertions, 2 deletions
diff --git a/lib/private/group/backend.php b/lib/private/group/backend.php index 11ec6c2920d..fd9a8d61c12 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); //OBSOLETE +define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); +define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000); /** * Abstract base class for user management @@ -44,6 +45,8 @@ 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', ); /** diff --git a/lib/private/group/database.php b/lib/private/group/database.php index ff2c24ae9d7..d855ad4b349 100644 --- a/lib/private/group/database.php +++ b/lib/private/group/database.php @@ -211,4 +211,43 @@ class OC_Group_Database extends OC_Group_Backend { return $users; } + /** + * @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 int | false + */ + 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.'%')); + return $result->fetchOne(); + } + + /** + * @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(); + + $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); + $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; + } } diff --git a/lib/private/group/dummy.php b/lib/private/group/dummy.php index 8dad769f9c6..a502800b16a 100644 --- a/lib/private/group/dummy.php +++ b/lib/private/group/dummy.php @@ -175,6 +175,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 f10964dfff2..9689ecb08e5 100644 --- a/lib/private/group/group.php +++ b/lib/private/group/group.php @@ -181,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(method_exists($backend, 'countUsersInGroup')) { + 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 |