$returnurl = new moodle_url('/admin/user.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage, 'page'=>$page));
+ // The $user variable is also used outside of these if statements.
+ $user = null;
if ($confirmuser and confirm_sesskey()) {
require_capability('moodle/user:update', $sitecontext);
if (!$user = $DB->get_record('user', array('id'=>$confirmuser, 'mnethostid'=>$CFG->mnet_localhost_id))) {
// Carry on with the user listing
$context = context_system::instance();
$extracolumns = get_extra_user_fields($context);
- $columns = array_merge(array('firstname', 'lastname'), $extracolumns,
- array('city', 'country', 'lastaccess'));
+ // Get all user name fields as an array.
+ $allusernamefields = get_all_user_name_fields(false, null, null, null, true);
+ $columns = array_merge($allusernamefields, $extracolumns, array('city', 'country', 'lastaccess'));
foreach ($columns as $column) {
$string[$column] = get_user_field_name($column);
$$column = "<a href=\"user.php?sort=$column&dir=$columndir\">".$string[$column]."</a>$columnicon";
}
- $override = new stdClass();
- $override->firstname = 'firstname';
- $override->lastname = 'lastname';
- $fullnamelanguage = get_string('fullnamedisplay', '', $override);
- if (($CFG->fullnamedisplay == 'firstname lastname') or
- ($CFG->fullnamedisplay == 'firstname') or
- ($CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'firstname lastname' )) {
- $fullnamedisplay = "$firstname / $lastname";
- if ($sort == "name") { // If sort has already been set to something else then ignore.
- $sort = "firstname";
- }
- } else { // ($CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'lastname firstname').
- $fullnamedisplay = "$lastname / $firstname";
- if ($sort == "name") { // This should give the desired sorting based on fullnamedisplay.
- $sort = "lastname";
- }
+ // We need to check that alternativefullnameformat is not set to '' or language.
+ // We don't need to check the fullnamedisplay setting here as the fullname function call further down has
+ // the override parameter set to true.
+ $fullnamesetting = $CFG->alternativefullnameformat;
+ // If we are using language or it is empty, then retrieve all of the user's names.
+ if ($fullnamesetting == 'language' || empty($fullnamesetting)) {
+ $fullnamesetting = implode(' ', $allusernamefields);
+ }
+
+ // Order in string will ensure that the name columns are in the correct order.
+ $usernames = order_in_string($allusernamefields, $fullnamesetting);
+ $fullnamedisplay = array();
+ foreach ($usernames as $name) {
+ // Use the link from $$column for sorting on the user's name.
+ $fullnamedisplay[] = ${$name};
+ }
+ // All of the names are in one column. Put them into a string and separate them with a /.
+ $fullnamedisplay = implode(' / ', $fullnamedisplay);
+ // If $sort = name then it is the default for the setting and we should use the first name to sort by.
+ if ($sort == "name") {
+ // Use the first item in the array.
+ $sort = reset($usernames);
}
list($extrasql, $params) = $ufiltering->get_sql_filter();
JOIN {enrol} e ON (e.id = ue.enrolid)
LEFT JOIN {user_lastaccess} ul ON (ul.courseid = e.courseid AND ul.userid = u.id)
LEFT JOIN {groups_members} gm ON u.id = gm.userid
- WHERE $filtersql";
- if ($sort === 'firstname') {
- $sql .= " ORDER BY u.firstname $direction, u.lastname $direction";
- } else if ($sort === 'lastname') {
- $sql .= " ORDER BY u.lastname $direction, u.firstname $direction";
- } else if ($sort === 'email') {
- $sql .= " ORDER BY u.email $direction, u.lastname $direction, u.firstname $direction";
- } else if ($sort === 'lastseen') {
- $sql .= " ORDER BY ul.timeaccess $direction, u.lastname $direction, u.firstname $direction";
- }
+ WHERE $filtersql
+ ORDER BY u.$sort $direction";
$this->users[$key] = $DB->get_records_sql($sql, $params, $page*$perpage, $perpage);
}
return $this->users[$key];
* @static
* @var array
*/
- protected static $sortablefields = array('firstname', 'lastname', 'idnumber', 'email',
- 'phone1', 'phone2', 'institution', 'department' );
+ protected static $sortablefields = array('firstname', 'lastname', 'firstnamephonetic', 'lastnamephonetic', 'middlename',
+ 'alternatename', 'idnumber', 'email', 'phone1', 'phone2', 'institution', 'department' );
/**
* Constructs the table
* @static
* @var array
*/
- protected static $sortablefields = array('firstname', 'lastname', 'email', 'lastaccess');
+ protected static $sortablefields = array('firstname', 'lastname', 'firstnamephonetic', 'lastnamephonetic', 'middlename',
+ 'alternatename', 'email', 'lastaccess');
}
/**
$renderer = $PAGE->get_renderer('core_enrol');
-$userdetails = array (
- 'picture' => false,
- 'firstname' => get_string('firstname'),
- 'lastname' => get_string('lastname'),
-);
+$userdetails = array('picture' => false);
+// Get all the user names in a reasonable default order.
+$allusernames = get_all_user_name_fields(false, null, null, null, true);
+// Initialise the variable for the user's names in the table header.
+$usernameheader = null;
+// Get the alternative full name format for users with the viewfullnames capability.
+$fullusernames = $CFG->alternativefullnameformat;
+// If fullusernames is empty or accidentally set to language then fall back on the $allusernames set up.
+if ($fullusernames == 'language' || empty($fullusernames)) {
+ $usernameheader = $allusernames;
+} else {
+ // If everything is as expected then put them in the order specified by the alternative full name format setting.
+ $usernameheader = order_in_string($allusernames, $fullusernames);
+}
+
+// Loop through each name and return the language string.
+foreach ($usernameheader as $key => $username) {
+ $userdetails[$username] = get_string($username);
+}
$extrafields = get_extra_user_fields($context);
foreach ($extrafields as $field) {
$userdetails[$field] = get_user_field_name($field);