[Pkg-owncloud-commits] [owncloud] 08/34: add optional countUsersInGroup method to group backends
David Prévot
taffit at moszumanska.debian.org
Thu Nov 13 19:37:12 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v6.0.6
in repository owncloud.
commit 01ce97f85f00fafd7641dcb459e20b4a827f2364
Author: Arthur Schiwon <blizzz at owncloud.com>
Date: Fri Apr 4 18:56:14 2014 +0200
add optional countUsersInGroup method to group backends
Conflicts:
lib/private/group/backend.php
lib/private/group/database.php
lib/private/group/dummy.php
---
lib/private/group/backend.php | 5 ++++-
lib/private/group/database.php | 39 +++++++++++++++++++++++++++++++++++++++
lib/private/group/dummy.php | 10 +++++++++-
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 11ec6c2..fd9a8d6 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 ff2c24a..d855ad4 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 8dad769..a502800 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 f10964d..9689ecb 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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list