Merge branch 'wip-MDL-42098-master' of git://github.com/abgreeve/moodle

This commit is contained in:
Damyon Wiese
2013-10-09 11:48:14 +08:00
3 changed files with 26 additions and 8 deletions
+13 -6
View File
@@ -3559,6 +3559,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 '';
}
@@ -3586,17 +3599,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);
}
}
}
+10
View File
@@ -2375,6 +2375,16 @@ class core_moodlelib_testcase extends advanced_testcase {
$this->assertSame($expectedname, $testname);
}
// Test debugging message displays when
// fullnamedisplay setting is "normal".
$CFG->fullnamedisplay = 'firstname lastname';
unset($user);
$user = new stdClass();
$user->firstname = 'Stan';
$user->lastname = 'Lee';
$namedisplay = fullname($user);
$this->assertDebuggingCalled();
// Tidy up after we finish testing.
$CFG->fullnamedisplay = $originalcfg->fullnamedisplay;
}
+3 -2
View File
@@ -240,10 +240,11 @@ class mod_forum_external extends external_api {
if ($forum->type == 'qanda' && !forum_user_has_posted($discussion->forum, $discussion->id, $USER->id)) {
require_capability('mod/forum:viewqandawithoutposting', $modcontext);
}
$usernamefields = user_picture::fields();
// If we don't have the users details then perform DB call.
if (empty($arrusers[$discussion->userid])) {
$arrusers[$discussion->userid] = $DB->get_record('user', array('id' => $discussion->userid),
'firstname, lastname, email, picture, imagealt', MUST_EXIST);
$usernamefields, MUST_EXIST);
}
// Get the subject.
$subject = $DB->get_field('forum_posts', 'subject', array('id' => $discussion->firstpost), MUST_EXIST);
@@ -284,7 +285,7 @@ class mod_forum_external extends external_api {
$lastpost = $DB->get_record('forum_posts', array('id' => $return->lastpost), '*', MUST_EXIST);
if (empty($arrusers[$lastpost->userid])) {
$arrusers[$lastpost->userid] = $DB->get_record('user', array('id' => $lastpost->userid),
'firstname, lastname, email, picture, imagealt', MUST_EXIST);
$usernamefields, MUST_EXIST);
}
$return->lastuserid = $lastpost->userid;
$return->lastuserfullname = fullname($arrusers[$lastpost->userid], $canviewfullname);