diff --git a/lib/private/group/backend.php b/lib/private/group/backend.php index 2e17b5d0b7f9f805b7e5d47572e21d558286f7a0..b0ed0d90d76bc59b278dea0fba15f7c0168fe0c9 100644 --- a/lib/private/group/backend.php +++ b/lib/private/group/backend.php @@ -34,6 +34,7 @@ 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_COUNT_USERS', 0x00100000); /** * Abstract base class for user management @@ -45,6 +46,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface { 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 d0974685ff623bad945e29003fc827c075dbb4df..3815dcff2e5c362a864f0126f5c9b6f9924390cc 100644 --- a/lib/private/group/database.php +++ b/lib/private/group/database.php @@ -211,6 +211,20 @@ 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 diff --git a/lib/private/group/dummy.php b/lib/private/group/dummy.php index da26e1b910e633b03437d2cf26a4de4defb7f1f4..94cbb607ad1157d27c9a0e3591a0192ec9269f5d 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 8d2aa87a788fc160c3e6fe4ad5f071ec1df93d83..9965d938ebb2670c9c5647f56ecafea1b1a1b183 100644 --- a/lib/private/group/group.php +++ b/lib/private/group/group.php @@ -186,6 +186,27 @@ class Group { return array_values($users); } + /** + * 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 *