From 031b5882554266ab709299bb157f66c18b7e7e34 Mon Sep 17 00:00:00 2001 From: Patrick Valsecchi Date: Tue, 19 Dec 2017 20:13:03 +0100 Subject: [PATCH 1/2] Add countUsersInGroup --- group_sql.php | 15 +++++++++++++++ lib/helper.php | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/group_sql.php b/group_sql.php index 641beff..e1c1a26 100644 --- a/group_sql.php +++ b/group_sql.php @@ -75,5 +75,20 @@ class OC_GROUP_SQL extends \OC_Group_Backend implements \OCP\GroupInterface } return $users; } + + public function countUsersInGroup($gid, $search = '') { + if(empty($this -> settings['sql_group_table'])) + { + return 0; + } + $search = "%".$search."%"; + $count = $this -> helper -> runQuery('countUsersInGroup', array('gid' => $gid, 'search' => $search)); + if($count === false) + { + return 0; + } else { + return intval(reset($count)); + } + } } ?> diff --git a/lib/helper.php b/lib/helper.php index 18177a3..5de5d6a 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -188,6 +188,10 @@ class Helper { case 'getGroupUsers': $query = "SELECT distinct ".$this->settings['col_group_username']." FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_name']." = :gid"; break; + + case 'countUsersInGroup': + $query = "SELECT count(".$this->settings['col_group_username'].") FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_name']." = :gid AND ".$this->settings['col_group_username']." LIKE :search"; + break; } if(isset($limits['limit']) && $limits['limit'] !== null) From 96c9bfeba8c924fb0d8bb709518ea1d04d41331b Mon Sep 17 00:00:00 2001 From: Patrick Valsecchi Date: Tue, 19 Dec 2017 20:21:06 +0100 Subject: [PATCH 2/2] Better getGroups implementation --- group_sql.php | 5 +++-- lib/helper.php | 2 +- user_sql.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/group_sql.php b/group_sql.php index e1c1a26..08c8d76 100644 --- a/group_sql.php +++ b/group_sql.php @@ -42,8 +42,9 @@ class OC_GROUP_SQL extends \OC_Group_Backend implements \OCP\GroupInterface if(empty($this -> settings['sql_group_table'])) { return []; - } - $rows = $this -> helper -> runQuery('getGroups', array(), false, true); + } + $search = "%".$search."%"; + $rows = $this -> helper -> runQuery('getGroups', array('search' => $search), false, true, array('limit' => $limit, 'offset' => $offset)); if($rows === false) { return []; diff --git a/lib/helper.php b/lib/helper.php index 5de5d6a..0074f1d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -182,7 +182,7 @@ class Helper { break; case 'getGroups': - $query = "SELECT distinct ".$this->settings['col_group_name']." FROM ".$this->settings['sql_group_table']; + $query = "SELECT distinct ".$this->settings['col_group_name']." FROM ".$this->settings['sql_group_table']." WHERE ".$this->settings['col_group_name']." LIKE :search"; break; case 'getGroupUsers': diff --git a/user_sql.php b/user_sql.php index cfb8404..4186b33 100644 --- a/user_sql.php +++ b/user_sql.php @@ -404,7 +404,7 @@ class OC_USER_SQL extends \OC_User_Backend implements \OCP\IUserBackend, \OCP\Us } else { - $search = "%".$this -> doUserDomainMapping("")."%"; + $search = "%".$this -> doUserDomainMapping("")."%"; } $rows = $this -> helper -> runQuery('getUsers', array('search' => $search), false, true, array('limit' => $limit, 'offset' => $offset));