Add search, limit, offset parameters to usersInGroups()

This commit is contained in:
Michael Gapczynski 2012-08-11 16:21:09 -04:00
parent 4f1b3631ba
commit a1c88a3e39
6 changed files with 20 additions and 15 deletions

View File

@ -264,10 +264,10 @@ class OC_Group {
* @brief get a list of all users in a group
* @returns array with user ids
*/
public static function usersInGroup($gid){
public static function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$users=array();
foreach(self::$_usedBackends as $backend){
$users=array_merge($backend->usersInGroup($gid),$users);
$users = array_merge($backend->usersInGroup($gid, $search, $limit, $offset), $users);
}
return $users;
}
@ -277,10 +277,11 @@ class OC_Group {
* @param array $gids
* @returns array with user ids
*/
public static function usersInGroups($gids){
public static function usersInGroups($gids, $search = '', $limit = -1, $offset = 0) {
$users = array();
foreach($gids as $gid){
$users = array_merge(array_diff(self::usersInGroup($gid), $users), $users);
foreach ($gids as $gid) {
// TODO Need to apply limits to groups as total
$users = array_merge(array_diff(self::usersInGroup($gid, $search, $limit, $offset), $users), $users);
}
return $users;
}

View File

@ -122,7 +122,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
* @brief get a list of all users in a group
* @returns array with user ids
*/
public function usersInGroup($gid){
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
return array();
}

View File

@ -182,12 +182,16 @@ class OC_Group_Database extends OC_Group_Backend {
* @brief get a list of all users in a group
* @returns array with user ids
*/
public 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'];
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
if ($limit == -1) {
$query = OC_DB::prepare('SELECT uid FROM *PREFIX*group_user WHERE gid = ? AND uid LIKE ?');
} else {
$query = OC_DB::prepare('SELECT uid FROM *PREFIX*group_user WHERE gid = ? AND uid LIKE ? LIMIT '.$limit.' OFFSET '.$offset);
}
$result = $query->execute(array($gid, $search.'%'));
$users = array();
while ($row = $result->fetchRow()) {
$users[] = $row['uid'];
}
return $users;
}

View File

@ -149,7 +149,7 @@ class OC_Group_Dummy extends OC_Group_Backend {
* @brief get a list of all users in a group
* @returns array with user ids
*/
public function usersInGroup($gid){
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
if(isset($this->groups[$gid])){
return $this->groups[$gid];
}else{

View File

@ -104,6 +104,6 @@ abstract class OC_Group_Example {
* @brief get a list of all users in a group
* @returns array with user ids
*/
abstract public static function usersInGroup($gid);
abstract public static function usersInGroup($gid, $search = '', $limit = -1, $offset = 0);
}

View File

@ -71,6 +71,6 @@ interface OC_Group_Interface {
* @brief get a list of all users in a group
* @returns array with user ids
*/
public function usersInGroup($gid);
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0);
}