MDL-21676 user_picture refactoring, reenabling email requirement - towards Gravatar...
authorPetr Skoda <skodak@moodle.org>
Sun, 4 Jul 2010 18:36:34 +0000 (18:36 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 4 Jul 2010 18:36:34 +0000 (18:36 +0000)
24 files changed:
admin/report/configlog/index.php
blocks/messages/block_messages.php
blocks/online_users/block_online_users.php
comment/lib.php
enrol/users.php
grade/report/grader/lib.php
lib/deprecatedlib.php
lib/outputcomponents.php
message/lib.php
mod/assignment/lib.php
mod/chat/lib.php
mod/choice/lib.php
mod/feedback/lib.php
mod/forum/lib.php
mod/quiz/lib.php
mod/quiz/report/overview/overview_table.php
mod/quiz/report/overview/report.php
mod/quiz/report/responses/responses_table.php
mod/scorm/report.php
mod/workshop/allocation/manual/lib.php
mod/workshop/locallib.php
mod/workshop/renderer.php
mod/workshop/view.php
rating/lib.php

index fed4891..5b9b370 100644 (file)
@@ -80,7 +80,8 @@ if ($sort == 'firstname' or $sort == 'lastname') {
     $orderby = "cl.$sort $dir";
 }
 
-$sql = "SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
+$ufields = user_picture::fields('u');
+$sql = "SELECT $ufields,
                cl.timemodified, cl.plugin, cl.name, cl.value, cl.oldvalue
           FROM {config_log} cl
           JOIN {user} u ON u.id = cl.userid
index 32e50e5..4ed83c0 100644 (file)
@@ -32,11 +32,11 @@ class block_messages extends block_base {
         $action = null; //this was using popup_action() but popping up a fullsize window seems wrong
         $this->content->footer = $OUTPUT->action_link($link, get_string('messages', 'message'), $action);
 
-        $users = $DB->get_records_sql("SELECT m.useridfrom AS id, COUNT(m.useridfrom) AS count,
-                                              u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
+        $ufields = user_picture::fields('u', array('lastaccess'));
+        $users = $DB->get_records_sql("SELECT $ufields, COUNT(m.useridfrom) AS count
                                          FROM {user} u, {message} m
                                         WHERE m.useridto = ? AND u.id = m.useridfrom
-                                     GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt", array($USER->id));
+                                     GROUP BY $ufields", array($USER->id));
 
 
         //Now, we have in users, the list of users to show
index c817394..f5d30d5 100644 (file)
@@ -54,7 +54,7 @@ class block_online_users extends block_base {
             $params['currentgroup'] = $currentgroup;
         }
 
-        $userfields = user_picture::fields('u').', username';
+        $userfields = user_picture::fields('u', array('username'));
 
         if ($this->page->course->id == SITEID) {  // Site-level
             $sql = "SELECT $userfields, MAX(u.lastaccess) AS lastaccess
index 8687cfc..caca8d7 100644 (file)
@@ -19,7 +19,7 @@
  * Comment is helper class to add/delete comments anywhere in moodle
  *
  * @package   comment
- * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com> 
+ * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
@@ -107,7 +107,7 @@ class comment {
         } else {
             $this->cid = uniqid();
         }
-        
+
         // setup context
         if (!empty($options->context)) {
             $this->context = $options->context;
@@ -132,7 +132,7 @@ class comment {
         if (!empty($options->pluginname)) {
             $this->pluginname = $options->pluginname;
         }
-        
+
         // setup coursemodule
         if (!empty($options->cm)) {
             $this->cm = $options->cm;
@@ -403,34 +403,38 @@ EOD;
         $this->page = $page;
         $params = array();
         $start = $page * $CFG->commentsperpage;
-        $sql = "SELECT c.id, c.userid, c.content, c.format, c.timecreated, u.picture, u.imagealt, u.username, u.firstname, u.lastname
-            FROM {comments} c, {user} u WHERE u.id=c.userid AND c.contextid=? AND c.commentarea=? AND c.itemid=?
-            ORDER BY c.timecreated DESC";
-        $params[] = $this->contextid;
-        $params[] = $this->commentarea;
-        $params[] = $this->itemid;
+        $ufields = user_picture::fields('u');
+        $sql = "SELECT $ufields, c.id AS cid, c.content AS c.content, c.format AS cformat, c.timecreated AS ctimecreated
+                  FROM {comments} c
+                  JOIN {user} u ON u.id = c.userid
+                 WHERE c.contextid = :contextid AND c.commentarea = :commentarea AND c.itemid = :itemid
+              ORDER BY c.timecreated DESC";
+        $params['contextid'] = $this->contextid;
+        $params['commentarea'] = $this->commentarea;
+        $params['itemid'] = $this->itemid;
 
         $comments = array();
         $candelete = has_capability('moodle/comment:delete', $this->context);
-        if ($records = $DB->get_records_sql($sql, $params, $start, $CFG->commentsperpage)) {
-            foreach ($records as &$c) {
-                $url = $CFG->httpswwwroot.'/user/view.php?id='.$c->userid.'&amp;course='.$this->courseid;
-                $c->username = '<a href="'.$url.'">'.fullname($c).'</a>';
-                $c->time = userdate($c->timecreated, get_string('strftimerecent', 'langconfig'));
-                $user = new stdclass;
-                $user->id = $c->userid;
-                $user->picture = $c->picture;
-                $user->firstname = $c->firstname;
-                $user->lastname  = $c->lastname;
-                $user->imagealt  = $c->imagealt;
-                $c->content = format_text($c->content, $c->format);
-                $c->avatar = $OUTPUT->user_picture($user, array('size'=>18));
-                if (($USER->id == $c->userid) || !empty($candelete)) {
-                    $c->delete = true;
-                }
-                $comments[] = $c;
+        $rs = $DB->get_recordset_sql($sql, $params, $start, $CFG->commentsperpage);
+        foreach ($records as $u) {
+            $c = new object();
+            $c->id          = $u->cid;
+            $c->content     = $u->ccontent;
+            $c->format      = $u->cformat;
+            $c->timecreated = $u->ctimecreated;
+            $url = $CFG->httpswwwroot.'/user/view.php?id='.$c->id.'&amp;course='.$this->courseid;
+            $c->username = '<a href="'.$url.'">'.fullname($u).'</a>';
+            $c->time = userdate($c->timecreated, get_string('strftimerecent', 'langconfig'));
+            $c->content = format_text($c->content, $c->format);
+
+            $c->avatar = $OUTPUT->user_picture($u, array('size'=>18));
+            if (($USER->id == $u->id) || !empty($candelete)) {
+                $c->delete = true;
             }
+            $comments[] = $c;
         }
+        $rs->close();
+
         if (!empty($this->plugintype)) {
             // moodle module will filter comments
             $comments = plugin_callback($this->plugintype, $this->pluginname, FEATURE_COMMENT, 'display', array($comments, $this->args), $comments);
index 2bce0d4..e2fced2 100644 (file)
@@ -374,7 +374,7 @@ foreach ($users as $user) {
     $picture = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
 
     if ($user->lastseen) {
-        $strlastaccess = format_time(time() - $user->lastaccess);
+        $strlastaccess = userdate($user->lastseen);
     } else {
         $strlastaccess = get_string('never');
     }
index 8b1463c..d794347 100644 (file)
@@ -340,7 +340,8 @@ class grade_report_grader extends grade_report {
             // the MAX() magic is required in order to please PG
             $sort = "MAX(g.finalgrade) $this->sortorder";
 
-            $sql = "SELECT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
+            $ufields = user_picture::fields('u', array('idnumber'));
+            $sql = "SELECT $ufields
                       FROM {user} u
                            JOIN {role_assignments} ra ON ra.userid = u.id
                            $this->groupsql
@@ -348,7 +349,7 @@ class grade_report_grader extends grade_report {
                      WHERE ra.roleid $usql AND u.deleted = 0
                            $this->groupwheresql
                            AND ra.contextid ".get_related_contexts_string($this->context)."
-                  GROUP BY u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
+                  GROUP BY $ufields
                   ORDER BY $sort";
 
         } else {
@@ -364,8 +365,8 @@ class grade_report_grader extends grade_report {
 
             $params = array_merge($gbrparams, $this->groupwheresql_params);
 
-            $userfields = user_picture::fields('u');
-            $sql = "SELECT DISTINCT $userfields, u.idnumber
+            $userfields = user_picture::fields('u', array('idnumber'));
+            $sql = "SELECT DISTINCT $userfields
                       FROM {user} u
                            JOIN {role_assignments} ra ON u.id = ra.userid
                            $this->groupsql
index ee056be..9db5c73 100644 (file)
@@ -2132,7 +2132,7 @@ function print_header($title='', $heading='', $navigation='', $focus='',
 
     $PAGE->set_title($title);
     $PAGE->set_heading($heading);
-    $PAGE->set_cacheable($cache);    
+    $PAGE->set_cacheable($cache);
     if ($button == '') {
         $button = '&nbsp;';
     }
@@ -2197,7 +2197,7 @@ function print_header_simple($title='', $heading='', $navigation='', $focus='',
     }
 
     $PAGE->set_title($title);
-    $PAGE->set_heading($heading);   
+    $PAGE->set_heading($heading);
     $PAGE->set_cacheable(true);
     $PAGE->set_button($button);
 
@@ -2663,7 +2663,7 @@ function print_file_picture($path, $courseid=0, $height='', $width='', $link='',
  *
  * @global object
  * @global object
- * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname
+ * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
  *      If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
  *      if at all possible, particularly for reports. It is very bad for performance.
  * @param int $courseid The course id. Used when constructing the link to the user's profile.
index 05621e4..5a42769 100644 (file)
@@ -98,13 +98,12 @@ class file_picker implements renderable {
  */
 class user_picture implements renderable {
     /**
-     * List of mandatory fields in user record here.
-     * @var string
+     * @var array List of mandatory fields in user record here. (do not include TEXT columns because it would break SELECT DISTINCT in MSSQL and ORACLE)
      */
-    const FIELDS = 'id,picture,firstname,lastname,imagealt'; //TODO: add email, but first update all places that call user_picture(), this is necessary for gravatar support
+    protected static $fields = array('id', 'picture', 'firstname', 'lastname', 'imagealt', 'email');
 
     /**
-     * @var object $user A user object with at least fields all columns specified in FIELDS constant set.
+     * @var object $user A user object with at least fields all columns specified in $fields array constant set.
      */
     public $user;
     /**
@@ -143,18 +142,13 @@ class user_picture implements renderable {
     public function __construct(stdClass $user) {
         global $DB;
 
-        static $fields = null;
-        if (is_null($fields)) {
-            $fields = explode(',', self::FIELDS);
-        }
-
         if (empty($user->id)) {
             throw new coding_exception('User id is required when printing user avatar image.');
         }
 
         // only touch the DB if we are missing data and complain loudly...
         $needrec = false;
-        foreach ($fields as $field) {
+        foreach (self::$fields as $field) {
             if (!array_key_exists($field, $user)) {
                 $needrec = true;
                 debugging('Missing '.$field.' property in $user object, this is a performance problem that needs to be fixed by a developer. '
@@ -164,7 +158,7 @@ class user_picture implements renderable {
         }
 
         if ($needrec) {
-            $this->user = $DB->get_record('user', array('id'=>$user->id), self::FIELDS, MUST_EXIST);
+            $this->user = $DB->get_record('user', array('id'=>$user->id), self::fields(), MUST_EXIST);
         } else {
             $this->user = clone($user);
         }
@@ -178,19 +172,33 @@ class user_picture implements renderable {
      * id of the result record. Please note it has to be converted back to id before rendering.
      *
      * @param string $tableprefix name of database table prefix in query
+     * @param array $extrafields extra fields to be included in result (do not include TEXT columns because it would break SELECT DISTINCT in MSSQL and ORACLE)
      * @param string $idalias alias of id field
      * @return string
      */
-    public static function fields($tableprefix = '', $idalias = '') {
-        if ($tableprefix === '' and $idalias === '') {
-            return self::FIELDS;
+    public static function fields($tableprefix = '', array $extrafields = NULL, $idalias = 'id') {
+        if (!$tableprefix and !$extrafields and !$idalias) {
+            return implode(',', self::$fields);
+        }
+        if ($tableprefix) {
+            $tableprefix .= '.';
         }
-        $fields = explode(',', self::FIELDS);
-        foreach ($fields as $key=>$field) {
-            if ($field === 'id' and $idalias !== '') {
-                $field = "$field AS $idalias";
+        $fields = array();
+        foreach (self::$fields as $field) {
+            if ($field === 'id' and $idalias and $idalias !== 'id') {
+                $fields[$field] = "$tableprefix.$field AS $idalias";
+            } else {
+                $fields[$field] = $tableprefix.$field;
+            }
+        }
+        // add extra fields if not already there
+        if ($extrafields) {
+            foreach ($extrafields as $e) {
+                if ($e === 'id' or isset($fields[$e])) {
+                    continue;
+                }
+                $fields[$e] = $tableprefix.$e;
             }
-            $fields[$key] = "$tableprefix.$field";
         }
         return implode(',', $fields);
     }
index fcd4592..95745d9 100644 (file)
@@ -65,7 +65,7 @@ if (!isset($CFG->message_offline_time)) {
 
 function message_print_contact_selector($countunreadtotal, $usergroup, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showcontactactionlinks) {
     global $PAGE;
-    
+
     echo html_writer::start_tag('div', array('class'=>'contactselector mdl-align'));
 
         //if 0 unread messages and they've requested unread messages then show contacts
@@ -128,7 +128,7 @@ function message_print_participants($context, $courseid, $contactselecturl=null,
     global $DB, $USER;
 
     $participants = get_enrolled_users($context);
-    
+
     echo '<table id="message_participants" class="boxaligncenter" cellspacing="2" cellpadding="0" border="0">';
 
     if (!empty($titletodisplay)) {
@@ -166,15 +166,14 @@ function message_get_blocked_users($user1=null, &$user2=null) {
         $user2->isblocked = false;
     }
 
-    $userfields = user_picture::fields('u');
-    $blockeduserssql = "SELECT $userfields, u.lastaccess, count(m.id) as messagecount
-                            FROM {message_contacts} mc
-                            JOIN {user} u ON u.id = mc.contactid
-                            LEFT OUTER JOIN {message} m ON m.useridfrom = mc.contactid AND m.useridto = :user1id1
-                            WHERE mc.userid = :user1id2 AND mc.blocked = 1
-                        GROUP BY u.id, u.firstname, u.lastname, u.picture,
-                                 u.imagealt, u.lastaccess
-                        ORDER BY u.firstname ASC";
+    $userfields = user_picture::fields('u', array('lastaccess'));
+    $blockeduserssql = "SELECT $userfields, COUNT(m.id) AS messagecount
+                          FROM {message_contacts} mc
+                          JOIN {user} u ON u.id = mc.contactid
+                          LEFT OUTER JOIN {message} m ON m.useridfrom = mc.contactid AND m.useridto = :user1id1
+                         WHERE mc.userid = :user1id2 AND mc.blocked = 1
+                      GROUP BY $userfields
+                      ORDER BY u.firstname ASC";
     $rs =  $DB->get_recordset_sql($blockeduserssql, array('user1id1'=>$user1->id, 'user1id2'=>$user1->id));
 
     $blockedusers = array();
@@ -243,17 +242,16 @@ function message_get_contacts($user1=null, &$user2=null) {
     // people who are not in our contactlist but have sent us a message
     $strangers       = array();
 
-    $userfields = user_picture::fields('u');
+    $userfields = user_picture::fields('u', array('lastaccess'));
 
     // get all in our contactlist who are not blocked in our contact list
     // and count messages we have waiting from each of them
-    $contactsql = "SELECT $userfields, u.lastaccess, count(m.id) as messagecount
+    $contactsql = "SELECT $userfields, COUNT(m.id) AS messagecount
                      FROM {message_contacts} mc
                      JOIN {user} u ON u.id = mc.contactid
                      LEFT OUTER JOIN {message} m ON m.useridfrom = mc.contactid AND m.useridto = ?
                     WHERE mc.userid = ? AND mc.blocked = 0
-                 GROUP BY u.id, u.firstname, u.lastname, u.picture,
-                          u.imagealt, u.lastaccess
+                 GROUP BY $userfields
                  ORDER BY u.firstname ASC";
 
     if ($rs = $DB->get_recordset_sql($contactsql, array($user1->id, $user1->id))){
@@ -277,13 +275,12 @@ function message_get_contacts($user1=null, &$user2=null) {
 
     // get messages from anyone who isn't in our contact list and count the number
     // of messages we have from each of them
-    $strangersql = "SELECT $userfields, u.lastaccess, count(m.id) as messagecount
+    $strangersql = "SELECT $userfields, count(m.id) as messagecount
                       FROM {message} m
                       JOIN {user} u  ON u.id = m.useridfrom
                       LEFT OUTER JOIN {message_contacts} mc ON mc.contactid = m.useridfrom AND mc.userid = m.useridto
                      WHERE mc.id IS NULL AND m.useridto = ?
-                  GROUP BY u.id, u.firstname, u.lastname, u.picture,
-                           u.imagealt, u.lastaccess
+                  GROUP BY $userfields
                   ORDER BY u.firstname ASC";
 
     if($rs = $DB->get_recordset_sql($strangersql, array($USER->id))){
@@ -512,7 +509,7 @@ function message_print_search($advancedsearch = false, $user1=null) {
     global $USER, $PAGE, $OUTPUT;
 
     $frm = data_submitted();
-    
+
     $doingsearch = false;
     if ($frm) {
         $doingsearch = !empty($frm->combinedsubmit) || !empty($frm->keywords) || (!empty($frm->personsubmit) and !empty($frm->name));
@@ -528,7 +525,7 @@ function message_print_search($advancedsearch = false, $user1=null) {
 
     if ($doingsearch) {
         if ($advancedsearch) {
-            
+
             $messagesearch = '';
             if (!empty($frm->keywords)) {
                 $messagesearch = $frm->keywords;
@@ -967,7 +964,7 @@ function message_contact_link($userid, $linktype='add', $return=false, $script=n
     $safealttext = s($string);
 
     $safestring = '';
-    if (!empty($text)) { 
+    if (!empty($text)) {
         $safestring = $safealttext;
     }
 
@@ -1095,32 +1092,30 @@ function message_search_users($courseid, $searchtext, $sort='', $exceptions='')
         $order = '';
     }
 
-    $select = 'u.deleted = \'0\' AND u.confirmed = \'1\'';
-    $fields = 'u.id, u.firstname, u.lastname, u.picture, u.imagealt, mc.id as contactlistid, mc.blocked';
-
+    $ufields = user_picture::fields('u');
     if (!$courseid or $courseid == SITEID) {
         $params = array($USER->id, "%$searchtext%");
-        return $DB->get_records_sql("SELECT $fields
+        return $DB->get_records_sql("SELECT $ufields, mc.id as contactlistid, mc.blocked
                                        FROM {user} u
                                        LEFT JOIN {message_contacts} mc
                                             ON mc.contactid = u.id AND mc.userid = ?
-                                      WHERE $select
+                                      WHERE u.deleted = '0' AND u.confirmed = '1'
                                             AND ($fullname $LIKE ?)
                                             $except
                                      $order", $params);
     } else {
-
+//TODO: add enabled enrolment join here (skodak)
         $context = get_context_instance(CONTEXT_COURSE, $courseid);
         $contextlists = get_related_contexts_string($context);
 
         // everyone who has a role assignement in this course or higher
         $params = array($USER->id, "%$searchtext%");
-        $users = $DB->get_records_sql("SELECT $fields
-                                         FROM {user} u
+        $users = $DB->get_records_sql("SELECT $ufields,
+                                         FROM {user} u, mc.id as contactlistid, mc.blocked
                                          JOIN {role_assignments} ra ON ra.userid = u.id
                                          LEFT JOIN {message_contacts} mc
                                               ON mc.contactid = u.id AND mc.userid = ?
-                                        WHERE $select
+                                        WHERE u.deleted = '0' AND u.confirmed = '1'
                                               AND ra.contextid $contextlists
                                               AND ($fullname $LIKE ?)
                                               $except
@@ -1390,7 +1385,7 @@ function message_get_history($user1, $user2, $limitnum=0) {
         ksort($messages);
         $messages = array_slice($messages, count($messages)-$limitnum, $limitnum, true);
     }
-    
+
     return $messages;
 }
 
index 3b24714..a7276da 100644 (file)
@@ -917,10 +917,11 @@ class assignment_base {
         $nextid = 0;
 
         if ($users) {
-            $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
+            $userfields = user_picture::fields('u', array('lastaccess'));
+            $select = "SELECT $userfields,
                               s.id AS submissionid, s.grade, s.submissioncomment,
                               s.timemodified, s.timemarked,
-                              COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
+                              COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ";
             $sql = 'FROM {user} u '.
                    'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
                                                                       AND s.assignment = '.$this->assignment->id.' '.
@@ -1178,10 +1179,11 @@ class assignment_base {
             $sort = ' ORDER BY '.$sort;
         }
 
-        $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
+        $ufields = user_picture::fields('u');
+        $select = "SELECT $ufields,
                           s.id AS submissionid, s.grade, s.submissioncomment,
                           s.timemodified, s.timemarked,
-                          COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
+                          COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ";
         $sql = 'FROM {user} u '.
                'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
                                                                   AND s.assignment = '.$this->assignment->id.' '.
index 3fb3b29..e151f5b 100644 (file)
@@ -539,11 +539,12 @@ function chat_get_users($chatid, $groupid=0, $groupingid=0) {
         $groupingjoin = '';
     }
 
-    return $DB->get_records_sql("SELECT
-        DISTINCT u.id, u.firstname, u.lastname, u.picture, c.lastmessageping, c.firstping, u.imagealt
-        FROM {chat_users} c JOIN {user} u ON u.id = c.userid $groupingjoin
-        WHERE c.chatid = :chatid $groupselect
-        ORDER BY c.firstping ASC", $params);
+    $ufields = user_picture::fields('u');
+    return $DB->get_records_sql("SELECT DISTINCT $ufields, c.lastmessageping, c.firstping
+                                   FROM {chat_users} c
+                                   JOIN {user} u ON u.id = c.userid $groupingjoin
+                                  WHERE c.chatid = :chatid $groupselect
+                               ORDER BY c.firstping ASC", $params);
 }
 
 /**
@@ -888,7 +889,7 @@ function chat_format_message($message, $courseid, $currentuser, $chat_lastrow=NU
 
     if (isset($users[$message->userid])) {
         $user = $users[$message->userid];
-    } else if ($user = $DB->get_record('user', array('id'=>$message->userid), 'id,picture,firstname,lastname,imagealt')) {
+    } else if ($user = $DB->get_record('user', array('id'=>$message->userid), user_image::fields())) {
         $users[$message->userid] = $user;
     } else {
         return NULL;
@@ -917,7 +918,7 @@ function chat_format_message_theme ($message, $courseid, $currentuser, $theme =
 
     if (isset($users[$message->userid])) {
         $sender = $users[$message->userid];
-    } else if ($sender = $DB->get_record('user', array('id'=>$message->userid), 'id,picture,firstname,lastname,imagealt')) {
+    } else if ($sender = $DB->get_record('user', array('id'=>$message->userid), user_picture::fields())) {
         $users[$message->userid] = $sender;
     } else {
         return NULL;
index 1cc93ea..4fe7770 100644 (file)
@@ -520,7 +520,7 @@ function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish
             if ($choice->showunanswered) {
                 echo "<td></td>";
             }
-            
+
             foreach ($choice->option as $optionid => $optiontext) {
                 echo "<td align=\"center\" class=\"col$count count\">";
                 if ($choice->limitanswers) {
@@ -865,7 +865,7 @@ function choice_get_response_data($choice, $cm, $groupmode) {
 
 /// First get all the users who have access here
 /// To start with we assume they are all "unanswered" then move them later
-    $allresponses[0] = get_enrolled_users($context, 'mod/choice:choose', $currentgroup, 'u.id, u.picture, u.imagealt, u.firstname, u.lastname, u.idnumber', 'u.lastname ASC,u.firstname ASC');
+    $allresponses[0] = get_enrolled_users($context, 'mod/choice:choose', $currentgroup, user_picture::fields('u', array('idnumber')), 'u.lastname ASC,u.firstname ASC');
 
 /// Get all the recorded responses for this choice
     $rawresponses = $DB->get_records('choice_answers', array('choiceid' => $choice->id));
index f8b418e..800e2eb 100644 (file)
@@ -305,7 +305,8 @@ function feedback_get_recent_mod_activity(&$activities, &$index, $timemodified,
 
     $sqlargs = array();
 
-    $sql = " SELECT fk . * , fc . * , u.firstname, u.lastname, u.email, u.picture
+    //TODO: user user_picture::fields;
+    $sql = " SELECT fk . * , fc . * , u.firstname, u.lastname, u.email, u.picture, u.email
                                             FROM {feedback_completed} fc
                                                 JOIN {feedback} fk ON fk.id = fc.feedback
                                                 JOIN {user} u ON u.id = fc.userid ";
@@ -369,6 +370,7 @@ function feedback_get_recent_mod_activity(&$activities, &$index, $timemodified,
         $tmpactivity->content->feedbackid = $feedbackitem->id;
         $tmpactivity->content->feedbackuserid = $feedbackitem->userid;
 
+        //TODO: add all necessary user fields, this is not enough for user_picture
         $tmpactivity->user->userid   = $feedbackitem->userid;
         $tmpactivity->user->fullname = fullname($feedbackitem, $viewfullnames);
         $tmpactivity->user->picture  = $feedbackitem->picture;
index 568aab2..068c0e3 100644 (file)
@@ -2014,7 +2014,8 @@ function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=5
                          u.lastname,
                          u.email,
                          u.picture,
-                         u.imagealt
+                         u.imagealt,
+                         u.email
                     FROM $fromsql
                    WHERE $selectsql
                 ORDER BY p.modified DESC";
@@ -5341,7 +5342,7 @@ function forum_print_posts_flat($course, &$cm, $forum, $discussion, $post, $mode
 
         $postread = !empty($post->postread);
 
-        forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, $link, 
+        forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, $link,
                              '', '', $postread, true, $forumtracked);
     }
 }
@@ -5374,7 +5375,7 @@ function forum_print_posts_threaded($course, &$cm, $forum, $discussion, $parent,
 
                 $postread = !empty($post->postread);
 
-                forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, $link, 
+                forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, $link,
                                      '', '', $postread, true, $forumtracked);
             } else {
                 if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) {
@@ -5481,7 +5482,7 @@ function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $cours
 
     if (!$posts = $DB->get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
                                               d.timestart, d.timeend, d.userid AS duserid,
-                                              u.firstname, u.lastname, u.email, u.picture, u.imagealt
+                                              u.firstname, u.lastname, u.email, u.picture, u.imagealt, u.email
                                          FROM {forum_posts} p
                                               JOIN {forum_discussions} d ON d.id = p.discussion
                                               JOIN {forum} f             ON f.id = d.forum
index 13dce73..181744a 100644 (file)
@@ -901,6 +901,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart,
         $tmpactivity->user->fullname = fullname($attempt, $viewfullnames);
         $tmpactivity->user->picture  = $attempt->picture;
         $tmpactivity->user->imagealt = $attempt->imagealt;
+        $tmpactivity->user->email = $attempt->email;
 
         $activities[$index++] = $tmpactivity;
     }
@@ -1654,7 +1655,7 @@ function quiz_extend_settings_navigation($settings, $quiznode) {
 
     if (has_capability('mod/quiz:manage', $PAGE->cm->context)) {
         $editnode = $quiznode->add(get_string('edit'), null, navigation_node::TYPE_CONTAINER, null, 'quizedit');
-        
+
         $url = new moodle_url('/mod/quiz/edit.php', array('cmid'=>$PAGE->cm->id));
         $text = get_string("editinga", "moodle", get_string('modulename', 'quiz'));
         $editnode->add($text, $url, navigation_node::TYPE_SETTING, null, 'edit', new pix_icon('t/edit', ''));
index 06f5d05..0e1a261 100644 (file)
@@ -125,6 +125,7 @@ class quiz_report_overview_table extends table_sql {
         $user->firstname = $attempt->firstname;
         $user->imagealt = $attempt->imagealt;
         $user->picture = $attempt->picture;
+        $user->email = $attempt->email;
         return $OUTPUT->user_picture($user);
     }
 
index 22f404f..6790a91 100644 (file)
@@ -214,7 +214,7 @@ class quiz_overview_report extends quiz_default_report {
             }
 
             $fields .='qa.uniqueid AS attemptuniqueid, qa.id AS attempt, ' .
-                'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, '.
+                'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email, '.
                 'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
 
             // This part is the same for all cases - join users and quiz_attempts tables
index 93755ba..6890002 100644 (file)
@@ -80,6 +80,7 @@ class quiz_report_responses_table extends table_sql {
         $user->firstname = $attempt->firstname;
         $user->imagealt = $attempt->imagealt;
         $user->picture = $attempt->picture;
+        $user->email = $attempt->email;
         return $OUTPUT->user_picture($user);
     }
 
index 6e20844..221d314 100755 (executable)
 
                 // We only want to show the checkbox to delete attempts
                 // if the user has permissions and if the report mode is showing attempts.
-                $candelete = has_capability('mod/scorm:deleteresponses',$contextmodule) 
+                $candelete = has_capability('mod/scorm:deleteresponses',$contextmodule)
                         && ($attemptsmode!= SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
                 // select the students
                 $nostudents = false;
                     }
                     $allowedlist = join(',', array_keys($groupstudents));
                 }
-                
+
                 if( !$nostudents ) {
-                    
+
                     // Now check if asked download of data
                     if ($download) {
                         $filename = clean_filename("$course->shortname ".format_string($scorm->name,true));
                     }
-                
+
                     // Define table columns
                     $columns = array();
                     $headers = array();
                     } else {
                         $scoes = NULL;
                     }
-                    
+
                     if (!$download) {
                         $table = new flexible_table('mod-scorm-report');
-            
+
                         $table->define_columns($columns);
                         $table->define_headers($headers);
                         $table->define_baseurl($reporturlwithdisplayoptions->out());
-            
+
                         $table->sortable(true);
                         $table->collapsible(true);
-                        
+
                         $table->column_suppress('picture');
                         $table->column_suppress('fullname');
                         $table->column_suppress('idnumber');
-                        
+
                         $table->no_sorting('start');
                         $table->no_sorting('finish');
                         $table->no_sorting('score');
                                 }
                             }
                         }
-                        
+
                         $table->column_class('picture', 'picture');
                         $table->column_class('fullname', 'bold');
                         $table->column_class('score', 'bold');
-            
+
                         $table->set_attribute('cellspacing', '0');
                         $table->set_attribute('id', 'attempts');
                         $table->set_attribute('class', 'generaltable generalbox');
-                        
+
                         // Start working -- this is necessary as soon as the niceties are over
                         $table->setup();
                     } else if ($download =='ODS') {
                         require_once("$CFG->libdir/odslib.class.php");
-            
+
                         $filename .= ".ods";
                         // Creating a workbook
                         $workbook = new MoodleODSWorkbook("-");
                         $formatg->set_color('green');
                         $formatg->set_align('center');
                         // Here starts workshhet headers
-            
+
                         $colnum = 0;
                         foreach ($headers as $item) {
                             $myxls->write(0,$colnum,$item,$formatbc);
                         $rownum=1;
                     } else if ($download =='Excel') {
                         require_once("$CFG->libdir/excellib.class.php");
-            
+
                         $filename .= ".xls";
                         // Creating a workbook
                         $workbook = new MoodleExcelWorkbook("-");
                         $formatg->set_bold(1);
                         $formatg->set_color('green');
                         $formatg->set_align('center');
-            
+
                         $colnum = 0;
                         foreach ($headers as $item) {
                             $myxls->write(0,$colnum,$item,$formatbc);
 
                     // Construct the SQL
                     $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, ';
-                    $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . 
-                            'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt ';
+                    $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' .
+                            'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email ';
 
                     // This part is the same for all cases - join users and scorm_scoes_track tables
                     $from = 'FROM '.$CFG->prefix.'user u ';
                             $where = ' WHERE u.id IN (' .$allowedlist. ') AND (st.userid IS NOT NULL OR st.userid IS NULL)';
                             break;
                     }
-                    
+
                     $countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').')) AS nbresults, ';
                     $countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'','st.attempt').')) AS nbattempts, ';
                     $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
                     $countsql .= $from.$where;
-                    
+
                     if (!$download) {
                         $sort = $table->get_sql_sort();
                     }
                         }
 
                         $table->pagesize($pagesize, $total);
-                        
+
                         echo '<div class="quizattemptcounts">';
                         if ( $count->nbresults == $count->nbattempts ) {
                             echo get_string('reportcountattempts','scorm', $count);
                             }
                             if (in_array('picture', $columns)){
                                 $user = (object)array('id'=>$scouser->userid,
-                                                      'picture'=>$scouser->picture, 
-                                                      'imagealt'=>$scouser->imagealt, 
+                                                      'picture'=>$scouser->picture,
+                                                      'imagealt'=>$scouser->imagealt,
+                                                      'email'=>$scouser->email,
                                                       'firstname'=>$scouser->firstname,
                                                       'lastname'=>$scouser->lastname);
                                 $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
                                 else $row[] = userdate($timetracks->start);
                                 if ($download =='ODS' || $download =='Excel' ) $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
                                 else $row[] = userdate($timetracks->finish);
-                                
+
                                 $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
                             }
                             // print out all scores of attempt
                                     }
                                 }
                             }
-                            
+
                             if (!$download) {
                                 $table->add_data($row);
                             } else if ($download == 'Excel' or $download == 'ODS') {
index d26ac1a..db0a7dc 100644 (file)
@@ -204,7 +204,7 @@ class workshop_manual_allocator implements workshop_allocator {
         }
 
         // this will hold the information needed to display user names and pictures
-        $userinfo = $DB->get_records_list('user', 'id', array_keys($participants), '', 'id,lastname,firstname,picture,imagealt');
+        $userinfo = $DB->get_records_list('user', 'id', array_keys($participants), '', user_picture::fields());
 
         // load the participants' submissions
         $submissions = $this->workshop->get_submissions(array_keys($participants));
@@ -216,6 +216,7 @@ class workshop_manual_allocator implements workshop_allocator {
                 $userinfo[$submission->authorid]->lastname  = $submission->authorlastname;
                 $userinfo[$submission->authorid]->picture   = $submission->authorpicture;
                 $userinfo[$submission->authorid]->imagealt  = $submission->authorimagealt;
+                $userinfo[$submission->authorid]->email     = $submission->authoremail;
             }
         }
 
@@ -224,7 +225,7 @@ class workshop_manual_allocator implements workshop_allocator {
         if ($submissions) {
             list($submissionids, $params) = $DB->get_in_or_equal(array_keys($submissions), SQL_PARAMS_NAMED);
             $sql = "SELECT a.id AS assessmentid, a.submissionid,
-                           r.id AS reviewerid, r.lastname, r.firstname, r.picture, r.imagealt,
+                           r.id AS reviewerid, r.lastname, r.firstname, r.picture, r.imagealt, e.email,
                            s.id AS submissionid, s.authorid
                       FROM {workshop_assessments} a
                       JOIN {user} r ON (a.reviewerid = r.id)
@@ -239,6 +240,7 @@ class workshop_manual_allocator implements workshop_allocator {
                     $userinfo[$reviewer->reviewerid]->lastname  = $reviewer->lastname;
                     $userinfo[$reviewer->reviewerid]->picture   = $reviewer->picture;
                     $userinfo[$reviewer->reviewerid]->imagealt  = $reviewer->imagealt;
+                    $userinfo[$reviewer->reviewerid]->email     = $reviewer->email;
                 }
             }
         }
@@ -251,7 +253,7 @@ class workshop_manual_allocator implements workshop_allocator {
             $sql = "SELECT a.id AS assessmentid, a.submissionid,
                            u.id AS reviewerid,
                            s.id AS submissionid,
-                           e.id AS revieweeid, e.lastname, e.firstname, e.picture, e.imagealt
+                           e.id AS revieweeid, e.lastname, e.firstname, e.picture, e.imagealt, e.email
                       FROM {user} u
                       JOIN {workshop_assessments} a ON (a.reviewerid = u.id)
                       JOIN {workshop_submissions} s ON (a.submissionid = s.id)
@@ -266,6 +268,7 @@ class workshop_manual_allocator implements workshop_allocator {
                     $userinfo[$reviewee->revieweeid]->lastname  = $reviewee->lastname;
                     $userinfo[$reviewee->revieweeid]->picture   = $reviewee->picture;
                     $userinfo[$reviewee->revieweeid]->imagealt  = $reviewee->imagealt;
+                    $userinfo[$reviewee->revieweeid]->email     = $reviewee->email;
                 }
             }
         }
@@ -340,7 +343,7 @@ class workshop_manual_allocator implements workshop_allocator {
         $params['workshopid'] = $this->workshop->id;
 
         $sql = "SELECT author.id AS authorid, author.firstname AS authorfirstname, author.lastname AS authorlastname,
-                       author.picture AS authorpicture, author.imagealt AS authorimagealt,
+                       author.picture AS authorpicture, author.imagealt AS authorimagealt, author.email AS authoremail,
                        s.id AS submissionid, s.title AS submissiontitle, s.grade AS submissiongrade,
                        a.id AS assessmentid, a.timecreated AS timeallocated, a.reviewerid,
                        reviewer.firstname AS reviewerfirstname, reviewer.lastname AS reviewerlastname,
index 94bbc94..62cc8fe 100644 (file)
@@ -489,9 +489,9 @@ class workshop {
         $sql = 'SELECT s.id, s.workshopid, s.example, s.authorid, s.timecreated, s.timemodified,
                        s.title, s.grade, s.gradeover, s.gradeoverby, s.published,
                        u.lastname AS authorlastname, u.firstname AS authorfirstname,
-                       u.picture AS authorpicture, u.imagealt AS authorimagealt,
+                       u.picture AS authorpicture, u.imagealt AS authorimagealt, u.email AS authoremail,
                        t.lastname AS overlastname, t.firstname AS overfirstname,
-                       t.picture AS overpicture, t.imagealt AS overimagealt
+                       t.picture AS overpicture, t.imagealt AS overimagealt, t.email AS overemail
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.authorid = u.id)
              LEFT JOIN {user} t ON (s.gradeoverby = t.id)
@@ -526,7 +526,7 @@ class workshop {
         // from other instances
         $sql = 'SELECT s.*,
                        u.lastname AS authorlastname, u.firstname AS authorfirstname, u.id AS authorid,
-                       u.picture AS authorpicture, u.imagealt AS authorimagealt
+                       u.picture AS authorpicture, u.imagealt AS authorimagealt, u.email AS authoremail
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.authorid = u.id)
                  WHERE s.example = 0 AND s.workshopid = :workshopid AND s.id = :id';
@@ -548,7 +548,7 @@ class workshop {
         }
         $sql = 'SELECT s.*,
                        u.lastname AS authorlastname, u.firstname AS authorfirstname, u.id AS authorid,
-                       u.picture AS authorpicture, u.imagealt AS authorimagealt
+                       u.picture AS authorpicture, u.imagealt AS authorimagealt, u.email AS authoremail
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.authorid = u.id)
                  WHERE s.example = 0 AND s.workshopid = :workshopid AND s.authorid = :authorid';
@@ -567,7 +567,7 @@ class workshop {
         $sql = "SELECT s.id, s.authorid, s.timecreated, s.timemodified,
                        s.title, s.grade, s.gradeover, COALESCE(s.gradeover,s.grade) AS finalgrade,
                        u.lastname AS authorlastname, u.firstname AS authorfirstname, u.id AS authorid,
-                       u.picture AS authorpicture, u.imagealt AS authorimagealt
+                       u.picture AS authorpicture, u.imagealt AS authorimagealt, u.email AS authoremail
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.authorid = u.id)
                  WHERE s.example = 0 AND s.workshopid = :workshopid AND s.published = 1
@@ -778,7 +778,7 @@ class workshop {
                        s.id AS submissionid, s.title AS submissiontitle, s.timecreated AS submissioncreated,
                        s.timemodified AS submissionmodified,
                        author.id AS authorid, author.firstname AS authorfirstname,author.lastname AS authorlastname,
-                       author.picture AS authorpicture, author.imagealt AS authorimagealt
+                       author.picture AS authorpicture, author.imagealt AS authorimagealt, author.email AS authoremail
                   FROM {workshop_assessments} a
             INNER JOIN {user} reviewer ON (a.reviewerid = reviewer.id)
             INNER JOIN {workshop_submissions} s ON (a.submissionid = s.id)
@@ -1219,7 +1219,7 @@ class workshop {
             $params['workshopid1'] = $this->id;
             $params['workshopid2'] = $this->id;
             $sqlsort = $sortby . ' ' . $sorthow . ',u.lastname,u.firstname,u.id';
-            $sql = "SELECT u.id AS userid,u.firstname,u.lastname,u.picture,u.imagealt,
+            $sql = "SELECT u.id AS userid,u.firstname,u.lastname,u.picture,u.imagealt,u.email,
                            s.title AS submissiontitle, s.grade AS submissiongrade, ag.gradinggrade
                       FROM {user} u
                  LEFT JOIN {workshop_submissions} s ON (s.authorid = u.id AND s.workshopid = :workshopid1 AND s.example = 0)
@@ -1243,6 +1243,7 @@ class workshop {
                 $userinfo[$participant->userid]->lastname  = $participant->lastname;
                 $userinfo[$participant->userid]->picture   = $participant->picture;
                 $userinfo[$participant->userid]->imagealt  = $participant->imagealt;
+                $userinfo[$participant->userid]->email     = $participant->email;
             }
         }
 
@@ -1258,6 +1259,7 @@ class workshop {
                 $userinfo[$submission->gradeoverby]->lastname  = $submission->overlastname;
                 $userinfo[$submission->gradeoverby]->picture   = $submission->overpicture;
                 $userinfo[$submission->gradeoverby]->imagealt  = $submission->overimagealt;
+                $userinfo[$submission->gradeoverby]->email     = $submission->overemail;
             }
         }
 
@@ -1266,7 +1268,7 @@ class workshop {
         if ($submissions) {
             list($submissionids, $params) = $DB->get_in_or_equal(array_keys($submissions), SQL_PARAMS_NAMED);
             $sql = "SELECT a.id AS assessmentid, a.submissionid, a.grade, a.gradinggrade, a.gradinggradeover, a.weight,
-                           r.id AS reviewerid, r.lastname, r.firstname, r.picture, r.imagealt,
+                           r.id AS reviewerid, r.lastname, r.firstname, r.picture, r.imagealt, r.email,
                            s.id AS submissionid, s.authorid
                       FROM {workshop_assessments} a
                       JOIN {user} r ON (a.reviewerid = r.id)
@@ -1282,6 +1284,7 @@ class workshop {
                     $userinfo[$reviewer->reviewerid]->lastname  = $reviewer->lastname;
                     $userinfo[$reviewer->reviewerid]->picture   = $reviewer->picture;
                     $userinfo[$reviewer->reviewerid]->imagealt  = $reviewer->imagealt;
+                    $userinfo[$reviewer->reviewerid]->email     = $reviewer->email;
                 }
             }
         }
@@ -1293,7 +1296,7 @@ class workshop {
             $params['workshopid'] = $this->id;
             $sql = "SELECT a.id AS assessmentid, a.submissionid, a.grade, a.gradinggrade, a.gradinggradeover, a.reviewerid, a.weight,
                            s.id AS submissionid,
-                           e.id AS authorid, e.lastname, e.firstname, e.picture, e.imagealt
+                           e.id AS authorid, e.lastname, e.firstname, e.picture, e.imagealt, e.email
                       FROM {user} u
                       JOIN {workshop_assessments} a ON (a.reviewerid = u.id)
                       JOIN {workshop_submissions} s ON (a.submissionid = s.id AND s.example = 0)
@@ -1309,6 +1312,7 @@ class workshop {
                     $userinfo[$reviewee->authorid]->lastname  = $reviewee->lastname;
                     $userinfo[$reviewee->authorid]->picture   = $reviewee->picture;
                     $userinfo[$reviewee->authorid]->imagealt  = $reviewee->imagealt;
+                    $userinfo[$reviewee->authorid]->email     = $reviewee->email;
                 }
             }
         }
index ebc253c..d3a7615 100644 (file)
@@ -96,7 +96,7 @@ class mod_workshop_renderer extends plugin_renderer_base {
      * Display a short summary of the submission
      *
      * The passed submission object must define at least: id, title, timecreated, timemodified,
-     * authorid, authorfirstname, authorlastname, authorpicture and authorimagealt. Optional
+     * authorid, authorfirstname, authorlastname, authorpicture, authorimagealt and email. Optional
      * property is status (graded, notgraded).
      *
      * @param stdclass $submission     The submission record
@@ -122,6 +122,7 @@ class mod_workshop_renderer extends plugin_renderer_base {
             $author->lastname   = $submission->authorlastname;
             $author->picture    = $submission->authorpicture;
             $author->imagealt   = $submission->authorimagealt;
+            $author->email      = $submission->authoremail;
             $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35));
             $userurl            = new moodle_url('/user/view.php',
                                             array('id' => $author->id, 'course' => $this->page->course->id));
@@ -180,6 +181,7 @@ class mod_workshop_renderer extends plugin_renderer_base {
             $author->lastname   = $submission->authorlastname;
             $author->picture    = $submission->authorpicture;
             $author->imagealt   = $submission->authorimagealt;
+            $author->email      = $submission->authoremail;
             $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 64));
             $userurl            = new moodle_url('/user/view.php',
                                             array('id' => $author->id, 'course' => $this->page->course->id));
index 0916c51..183161e 100644 (file)
@@ -259,6 +259,7 @@ case workshop::PHASE_ASSESSMENT:
                 $submission->authorlastname     = $assessment->authorlastname;
                 $submission->authorpicture      = $assessment->authorpicture;
                 $submission->authorimagealt     = $assessment->authorimagealt;
+                $submission->authoremail        = $assessment->authoremail;
                 if (is_null($assessment->grade)) {
                     $class = ' notgraded';
                     $submission->status = 'notgraded';
@@ -342,6 +343,7 @@ case workshop::PHASE_EVALUATION:
             $submission->authorlastname     = $assessment->authorlastname;
             $submission->authorpicture      = $assessment->authorpicture;
             $submission->authorimagealt     = $assessment->authorimagealt;
+            $submission->authoremail        = $assessment->authoremail;
 
             if (is_null($assessment->grade)) {
                 $class = ' notgraded';
index 111a2a5..3c81e44 100644 (file)
@@ -174,7 +174,7 @@ class rating_manager {
     */
     public function delete_ratings($options) {
         global $DB;
-        
+
         if( !empty($options->ratingid) ) {
             //delete a single rating
             $DB->delete_records('rating', array('contextid'=>$options->contextid, 'id'=>$options->ratingid) );
@@ -207,9 +207,8 @@ class rating_manager {
             $sortclause = "ORDER BY $options->sort";
         }
 
-        $userfields = user_picture::fields('u','uid');
-        $sql = "SELECT r.id, r.rating, r.itemid, r.userid, r.timemodified,
-                    $userfields
+        $userfields = user_picture::fields('u', null, 'uid');
+        $sql = "SELECT r.id, r.rating, r.itemid, r.userid, r.timemodified, $userfields
                 FROM {rating} r
                 LEFT JOIN {user} u ON r.userid = u.id
                 WHERE r.contextid = :contextid AND
@@ -350,7 +349,7 @@ class rating_manager {
         $plugintype = !empty($options->plugintype) ? $options->plugintype : null;
         $pluginname = !empty($options->pluginname) ? $options->pluginname : null;
         $pluginpermissionsarray = $this->get_plugin_permissions_array($options->context->id, $plugintype, $pluginname);
-        
+
         $settings->pluginpermissions = new stdclass();
         $settings->pluginpermissions->view = $pluginpermissionsarray['view'];
         $settings->pluginpermissions->viewany = $pluginpermissionsarray['viewany'];
@@ -462,7 +461,7 @@ class rating_manager {
         else if ( !empty($options->modulename) && !empty($options->moduleid) ) {
             $modulename = $options->modulename;
             $moduleid   = $options->moduleid;
-            
+
             //going direct to the db for the context id seems wrong
             list($ctxselect, $ctxjoin) = context_instance_preload_sql('cm.id', CONTEXT_MODULE, 'ctx');
             $sql = "SELECT cm.* $ctxselect
@@ -485,7 +484,7 @@ class rating_manager {
 
         $sql = "SELECT :userid1 as id, :userid2 AS userid, $aggregationstring(r.rating) AS rawgrade
                 FROM {rating} r
-                WHERE r.contextid=:contextid 
+                WHERE r.contextid=:contextid
                     AND r.itemid IN (SELECT i.id AS itemid FROM {{$itemtable}} i WHERE i.{$itemtableusercolumn} = :userid3)";
 
         $results = $DB->get_records_sql($sql, $params);
@@ -593,7 +592,7 @@ class rating_manager {
                     return true;
                 }
             }
-            
+
             return false;//item doesn't exist or belongs to the current user
         } else {
             return true;//callback doesn't exist