Commit b6cafd85 authored by Nigel McNie's avatar Nigel McNie
Browse files

Increase the limit of users shown on the admin/staff pages to 250, sort both columns by lastname.

Previously, the 'curren staff/admins' columns were sorted by nothing at all.
(cherry picked from commit cff21007)
parent 5224d28d
......@@ -52,6 +52,11 @@ $form = array(
'filter' => false,
'lefttitle' => get_string('potentialadmins', 'admin'),
'righttitle' => get_string('currentadmins', 'admin'),
'searchparams' => array(
'query' => '',
'limit' => 250,
'orderby' => 'lastname',
),
'rules' => array(
'required' => true
)
......
......@@ -50,7 +50,12 @@ $form = array(
'defaultvalue' => $staffusers,
'filter' => false,
'lefttitle' => get_string('potentialstaff', 'admin'),
'righttitle' => get_string('currentstaff', 'admin')
'righttitle' => get_string('currentstaff', 'admin'),
'searchparams' => array(
'query' => '',
'limit' => 250,
'orderby' => 'lastname',
),
),
'submit' => array(
'type' => 'submit',
......
......@@ -44,13 +44,19 @@ $offset = param_integer('offset', 0);
$allfields = param_boolean('allfields');
$group = param_integer('group', 0);
$includeadmins = param_boolean('includeadmins', true);
$orderby = param_variable('orderby', 'firstname');
$options = array(
'orderby' => $orderby,
);
if ($group) {
$data = array('group' => $group, 'includeadmins' => $includeadmins);
$data = search_user($query, $limit, $offset, $data);
$options['group'] = $group;
$options['includeadmins'] = $includeadmins;
$data = search_user($query, $limit, $offset, $options);
}
else {
$data = search_user($query, $limit, $offset);
$data = search_user($query, $limit, $offset, $options);
}
json_headers();
......
......@@ -47,7 +47,8 @@ function pieform_element_userlist(Pieform $form, $element) {
}
if (is_array($value) && count($value)) {
$members = get_records_select_assoc('usr','id IN (' . join(',',$value) . ')', null, '', 'id,username,firstname,lastname,preferredname,staff');
$orderby = (isset($element['searchparams']['orderby']) && $element['searchparams']['orderby'] == 'lastname') ? 'lastname,firstname,id' : 'firstname,lastname,id';
$members = get_records_select_assoc('usr','id IN (' . join(',',$value) . ')', null, $orderby, 'id,username,firstname,lastname,preferredname,staff');
foreach($members as &$member) {
$member = display_name($member);
......
......@@ -96,6 +96,7 @@ class PluginSearchInternal extends PluginSearch {
public static function search_user_pg($query_string, $limit, $offset, $data, $publicfields) {
$fieldlist = "('" . join("','", $publicfields) . "')";
$data = self::prepare_search_user_options($data);
$sql = 'SELECT
COUNT(DISTINCT u.id)
FROM
......@@ -139,7 +140,7 @@ class PluginSearchInternal extends PluginSearch {
$count = get_field_sql($sql, $values);
if ($count > 0) {
$sql = 'SELECT DISTINCT ON (u.firstname, u.lastname, u.id)
$sql = 'SELECT DISTINCT ON (' . $data['orderby'] . ')
u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.staff
FROM {artefact} a
INNER JOIN {usr} u ON u.id = a.owner
......@@ -156,7 +157,7 @@ class PluginSearchInternal extends PluginSearch {
AND (' . $namesql . '
)
' . (isset($data['exclude']) ? 'AND u.id != ' . $data['exclude'] : '') . '
ORDER BY u.firstname, u.lastname, u.id';
ORDER BY ' . $data['orderby'];
$data = get_records_sql_array($sql, $values, $offset, $limit);
if ($data) {
......@@ -266,6 +267,22 @@ class PluginSearchInternal extends PluginSearch {
'data' => $data,
);
}
private static function prepare_search_user_options($options) {
if (isset($options['group'])) {
$options['group'] = intval($options['group']);
}
if (isset($options['includeadmins'])) {
$options['includeadmins'] = (bool)$options['includeadmins'];
}
if (isset($options['orderby']) && $options['orderby'] == 'lastname') {
$options['orderby'] = 'u.lastname, u.firstname, u.id';
}
else {
$options['orderby'] = 'u.firstname, u.lastname, u.id';
}
return $options;
}
private static function match_expression($op, $string, &$values, $ilike) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment