MDL-46921 lib: Add sorting on additional name fields

A thank you to Yishe Choden for creating a patch for this issue.
This commit is contained in:
Adrian Greeve 2014-09-08 14:14:17 +08:00
parent 6597413d41
commit 143aacaea0
2 changed files with 6 additions and 7 deletions

View File

@ -448,7 +448,8 @@ class flexible_table {
if (($sortcol = optional_param($this->request[TABLE_VAR_SORT], '', PARAM_ALPHANUMEXT)) &&
$this->is_sortable($sortcol) && empty($this->sess->collapse[$sortcol]) &&
(isset($this->columns[$sortcol]) || in_array($sortcol, array('firstname', 'lastname')) && isset($this->columns['fullname']))) {
(isset($this->columns[$sortcol]) || in_array($sortcol, get_all_user_name_fields())
&& isset($this->columns['fullname']))) {
if (array_key_exists($sortcol, $this->sess->sortby)) {
// This key already exists somewhere. Change its sortorder and bring it to the top.
@ -571,7 +572,7 @@ class flexible_table {
if (isset($this->columns[$column])) {
continue; // This column is OK.
}
if (in_array($column, array('firstname', 'lastname')) &&
if (in_array($column, get_all_user_name_fields()) &&
isset($this->columns['fullname'])) {
continue; // This column is OK.
}
@ -1186,7 +1187,7 @@ class flexible_table {
if ($nameformat == 'language') {
$nameformat = get_string('fullnamedisplay');
}
$requirednames = order_in_string(array('firstname', 'lastname'), $nameformat);
$requirednames = order_in_string(get_all_user_name_fields(), $nameformat);
if (!empty($requirednames)) {
if ($this->is_sortable($column)) {

View File

@ -410,11 +410,9 @@ list($esql, $params) = get_enrolled_sql($context, null, $currentgroup, true);
$joins = array("FROM {user} u");
$wheres = array();
$extrasql = get_extra_user_fields_sql($context, 'u', '', array(
'id', 'username', 'firstname', 'lastname', 'email', 'city', 'country',
'picture', 'lang', 'timezone', 'maildisplay', 'imagealt', 'lastaccess'));
$mainuserfields = user_picture::fields('u', array('username', 'email', 'city', 'country', 'lang', 'timezone', 'maildisplay'));
$alreadyretrievedfields = explode(',', $mainuserfields);
$extrasql = get_extra_user_fields_sql($context, 'u', '', $alreadyretrievedfields);
if ($isfrontpage) {
$select = "SELECT $mainuserfields, u.lastaccess$extrasql";