Commit a3a0bee3 authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Fix display issues with long usernames



Long usernames made display go bad, this fixes it by
only printing max 33 characters (30 of username + ...)

Bug #779722

Change-Id: Idbe356f0c014c0c485ebf0bcd5daed530ec27985
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent bc4cc476
......@@ -27,6 +27,8 @@
defined('INTERNAL') || die();
define('MAX_USERNAME_DISPLAY', 30);
/**
* loads up activity preferences for a given user
*
......@@ -725,7 +727,7 @@ function display_name($user, $userto=null, $nameonly=false, $realname=false, $us
if (empty($user->preferredname)) {
$firstlast = full_name($user);
if ($addusername) {
return $firstlast . ' (' . $user->username . ')';
return $firstlast . ' (' . display_username($user) . ')';
}
return $firstlast;
}
......@@ -758,12 +760,12 @@ function display_name($user, $userto=null, $nameonly=false, $realname=false, $us
if ($addrealname) {
$firstlast = full_name($user);
if ($addusername) {
return $user->preferredname . ' (' . $firstlast . ' - ' . $user->username . ')';
return $user->preferredname . ' (' . $firstlast . ' - ' . display_username($user) . ')';
}
return $user->preferredname . ' (' . $firstlast . ')';
}
if ($addusername) {
return $user->preferredname . ' (' . $user->username . ')';
return $user->preferredname . ' (' . display_username($user) . ')';
}
return $user->preferredname;
}
......@@ -819,6 +821,30 @@ function full_name($user=null) {
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
......
......@@ -336,6 +336,7 @@ class PluginSearchInternal extends PluginSearch {
}
}
foreach ($data as &$item) {
$item->username = display_username($item);
$item = (array)$item;
}
$data = array_values($data);
......
......@@ -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'))) {
$loginas = get_string('loginasuser', 'admin', $user->username);
$loginas = get_string('loginasuser', 'admin', display_username($user));
} else {
$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