Returns all users and their lowest status in a course.
authorSyxton <davidso1@rose-hulman.edu>
Fri, 11 Sep 2015 13:24:35 +0000 (09:24 -0400)
committerDan Marsden <dan@danmarsden.com>
Thu, 24 Sep 2015 00:37:02 +0000 (12:37 +1200)
This will fix 2 issues.  The first, if a user has a suspended enrollment
in child course A, the active enrollment in child course B will be
honored over the suspended enrollment.  Also in this scenerio, the user
with multiple enrollments was causing a duplicate userid error to be
generated.

locallib.php

index 21c9b9d..6b3b264 100644 (file)
@@ -1042,7 +1042,7 @@ class attendance {
             $maxtime = 'CASE WHEN MIN(ue.timeend) = 0 THEN 0 ELSE MAX(ue.timeend) END';
 
             // CONTRIB-3549
-            $sql = "SELECT ue.userid, ue.status,
+            $sql = "SELECT ue.userid, MIN(ue.status) as status,
                            $mintime AS mintime,
                            $maxtime AS maxtime
                       FROM {user_enrolments} ue
@@ -1050,7 +1050,7 @@ class attendance {
                      WHERE ue.userid $sql
                            AND e.status = :estatus
                            AND e.courseid = :courseid
-                  GROUP BY ue.userid, ue.status";
+                  GROUP BY ue.userid";
             $params += array('zerotime'=>0, 'estatus'=>ENROL_INSTANCE_ENABLED, 'courseid'=>$this->course->id);
             $enrolments = $DB->get_records_sql($sql, $params);