summaryrefslogtreecommitdiffstats
path: root/lib/group
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-08-11 10:11:44 +0200
committerRobin Appelman <icewind1991@gmail.com>2011-08-11 10:12:17 +0200
commitbfd72501a19c4352b2a9f220c3f2dfac69346b61 (patch)
treed07ae35302b38b27ca4c166c5ac443e36c1d7d19 /lib/group
parent110f96df78f1ba4074df59a6c13025dc69a6b26f (diff)
downloadnextcloud-server-bfd72501a19c4352b2a9f220c3f2dfac69346b61.tar.gz
nextcloud-server-bfd72501a19c4352b2a9f220c3f2dfac69346b61.zip
add OC_Group::usersInGroup() to get a list of all users in a group
Diffstat (limited to 'lib/group')
-rw-r--r--lib/group/backend.php6
-rw-r--r--lib/group/database.php22
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/group/backend.php b/lib/group/backend.php
index ebee8aacb91..43f94e7ea1a 100644
--- a/lib/group/backend.php
+++ b/lib/group/backend.php
@@ -93,4 +93,10 @@ abstract class OC_Group_Backend {
* Returns a list with all groups
*/
public static function getGroups(){}
+
+ /**
+ * @brief get a list of all users in a group
+ * @returns array with user ids
+ */
+ public static function usersInGroup($gid){}
}
diff --git a/lib/group/database.php b/lib/group/database.php
index 6ca80b93985..8a9fc53d39f 100644
--- a/lib/group/database.php
+++ b/lib/group/database.php
@@ -53,7 +53,7 @@ class OC_Group_Database extends OC_Group_Backend {
*/
public static function createGroup( $gid ){
// Check for existence
- $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*groups` WHERE gid = ?" );
+ $query = OC_DB::prepare( "SELECT gid FROM `*PREFIX*groups` WHERE gid = ?" );
$result = $query->execute( array( $gid ));
if( $result->numRows() > 0 ){
@@ -98,7 +98,7 @@ class OC_Group_Database extends OC_Group_Backend {
*/
public static function inGroup( $uid, $gid ){
// check
- $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE gid = ? AND uid = ?" );
+ $query = OC_DB::prepare( "SELECT uid FROM `*PREFIX*group_user` WHERE gid = ? AND uid = ?" );
$result = $query->execute( array( $gid, $uid ));
return $result->numRows() > 0 ? true : false;
@@ -146,7 +146,7 @@ class OC_Group_Database extends OC_Group_Backend {
*/
public static function getUserGroups( $uid ){
// No magic!
- $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*group_user` WHERE uid = ?" );
+ $query = OC_DB::prepare( "SELECT gid FROM `*PREFIX*group_user` WHERE uid = ?" );
$result = $query->execute( array( $uid ));
$groups = array();
@@ -164,7 +164,7 @@ class OC_Group_Database extends OC_Group_Backend {
* Returns a list with all groups
*/
public static function getGroups(){
- $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*groups`" );
+ $query = OC_DB::prepare( "SELECT gid FROM `*PREFIX*groups`" );
$result = $query->execute();
$groups = array();
@@ -174,4 +174,18 @@ class OC_Group_Database extends OC_Group_Backend {
return $groups;
}
+
+ /**
+ * @brief get a list of all users in a group
+ * @returns array with user ids
+ */
+ public static function usersInGroup($gid){
+ $query=OC_DB::prepare('SELECT uid FROM *PREFIX*group_user WHERE gid=?');
+ $users=array();
+ $result=$query->execute(array($gid));
+ while($row=$result->fetchRow()){
+ $users[]=$row['uid'];
+ }
+ return $users;
+ }
}