Commit aa19ef19 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Handle deleted users in display_name (bug 3367)

parent eb6fea58
......@@ -850,4 +850,5 @@ $string['allowpublicaccess'] = 'Allow public (non logged in) access';
$string['thisistheprofilepagefor'] = 'This is the profile page for %s';
$string['pleasedonotreplytothismessage'] = "Please do not reply to this message.";
$string['deleteduser'] = 'Deleted user';
?>
......@@ -439,6 +439,7 @@ function display_name($user, $userto=null, $nameonly=false) {
$user->lastname = $USER->get('lastname');
$user->admin = $USER->get('admin') || $USER->is_institutional_admin();
$user->staff = $USER->get('staff') || $USER->is_institutional_staff();
$user->deleted = 0;
$usercache[$user->id] = $user;
}
else {
......@@ -459,6 +460,7 @@ function display_name($user, $userto=null, $nameonly=false) {
$user->lastname = $userObj->get('lastname');
$user->admin = $userObj->get('admin');
$user->staff = $userObj->get('staff');
$user->deleted = $userObj->get('deleted');
}
$user->id = (isset($user->id)) ? $user->id : null;
......@@ -469,23 +471,21 @@ function display_name($user, $userto=null, $nameonly=false) {
}
// if they don't have a preferred name set, just return here
$firstlast = (isset($user->deleted) && $user->deleted) ? get_string('deleteduser') : ($user->firstname . ' ' . $user->lastname);
if (empty($user->preferredname)) {
if ((!empty($userto->admin) || !empty($userto->staff)) && !$nameonly) {
return ($resultcache[$user->id][$userto->id][$nameonly]
= $user->firstname . ' ' . $user->lastname . ' (' . $user->username . ')');
return ($resultcache[$user->id][$userto->id][$nameonly] = $firstlast . ' (' . $user->username . ')');
}
return ($resultcache[$user->id][$userto->id][$nameonly]
= $user->firstname . ' ' . $user->lastname);
return ($resultcache[$user->id][$userto->id][$nameonly] = $firstlast);
}
else if ($user->id == $userto->id) {
// If viewing our own name, show it how we like it
return ($resultcache[$user->id][$userto->id][$nameonly]
= $user->preferredname);
return ($resultcache[$user->id][$userto->id][$nameonly] = $user->preferredname);
}
if ((!empty($userto->admin) || !empty($userto->staff)) && !$nameonly) {
return ($resultcache[$user->id][$userto->id][$nameonly]
= $user->preferredname . ' (' . $user->firstname . ' ' . $user->lastname . ' - ' . $user->username . ')');
= $user->preferredname . ' (' . $firstlast . ' - ' . $user->username . ')');
}
$sql = "SELECT g1.member
......@@ -496,10 +496,9 @@ function display_name($user, $userto=null, $nameonly=false) {
WHERE g1.member = ? AND g2.member = ? AND g2.role = 'tutor'";
if (record_exists_sql($sql, array($user->id, $userto->id))) {
return ($resultcache[$user->id][$userto->id][$nameonly]
= $user->preferredname . ($nameonly ? '' : ' (' . $user->firstname . ' ' . $user->lastname . ')'));
= $user->preferredname . ($nameonly ? '' : ' (' . $firstlast . ')'));
}
return ($resultcache[$user->id][$userto->id][$nameonly]
= $user->preferredname);
return ($resultcache[$user->id][$userto->id][$nameonly] = $user->preferredname);
}
/**
......
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