Skip to content

Commit 6c4d1d4

Browse files
authored
Merge pull request #3425 from AngelFQC/BT17545
User groups: Add search in list - refs BT#17545
2 parents 2900dfa + 6c9097b commit 6c4d1d4

File tree

5 files changed

+41
-34
lines changed

5 files changed

+41
-34
lines changed

app/Resources/public/css/base.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,8 @@ div.admin_section h4 {
24282428
}
24292429

24302430
.ui-search-table .ui-search-input input {
2431-
height: 25px;
2431+
border: 1px solid #CCC;
2432+
margin: 2px auto;
24322433
}
24332434

24342435
.exercise_overview_options {

main/admin/usergroups.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@
3333
//Column config
3434
$column_model = [
3535
['name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left'],
36-
['name' => 'users', 'index' => 'users', 'width' => '15', 'align' => 'left'],
37-
['name' => 'courses', 'index' => 'courses', 'width' => '15', 'align' => 'left'],
38-
['name' => 'sessions', 'index' => 'sessions', 'width' => '15', 'align' => 'left'],
39-
['name' => 'group_type', 'index' => 'group_type', 'width' => '15', 'align' => 'center'],
36+
['name' => 'users', 'index' => 'users', 'width' => '15', 'align' => 'left', 'search' => 'false'],
37+
['name' => 'courses', 'index' => 'courses', 'width' => '15', 'align' => 'left', 'search' => 'false'],
38+
['name' => 'sessions', 'index' => 'sessions', 'width' => '15', 'align' => 'left', 'search' => 'false'],
39+
['name' => 'group_type', 'index' => 'group_type', 'width' => '15', 'align' => 'center', 'search' => 'false'],
4040
[
4141
'name' => 'actions',
4242
'index' => 'actions',
4343
'width' => '20',
4444
'align' => 'center',
4545
'sortable' => 'false',
4646
'formatter' => 'action_formatter',
47+
'search' => 'false',
4748
],
4849
];
4950

@@ -194,6 +195,11 @@
194195
true
195196
);
196197
?>
198+
199+
$('#usergroups').jqGrid(
200+
'filterToolbar',
201+
{stringResult: true, searchOnEnter: false, defaultSearch : "cn"}
202+
);
197203
});
198204
</script>
199205
<?php

main/inc/ajax/model.ajax.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ function getWhereClause($col, $oper, $val)
863863
case 'get_usergroups':
864864
$obj = new UserGroup();
865865
$obj->protectScript();
866-
$count = $obj->get_count();
866+
$count = $obj->get_count($whereCondition);
867867
break;
868868
case 'get_usergroups_teacher':
869869
$obj = new UserGroup();
@@ -2177,7 +2177,7 @@ function getWhereClause($col, $oper, $val)
21772177
case 'get_usergroups':
21782178
$obj->protectScript();
21792179
$columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions'];
2180-
$result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
2180+
$result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit, $whereCondition);
21812181
break;
21822182
case 'get_extra_fields':
21832183
$obj = new ExtraField($type);

main/inc/lib/array.lib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ function msort($array, $id = 'id', $order = 'desc')
5252
$index = 0;
5353
foreach ($array as $item) {
5454
if ('desc' == $order) {
55-
if ($item[$id] < $array[$lowest_id][$id]) {
55+
if (strip_tags($item[$id]) < strip_tags($array[$lowest_id][$id])) {
5656
$lowest_id = $index;
5757
}
5858
} else {
59-
if (isset($item[$id]) && $item[$id] > $array[$lowest_id][$id]) {
59+
if (isset($item[$id]) && strip_tags($item[$id]) > strip_tags($array[$lowest_id][$id])) {
6060
$lowest_id = $index;
6161
}
6262
}

main/inc/lib/usergroup.lib.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)