MDL-75283 core: Fetch proper column mapping for sort
Calling \core_user\fields::get_sql() incerements a static uniqueid variable. This should be called only once and not make a separate call for the sort mapping data as it doing so will result to an incorrect table alias for the sort mapping data.
This commit is contained in:
committed by
Ilya Tregubov
parent
f77ea5bffa
commit
c4ba598a0b
+7
-11
@@ -529,23 +529,19 @@ function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperp
|
||||
$userfields->with_identity($extracontext, true);
|
||||
}
|
||||
|
||||
$userfields->excluding('id');
|
||||
$userfields->including('username', 'email', 'city', 'country', 'lastaccess', 'confirmed', 'mnethostid', 'suspended');
|
||||
['selects' => $selects, 'joins' => $joins, 'params' => $joinparams, 'mappings' => $mappings] =
|
||||
(array)$userfields->get_sql('u', true);
|
||||
|
||||
if ($sort) {
|
||||
$possiblesortfields = \core_user\fields::for_name();
|
||||
if ($extracontext) {
|
||||
$possiblesortfields->with_identity($extracontext);
|
||||
}
|
||||
$orderbymap = $possiblesortfields->including('id', 'city', 'country', 'lastaccess', 'confirmed', 'mnethostid', 'suspended');
|
||||
$orderbymap = $orderbymap->get_sql('u', true)->mappings;
|
||||
$orderbymap = $mappings;
|
||||
$orderbymap['default'] = 'lastaccess';
|
||||
$sort = get_safe_orderby($orderbymap, $sort, $dir);
|
||||
}
|
||||
|
||||
$userfields->excluding('id', 'username', 'email', 'city', 'country', 'lastaccess', 'confirmed', 'mnethostid');
|
||||
['selects' => $selects, 'joins' => $joins, 'params' => $joinparams] =
|
||||
(array)$userfields->get_sql('u', true);
|
||||
|
||||
// warning: will return UNCONFIRMED USERS
|
||||
return $DB->get_records_sql("SELECT u.id, username, email, city, country, lastaccess, confirmed, mnethostid, suspended $selects
|
||||
return $DB->get_records_sql("SELECT u.id $selects
|
||||
FROM {user} u
|
||||
$joins
|
||||
WHERE $select
|
||||
|
||||
Reference in New Issue
Block a user