@@ -195,11 +195,11 @@ public function getUserGroupUsers($id, $getCount = false, $start = 0, $limit = 0
195195 }
196196
197197 /**
198- * @param int $type
198+ * @param string $extraWhereCondition
199199 *
200200 * @return int
201201 */
202- public function get_count ()
202+ public function get_count ($ extraWhereCondition = '' )
203203 {
204204 $ authorCondition = '' ;
205205
@@ -217,6 +217,7 @@ public function get_count()
217217 INNER JOIN $ this ->access_url_rel_usergroup a
218218 ON (u.id = a.usergroup_id)
219219 WHERE access_url_id = $ urlId $ authorCondition
220+ $ extraWhereCondition
220221 " ;
221222
222223 $ result = Database::query ($ sql );
@@ -230,6 +231,7 @@ public function get_count()
230231 FROM {$ this ->table } a
231232 WHERE 1 = 1
232233 $ authorCondition
234+ AND $ extraWhereCondition
233235 " ;
234236 $ result = Database::query ($ sql );
235237 if (Database::num_rows ($ result )) {
@@ -1112,45 +1114,43 @@ public function allowTeachers()
11121114 }
11131115
11141116 /**
1115- * @param int $sidx
1116- * @param int $sord
1117- * @param int $start
1118- * @param int $limit
1117+ * @param int $sidx
1118+ * @param int $sord
1119+ * @param int $start
1120+ * @param int $limit
1121+ * @param string $extraWhereCondition
11191122 *
11201123 * @return array
11211124 */
1122- public function getUsergroupsPagination ($ sidx , $ sord , $ start , $ limit )
1125+ public function getUsergroupsPagination ($ sidx , $ sord , $ start , $ limit, $ extraWhereCondition = '' )
11231126 {
11241127 $ sord = in_array (strtolower ($ sord ), ['asc ' , 'desc ' ]) ? $ sord : 'desc ' ;
11251128
11261129 $ start = (int ) $ start ;
11271130 $ limit = (int ) $ limit ;
1131+
1132+ $ sqlFrom = "{$ this ->table } u " ;
1133+ $ sqlWhere = '1 = 1 ' ;
1134+
11281135 if ($ this ->getUseMultipleUrl ()) {
11291136 $ urlId = api_get_current_access_url_id ();
1130- $ from = $ this ->table ." u
1131- INNER JOIN {$ this ->access_url_rel_usergroup } a
1132- ON (u.id = a.usergroup_id) " ;
1133- $ where = [' access_url_id = ? ' => $ urlId ];
1134- } else {
1135- $ from = $ this ->table .' u ' ;
1136- $ where = [];
1137+ $ sqlFrom .= " INNER JOIN {$ this ->access_url_rel_usergroup } a ON (u.id = a.usergroup_id) " ;
1138+ $ sqlWhere .= " AND a.access_url_id = $ urlId " ;
11371139 }
11381140
11391141 if ($ this ->allowTeachers ()) {
11401142 if (!api_is_platform_admin ()) {
11411143 $ userId = api_get_user_id ();
1142- $ where = [ ' author_id = ? ' => $ userId] ;
1144+ $ sqlWhere .= " AND author_id = $ userId " ;
11431145 }
11441146 }
11451147
1146- $ result = Database::select (
1147- 'u.* ' ,
1148- $ from ,
1149- [
1150- 'where ' => $ where ,
1151- 'order ' => "name $ sord " ,
1152- 'LIMIT ' => "$ start , $ limit " ,
1153- ]
1148+ if ($ extraWhereCondition ) {
1149+ $ sqlWhere .= " AND $ extraWhereCondition " ;
1150+ }
1151+
1152+ $ result = Database::store_result (
1153+ Database::query ("SELECT u.* FROM $ sqlFrom WHERE $ sqlWhere ORDER BY name $ sord LIMIT $ start, $ limit " )
11541154 );
11551155
11561156 $ new_result = [];
@@ -1320,7 +1320,7 @@ public function getUserGroupNotInList($list)
13201320 public function save ($ params , $ show_query = false )
13211321 {
13221322 $ params ['updated_at ' ] = $ params ['created_at ' ] = api_get_utc_datetime ();
1323- $ params ['group_type ' ] = isset ($ params ['group_type ' ]) ? self ::SOCIAL_CLASS : self ::NORMAL_CLASS ;
1323+ $ params ['group_type ' ] = ! empty ($ params ['group_type ' ]) ? self ::SOCIAL_CLASS : self ::NORMAL_CLASS ;
13241324 $ params ['allow_members_leave_group ' ] = isset ($ params ['allow_members_leave_group ' ]) ? 1 : 0 ;
13251325
13261326 $ groupExists = $ this ->usergroup_exists (trim ($ params ['name ' ]));
@@ -1365,7 +1365,7 @@ public function save($params, $show_query = false)
13651365 public function update ($ values , $ showQuery = false )
13661366 {
13671367 $ values ['updated_on ' ] = api_get_utc_datetime ();
1368- $ values ['group_type ' ] = isset ($ values ['group_type ' ]) ? self ::SOCIAL_CLASS : self ::NORMAL_CLASS ;
1368+ $ values ['group_type ' ] = ! empty ($ values ['group_type ' ]) ? self ::SOCIAL_CLASS : self ::NORMAL_CLASS ;
13691369 $ values ['allow_members_leave_group ' ] = isset ($ values ['allow_members_leave_group ' ]) ? 1 : 0 ;
13701370
13711371 if (isset ($ values ['id ' ])) {
0 commit comments