diff options
author | blizzz <blizzz@owncloud.com> | 2014-07-01 14:37:09 +0200 |
---|---|---|
committer | blizzz <blizzz@owncloud.com> | 2014-07-01 14:37:09 +0200 |
commit | 616f9b1e03b7939605ec233f7af5cc78b0be9fde (patch) | |
tree | 70db45859bf3662302a012323bb0e1bfac2344a6 /lib | |
parent | 16ce23d19df352cd2653387bf00a0e210016d2f2 (diff) | |
parent | 16275eca845f7bb7c4872f1120f76177f593a693 (diff) | |
download | nextcloud-server-616f9b1e03b7939605ec233f7af5cc78b0be9fde.tar.gz nextcloud-server-616f9b1e03b7939605ec233f7af5cc78b0be9fde.zip |
Merge pull request #9156 from owncloud/solve-8959
search term for users and groups may occur anywhere in the name or displ...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/group/database.php | 12 | ||||
-rw-r--r-- | lib/private/group/dummy.php | 33 | ||||
-rw-r--r-- | lib/private/user/database.php | 4 | ||||
-rw-r--r-- | lib/private/user/dummy.php | 11 |
4 files changed, 50 insertions, 10 deletions
diff --git a/lib/private/group/database.php b/lib/private/group/database.php index baaf2cf2739..b7148f38fe3 100644 --- a/lib/private/group/database.php +++ b/lib/private/group/database.php @@ -169,7 +169,7 @@ class OC_Group_Database extends OC_Group_Backend { */ public function getGroups($search = '', $limit = null, $offset = null) { $stmt = OC_DB::prepare('SELECT `gid` FROM `*PREFIX*groups` WHERE `gid` LIKE ?', $limit, $offset); - $result = $stmt->execute(array($search.'%')); + $result = $stmt->execute(array('%' . $search . '%')); $groups = array(); while ($row = $result->fetchRow()) { $groups[] = $row['gid']; @@ -203,7 +203,7 @@ class OC_Group_Database extends OC_Group_Backend { $stmt = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?', $limit, $offset); - $result = $stmt->execute(array($gid, $search.'%')); + $result = $stmt->execute(array($gid, '%'.$search.'%')); $users = array(); while ($row = $result->fetchRow()) { $users[] = $row['uid']; @@ -220,8 +220,12 @@ class OC_Group_Database extends OC_Group_Backend { */ 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(); + $result = $stmt->execute(array($gid, '%' . $search . '%')); + $count = $result->fetchOne(); + if($count !== false) { + $count = intval($count); + } + return $count; } } diff --git a/lib/private/group/dummy.php b/lib/private/group/dummy.php index e48c6a0e266..4af18b267bc 100644 --- a/lib/private/group/dummy.php +++ b/lib/private/group/dummy.php @@ -143,7 +143,16 @@ class OC_Group_Dummy extends OC_Group_Backend { * @return array an array of group names */ public function getGroups($search = '', $limit = -1, $offset = 0) { - return array_keys($this->groups); + if(empty($search)) { + return array_keys($this->groups); + } + $result = array(); + foreach(array_keys($this->groups) as $group) { + if(stripos($group, $search) !== false) { + $result[] = $group; + } + } + return $result; } /** @@ -156,7 +165,16 @@ class OC_Group_Dummy extends OC_Group_Backend { */ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { if(isset($this->groups[$gid])) { - return $this->groups[$gid]; + if(empty($search)) { + return $this->groups[$gid]; + } + $result = array(); + foreach($this->groups[$gid] as $user) { + if(stripos($user, $search) !== false) { + $result[] = $user; + } + } + return $result; }else{ return array(); } @@ -172,7 +190,16 @@ class OC_Group_Dummy extends OC_Group_Backend { */ public function countUsersInGroup($gid, $search = '', $limit = -1, $offset = 0) { if(isset($this->groups[$gid])) { - return count($this->groups[$gid]); + if(empty($search)) { + return count($this->groups[$gid]); + } + $count = 0; + foreach($this->groups[$gid] as $user) { + if(stripos($user, $search) !== false) { + $count++; + } + } + return $count; } } diff --git a/lib/private/user/database.php b/lib/private/user/database.php index d9263f6b5de..e9844f0f79c 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -158,7 +158,7 @@ class OC_User_Database extends OC_User_Backend { $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`' . ' WHERE LOWER(`displayname`) LIKE LOWER(?) OR ' . 'LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); - $result = $query->execute(array($search . '%', $search . '%')); + $result = $query->execute(array('%' . $search . '%', '%' . $search . '%')); $users = array(); while ($row = $result->fetchRow()) { $displayNames[$row['uid']] = $row['displayname']; @@ -232,7 +232,7 @@ class OC_User_Database extends OC_User_Backend { */ public function getUsers($search = '', $limit = null, $offset = null) { $query = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); - $result = $query->execute(array($search . '%')); + $result = $query->execute(array('%' . $search . '%')); $users = array(); while ($row = $result->fetchRow()) { $users[] = $row['uid']; diff --git a/lib/private/user/dummy.php b/lib/private/user/dummy.php index 776168048f6..dbcbb2a46f7 100644 --- a/lib/private/user/dummy.php +++ b/lib/private/user/dummy.php @@ -105,7 +105,16 @@ class OC_User_Dummy extends OC_User_Backend { * Get a list of all users. */ public function getUsers($search = '', $limit = null, $offset = null) { - return array_keys($this->users); + if(empty($search)) { + return array_keys($this->users); + } + $result = array(); + foreach(array_keys($this->users) as $user) { + if(stripos($user, $search) !== false) { + $result[] = $user; + } + } + return $result; } /** |