MDL-22910 workaround for inability of Oracle and MS sql to find distinct text fields...
authorPetr Skoda <skodak@moodle.org>
Wed, 30 Jun 2010 20:42:11 +0000 (20:42 +0000)
committerPetr Skoda <skodak@moodle.org>
Wed, 30 Jun 2010 20:42:11 +0000 (20:42 +0000)
enrol/users.php
lib/outputcomponents.php
mod/feedback/lib.php
mod/lesson/essay.php

index e9ee25b..2bce0d4 100644 (file)
@@ -299,7 +299,8 @@ $sqltotal = "SELECT COUNT(DISTINCT u.id)
                JOIN {enrol} e ON (e.id = ue.enrolid)";
 $totalusers = $DB->count_records_sql($sqltotal, $params);
 
-$sql = "SELECT DISTINCT u.*, ul.timeaccess AS lastseen
+$ufields = user_picture::fields('u');
+$sql = "SELECT DISTINCT $ufields, ul.timeaccess AS lastseen
           FROM {user} u
           JOIN {user_enrolments} ue ON (ue.userid = u.id  AND ue.enrolid $instancessql)
           JOIN {enrol} e ON (e.id = ue.enrolid)
index 6c0f656..71b507c 100644 (file)
@@ -296,10 +296,10 @@ class user_picture implements renderable {
      * List of mandatory fields in user record here.
      * @var string
      */
-    const FIELDS = 'id,picture,firstname,lastname,imagealt';
+    const FIELDS = 'id,picture,firstname,lastname,imagealt,email'; //note: the email will be useful for gravatar support int the future ;-)
 
     /**
-     * @var object $user A user object with at least fields id, picture, imagealt, firstname and lastname set.
+     * @var object $user A user object with at least fields all columns specified in FIELDS constant set.
      */
     public $user;
     /**
index f82f8f7..0f8f2b7 100644 (file)
@@ -827,7 +827,8 @@ function feedback_get_complete_users($cm, $group = false, $where, $sort = '', $s
         $sortsql = '';
     }
 
-    $sql = 'SELECT DISTINCT u.* FROM {user} u, {feedback_completed} c'.$fromgroup.'
+    $ufields = user_picture::fields('u');
+    $sql = 'SELECT DISTINCT '.$ufields.' FROM {user} u, {feedback_completed} c'.$fromgroup.'
               WHERE '.$where.' anonymous_response = ? AND u.id = c.userid AND c.feedback = ?
               '.$wheregroup.$sortsql;
               ;
index a034f1f..16714ef 100644 (file)
@@ -242,9 +242,10 @@ switch ($mode) {
             list($usql, $parameters) = $DB->get_in_or_equal(array_keys($pages));
             if ($essayattempts = $DB->get_records_select('lesson_attempts', 'pageid '.$usql, $parameters)) {
                 // Get all the users who have taken this lesson, order by their last name
+                $ufields = user_picture::fields('u');
                 if (!empty($cm->groupingid)) {
                     $params["groupinid"] = $cm->groupingid;
-                    $sql = "SELECT DISTINCT u.*
+                    $sql = "SELECT DISTINCT $ufields
                             FROM {lesson_attempts} a
                                 INNER JOIN {user} u ON u.id = a.userid
                                 INNER JOIN {groups_members} gm ON gm.userid = u.id
@@ -252,7 +253,7 @@ switch ($mode) {
                             WHERE a.lessonid = :lessonid
                             ORDER BY u.lastname";
                 } else {
-                    $sql = "SELECT DISTINCT u.*
+                    $sql = "SELECT DISTINCT $ufields
                             FROM {user} u,
                                  {lesson_attempts} a
                             WHERE a.lessonid = :lessonid and