User groups: Add filter by name in list - refs BT#17545

pull/3425/head
Angel Fernando Quiroz Campos 5 years ago
parent 4badc057ea
commit 843ca887e4
  1. 14
      main/admin/usergroups.php
  2. 4
      main/inc/ajax/model.ajax.php
  3. 46
      main/inc/lib/usergroup.lib.php

@ -33,10 +33,10 @@ $columns = [
//Column config
$column_model = [
['name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left'],
['name' => 'users', 'index' => 'users', 'width' => '15', 'align' => 'left'],
['name' => 'courses', 'index' => 'courses', 'width' => '15', 'align' => 'left'],
['name' => 'sessions', 'index' => 'sessions', 'width' => '15', 'align' => 'left'],
['name' => 'group_type', 'index' => 'group_type', 'width' => '15', 'align' => 'center'],
['name' => 'users', 'index' => 'users', 'width' => '15', 'align' => 'left', 'search' => 'false'],
['name' => 'courses', 'index' => 'courses', 'width' => '15', 'align' => 'left', 'search' => 'false'],
['name' => 'sessions', 'index' => 'sessions', 'width' => '15', 'align' => 'left', 'search' => 'false'],
['name' => 'group_type', 'index' => 'group_type', 'width' => '15', 'align' => 'center', 'search' => 'false'],
[
'name' => 'actions',
'index' => 'actions',
@ -44,6 +44,7 @@ $column_model = [
'align' => 'center',
'sortable' => 'false',
'formatter' => 'action_formatter',
'search' => 'false',
],
];
@ -194,6 +195,11 @@ Display::display_header();
true
);
?>
$('#usergroups').jqGrid(
'filterToolbar',
{stringResult: true, searchOnEnter: false, defaultSearch : "cn"}
);
});
</script>
<?php

@ -863,7 +863,7 @@ switch ($action) {
case 'get_usergroups':
$obj = new UserGroup();
$obj->protectScript();
$count = $obj->get_count();
$count = $obj->get_count($whereCondition);
break;
case 'get_usergroups_teacher':
$obj = new UserGroup();
@ -2177,7 +2177,7 @@ switch ($action) {
case 'get_usergroups':
$obj->protectScript();
$columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions'];
$result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
$result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit, $whereCondition);
break;
case 'get_extra_fields':
$obj = new ExtraField($type);

@ -195,11 +195,11 @@ class UserGroup extends Model
}
/**
* @param int $type
* @param string $extraWhereCondition
*
* @return int
*/
public function get_count()
public function get_count($extraWhereCondition = '')
{
$authorCondition = '';
@ -217,6 +217,7 @@ class UserGroup extends Model
INNER JOIN $this->access_url_rel_usergroup a
ON (u.id = a.usergroup_id)
WHERE access_url_id = $urlId $authorCondition
$extraWhereCondition
";
$result = Database::query($sql);
@ -230,6 +231,7 @@ class UserGroup extends Model
FROM {$this->table} a
WHERE 1 = 1
$authorCondition
AND $extraWhereCondition
";
$result = Database::query($sql);
if (Database::num_rows($result)) {
@ -1112,45 +1114,43 @@ class UserGroup extends Model
}
/**
* @param int $sidx
* @param int $sord
* @param int $start
* @param int $limit
* @param int $sidx
* @param int $sord
* @param int $start
* @param int $limit
* @param string $extraWhereCondition
*
* @return array
*/
public function getUsergroupsPagination($sidx, $sord, $start, $limit)
public function getUsergroupsPagination($sidx, $sord, $start, $limit, $extraWhereCondition = '')
{
$sord = in_array(strtolower($sord), ['asc', 'desc']) ? $sord : 'desc';
$start = (int) $start;
$limit = (int) $limit;
$sqlFrom = "{$this->table} u ";
$sqlWhere = '1 = 1 ';
if ($this->getUseMultipleUrl()) {
$urlId = api_get_current_access_url_id();
$from = $this->table." u
INNER JOIN {$this->access_url_rel_usergroup} a
ON (u.id = a.usergroup_id)";
$where = [' access_url_id = ?' => $urlId];
} else {
$from = $this->table.' u ';
$where = [];
$sqlFrom .= " INNER JOIN {$this->access_url_rel_usergroup} a ON (u.id = a.usergroup_id) ";
$sqlWhere .= " AND a.access_url_id = $urlId ";
}
if ($this->allowTeachers()) {
if (!api_is_platform_admin()) {
$userId = api_get_user_id();
$where = [' author_id = ?' => $userId];
$sqlWhere .= " AND author_id = $userId ";
}
}
$result = Database::select(
'u.*',
$from,
[
'where' => $where,
'order' => "name $sord",
'LIMIT' => "$start , $limit",
]
if ($extraWhereCondition) {
$sqlWhere .= " AND $extraWhereCondition ";
}
$result = Database::store_result(
Database::query("SELECT u.* FROM $sqlFrom WHERE $sqlWhere ORDER BY name $sord LIMIT $start, $limit")
);
$new_result = [];

Loading…
Cancel
Save