MDL-42812 libraries: Update username_load_fields_from_object to add the prefix to...
authorAdrian Greeve <adrian@moodle.com>
Mon, 11 Nov 2013 09:18:16 +0000 (17:18 +0800)
committerSam Hemelryk <sam@moodle.com>
Tue, 12 Nov 2013 03:30:16 +0000 (11:30 +0800)
lib/moodlelib.php
lib/tests/moodlelib_test.php
mod/forum/lib.php
mod/quiz/report/attemptsreport_table.php
mod/scorm/report/basic/report.php
mod/scorm/report/interactions/report.php
mod/scorm/report/objectives/report.php

index decda4c..773e547 100644 (file)
@@ -3700,7 +3700,7 @@ function get_all_user_name_fields($returnsql = false, $tableprefix = null, $pref
  *
  * @param object $addtoobject Object to add user name fields to.
  * @param object $secondobject Object that contains user name field information.
- * @param string $prefix prefix to be added to the user name field e.g. authorfirstname.
+ * @param string $prefix prefix to be added to all fields (including $additionalfields) e.g. authorfirstname.
  * @param array $additionalfields Additional fields to be matched with data in the second object.
  * The key can be set to the user table field name.
  * @return object User name fields.
@@ -3712,8 +3712,10 @@ function username_load_fields_from_object($addtoobject, $secondobject, $prefix =
         // the key is a number and then sets the key to the array value.
         foreach ($additionalfields as $key => $value) {
             if (is_numeric($key)) {
-                $additionalfields[$value] = $value;
+                $additionalfields[$value] = $prefix . $value;
                 unset($additionalfields[$key]);
+            } else {
+                $additionalfields[$key] = $prefix . $value;
             }
         }
         $fields = array_merge($fields, $additionalfields);
index 4d13866..fe7a58b 100644 (file)
@@ -2633,7 +2633,6 @@ class core_moodlelib_testcase extends advanced_testcase {
         $userinfo->imagealt = 'Michael Jordan draining another basket.';
         $userinfo->idnumber = 3982;
 
-
         // Just user name fields.
         $user = new stdClass();
         $user = username_load_fields_from_object($user, $userinfo);
@@ -2648,8 +2647,9 @@ class core_moodlelib_testcase extends advanced_testcase {
 
         // User information for showing a picture.
         $user = new stdClass();
-        $additionalfields = array('id' => 'userid', 'imagealt', 'picture', 'email');
+        $additionalfields = explode(',', user_picture::fields());
         $user = username_load_fields_from_object($user, $userinfo, null, $additionalfields);
+        $user->id = $userinfo->userid;
         $expectedarray = new stdClass();
         $expectedarray->id = 1;
         $expectedarray->firstname = 'Bruce';
@@ -2669,11 +2669,16 @@ class core_moodlelib_testcase extends advanced_testcase {
         $userinfo->authorfirstnamephonetic = 'ブルース';
         $userinfo->authorlastnamephonetic = 'カンベッル';
         $userinfo->authormiddlename = '';
+        $userinfo->authorpicture = 23;
+        $userinfo->authorimagealt = 'Michael Jordan draining another basket.';
+        $userinfo->authoremail = 'test@testing.net';
+
 
         // Return an object with user picture information.
         $user = new stdClass();
-        $additionalfields = array('id' => 'userid', 'imagealt', 'picture', 'email');
+        $additionalfields = explode(',', user_picture::fields());
         $user = username_load_fields_from_object($user, $userinfo, 'author', $additionalfields);
+        $user->id = $userinfo->userid;
         $expectedarray = new stdClass();
         $expectedarray->id = 1;
         $expectedarray->firstname = 'Bruce';
@@ -2682,7 +2687,7 @@ class core_moodlelib_testcase extends advanced_testcase {
         $expectedarray->lastnamephonetic = 'カンベッル';
         $expectedarray->middlename = '';
         $expectedarray->alternatename = '';
-        $expectedarray->email = '';
+        $expectedarray->email = 'test@testing.net';
         $expectedarray->picture = 23;
         $expectedarray->imagealt = 'Michael Jordan draining another basket.';
         $this->assertEquals($user, $expectedarray);
index a4af649..1966ec1 100644 (file)
@@ -3330,8 +3330,9 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
 
     // Build an object that represents the posting user
     $postuser = new stdClass;
-    $postuserfields = array('id' => 'userid', 'imagealt', 'picture', 'email');
+    $postuserfields = explode(',', user_picture::fields());
     $postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
+    $postuser->id = $post->userid;
     $postuser->fullname    = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']);
     $postuser->profilelink = new moodle_url('/user/view.php', array('id'=>$post->userid, 'course'=>$course->id));
 
@@ -3767,8 +3768,9 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
 
     // Picture
     $postuser = new stdClass();
-    $postuserfields = array('id' => 'userid', 'imagealt', 'picture', 'email');
+    $postuserfields = explode(',', user_picture::fields());
     $postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
+    $postuser->id = $post->userid;
     echo '<td class="picture">';
     echo $OUTPUT->user_picture($postuser, array('courseid'=>$forum->course));
     echo "</td>\n";
@@ -3830,7 +3832,8 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
     $usedate = (empty($post->timemodified)) ? $post->modified : $post->timemodified;  // Just in case
     $parenturl = (empty($post->lastpostid)) ? '' : '&amp;parent='.$post->lastpostid;
     $usermodified = new stdClass();
-    $usermodified = username_load_fields_from_object($usermodified, $post, 'um', array('id' => 'usermodified'));
+    $usermodified->id = $post->usermodified;
+    $usermodified = username_load_fields_from_object($usermodified, $post, 'um');
     echo '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$post->usermodified.'&amp;course='.$forum->course.'">'.
          fullname($usermodified).'</a><br />';
     echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.$parenturl.'">'.
@@ -6110,7 +6113,9 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours
 
         $tmpactivity->user = new stdClass();
         $additionalfields = array('id' => 'userid', 'picture', 'imagealt', 'email');
+        $additionalfields = explode(',', user_picture::fields());
         $tmpactivity->user = username_load_fields_from_object($tmpactivity->user, $post, null, $additionalfields);
+        $tmpactivity->user->id = $post->userid;
 
         $activities[$index++] = $tmpactivity;
     }
index 5c56c50..1b626ab 100644 (file)
@@ -121,8 +121,9 @@ abstract class quiz_attempts_report_table extends table_sql {
     public function col_picture($attempt) {
         global $OUTPUT;
         $user = new stdClass();
-        $additionalfields = array('id' => 'userid', 'imagealt', 'picture', 'email');
+        $additionalfields = explode(',', user_picture::fields());
         $user = username_load_fields_from_object($user, $attempt, null, $additionalfields);
+        $user->id = $attempt->userid
         return $OUTPUT->user_picture($user);
     }
 
index b2a6032..e97df4f 100644 (file)
@@ -381,8 +381,9 @@ class scorm_basic_report extends scorm_default_report {
                     }
                     if (in_array('picture', $columns)) {
                         $user = new stdClass();
-                        $additionalfields = array('id' => 'userid', 'picture', 'imagealt', 'email');
+                        $additionalfields = explode(',', user_picture::fields());
                         $user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
+                        $user->id = $scouser->userid;
                         $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
                     }
                     if (!$download) {
index 66ea5cc..e886c8b 100644 (file)
@@ -416,8 +416,9 @@ class scorm_interactions_report extends scorm_default_report {
                     }
                     if (in_array('picture', $columns)) {
                         $user = new stdClass();
-                        $additionalfields = array('id' => 'userid', 'picture', 'imagealt', 'email');
+                        $additionalfields = explode(',', user_picture::fields());
                         $user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
+                        $user->id = $scouser->userid;
                         $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
                     }
                     if (!$download) {
index 7b26703..199c094 100644 (file)
@@ -420,8 +420,9 @@ class scorm_objectives_report extends scorm_default_report {
                     }
                     if (in_array('picture', $columns)) {
                         $user = new stdClass();
-                        $additionalfields = array('id' => 'userid', 'picture', 'imagealt', 'email');
+                        $additionalfields = explode(',', user_picture::fields());
                         $user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
+                        $user->id = $scouser->userid;
                         $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
                     }
                     if (!$download) {