Commit d6f613cb authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge "Fix display issues with long usernames"

parents 45e4483d a3a0bee3
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
defined('INTERNAL') || die(); defined('INTERNAL') || die();
define('MAX_USERNAME_DISPLAY', 30);
/** /**
* loads up activity preferences for a given user * loads up activity preferences for a given user
* *
...@@ -725,7 +727,7 @@ function display_name($user, $userto=null, $nameonly=false, $realname=false, $us ...@@ -725,7 +727,7 @@ function display_name($user, $userto=null, $nameonly=false, $realname=false, $us
if (empty($user->preferredname)) { if (empty($user->preferredname)) {
$firstlast = full_name($user); $firstlast = full_name($user);
if ($addusername) { if ($addusername) {
return $firstlast . ' (' . $user->username . ')'; return $firstlast . ' (' . display_username($user) . ')';
} }
return $firstlast; return $firstlast;
} }
...@@ -758,12 +760,12 @@ function display_name($user, $userto=null, $nameonly=false, $realname=false, $us ...@@ -758,12 +760,12 @@ function display_name($user, $userto=null, $nameonly=false, $realname=false, $us
if ($addrealname) { if ($addrealname) {
$firstlast = full_name($user); $firstlast = full_name($user);
if ($addusername) { if ($addusername) {
return $user->preferredname . ' (' . $firstlast . ' - ' . $user->username . ')'; return $user->preferredname . ' (' . $firstlast . ' - ' . display_username($user) . ')';
} }
return $user->preferredname . ' (' . $firstlast . ')'; return $user->preferredname . ' (' . $firstlast . ')';
} }
if ($addusername) { if ($addusername) {
return $user->preferredname . ' (' . $user->username . ')'; return $user->preferredname . ' (' . display_username($user) . ')';
} }
return $user->preferredname; return $user->preferredname;
} }
...@@ -819,6 +821,30 @@ function full_name($user=null) { ...@@ -819,6 +821,30 @@ function full_name($user=null) {
return isset($user->deleted) && $user->deleted ? get_string('deleteduser') : $user->firstname . ' ' . $user->lastname; return isset($user->deleted) && $user->deleted ? get_string('deleteduser') : $user->firstname . ' ' . $user->lastname;
} }
/**
* Creates a string containing a displayable username.
*
* If the username is longer than 30 characters (bug #548165), then print
* the first 30 characters followed by '...'
*
* @param object $user The user object to display the username of. If empty,
* the global $USER object is used
*/
function display_username($user=null) {
global $USER;
if ($user === null) {
$user = new StdClass;
$user->username = $USER->get('username');
}
if (strlen($user->username) > MAX_USERNAME_DISPLAY) {
return substr($user->username, 0, MAX_USERNAME_DISPLAY).'...';
}
else {
return $user->username;
}
}
/** /**
* helper function to default to currently * helper function to default to currently
......
...@@ -336,6 +336,7 @@ class PluginSearchInternal extends PluginSearch { ...@@ -336,6 +336,7 @@ class PluginSearchInternal extends PluginSearch {
} }
} }
foreach ($data as &$item) { foreach ($data as &$item) {
$item->username = display_username($item);
$item = (array)$item; $item = (array)$item;
} }
$data = array_values($data); $data = array_values($data);
......
...@@ -274,7 +274,7 @@ if (!empty($loggedinid) && $loggedinid != $userid) { ...@@ -274,7 +274,7 @@ if (!empty($loggedinid) && $loggedinid != $userid) {
} }
if ($userid != $USER->get('id') && $USER->is_admin_for_user($user) && is_null($USER->get('parentuser'))) { if ($userid != $USER->get('id') && $USER->is_admin_for_user($user) && is_null($USER->get('parentuser'))) {
$loginas = get_string('loginasuser', 'admin', $user->username); $loginas = get_string('loginasuser', 'admin', display_username($user));
} else { } else {
$loginas = null; $loginas = null;
} }
......
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