MDL-42098 - Libraries: Alter fullname debugging logic to display when user name fields are missing.

This commit is contained in:
Adrian Greeve 2013-10-02 14:55:20 +08:00
parent 56cc9b387e
commit a49bc6c940

View File

@ -3562,6 +3562,19 @@ function ismoving($courseid) {
function fullname($user, $override=false) {
global $CFG, $SESSION;
// Get all of the name fields.
$allnames = get_all_user_name_fields();
if ($CFG->debugdeveloper) {
foreach ($allnames as $allname) {
if (!array_key_exists($allname, $user)) {
// If all the user name fields are not set in the user object, then notify the programmer that it needs to be fixed.
debugging('You need to update your sql to include additional name fields in the user object.', DEBUG_DEVELOPER);
// Message has been sent, no point in sending the message multiple times.
break;
}
}
}
if (!isset($user->firstname) and !isset($user->lastname)) {
return '';
}
@ -3589,17 +3602,11 @@ function fullname($user, $override=false) {
return get_string('fullnamedisplay', null, $user);
}
// Get all of the name fields.
$allnames = get_all_user_name_fields();
$requirednames = array();
// With each name, see if it is in the display name template, and add it to the required names array if it is.
foreach ($allnames as $allname) {
if (strpos($template, $allname) !== false) {
$requirednames[] = $allname;
// If the field is in the template but not set in the user object then notify the programmer that it needs to be fixed.
if (!array_key_exists($allname, $user)) {
debugging('You need to update your sql to include additional name fields in the user object.', DEBUG_DEVELOPER);
}
}
}