Add search, limit, and offset parameters to getUsers() and getGroups()

This commit is contained in:
Michael Gapczynski 2012-07-30 20:20:46 -04:00
parent ed71343df8
commit 2f1a990cad
9 changed files with 26 additions and 29 deletions

View File

@ -237,10 +237,10 @@ class OC_Group {
* *
* Returns a list with all groups * Returns a list with all groups
*/ */
public static function getGroups(){ public static function getGroups($search = '', $limit = 10, $offset = 0) {
$groups = array(); $groups = array();
foreach (self::$_usedBackends as $backend) { foreach (self::$_usedBackends as $backend) {
$groups=array_merge($backend->getGroups(),$groups); $groups = array_merge($backend->getGroups($search, $limit, $offset), $groups);
} }
asort($groups); asort($groups);
return $groups; return $groups;

View File

@ -105,7 +105,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
* *
* Returns a list with all groups * Returns a list with all groups
*/ */
public function getGroups(){ public function getGroups($search = '', $limit = 10, $offset = 0) {
return array(); return array();
} }

View File

@ -164,15 +164,13 @@ class OC_Group_Database extends OC_Group_Backend {
* *
* Returns a list with all groups * Returns a list with all groups
*/ */
public function getGroups(){ public function getGroups($search = '', $limit = 10, $offset = 0) {
$query = OC_DB::prepare( "SELECT gid FROM `*PREFIX*groups`" ); $query = OC_DB::prepare('SELECT gid FROM *PREFIX*groups WHERE gid LIKE ? LIMIT '.$limit.' OFFSET '.$offset);
$result = $query->execute(); $result = $query->execute(array($search.'%'));
$groups = array(); $groups = array();
while ($row = $result->fetchRow()) { while ($row = $result->fetchRow()) {
$groups[] = $row["gid"]; $groups[] = $row['gid'];
} }
return $groups; return $groups;
} }

View File

@ -58,7 +58,7 @@ interface OC_Group_Interface {
* *
* Returns a list with all groups * Returns a list with all groups
*/ */
public function getGroups(); public function getGroups($search = '', $limit = 10, $offset = 0);
/** /**
* check if a group exists * check if a group exists

View File

@ -51,7 +51,7 @@ class User {
* *
* Get a list of all users. * Get a list of all users.
*/ */
public static function getUsers(){ public static function getUsers($search = '', $limit = 10, $offset = 0) {
return \OC_USER::getUsers(); return \OC_USER::getUsers();
} }

View File

@ -337,10 +337,10 @@ class OC_User {
* *
* Get a list of all users. * Get a list of all users.
*/ */
public static function getUsers(){ public static function getUsers($search = '', $limit = 10, $offset = 0) {
$users = array(); $users = array();
foreach (self::$_usedBackends as $backend) { foreach (self::$_usedBackends as $backend) {
$backendUsers=$backend->getUsers(); $backendUsers = $backend->getUsers($search, $limit, $offset);
if (is_array($backendUsers)) { if (is_array($backendUsers)) {
$users = array_merge($users, $backendUsers); $users = array_merge($users, $backendUsers);
} }

View File

@ -97,7 +97,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
* *
* Get a list of all users. * Get a list of all users.
*/ */
public function getUsers(){ public function getUsers($search = '', $limit = 10, $offset = 0) {
return array(); return array();
} }

View File

@ -154,13 +154,12 @@ class OC_User_Database extends OC_User_Backend {
* *
* Get a list of all users. * Get a list of all users.
*/ */
public function getUsers(){ public function getUsers($search = '', $limit = 10, $offset = 0) {
$query = OC_DB::prepare( "SELECT uid FROM *PREFIX*users" ); $query = OC_DB::prepare('SELECT uid FROM *PREFIX*users WHERE uid LIKE ? LIMIT '.$limit.' OFFSET '.$offset);
$result = $query->execute(); $result = $query->execute(array($search.'%'));
$users = array(); $users = array();
while ($row = $result->fetchRow()) { while ($row = $result->fetchRow()) {
$users[] = $row["uid"]; $users[] = $row['uid'];
} }
return $users; return $users;
} }

View File

@ -48,7 +48,7 @@ interface OC_User_Interface {
* *
* Get a list of all users. * Get a list of all users.
*/ */
public function getUsers(); public function getUsers($search = '', $limit = 10, $offset = 0);
/** /**
* @brief check if a user exists * @brief check if a user exists