]> git.mjollnir.org Git - moodle.git/commitdiff
get_course_users was buggy when teachers or students was empty.
authormartin <martin>
Fri, 2 Aug 2002 17:41:14 +0000 (17:41 +0000)
committermartin <martin>
Fri, 2 Aug 2002 17:41:14 +0000 (17:41 +0000)
The SQL looked good to me, but I had to do it another way to make
it work.

lib/moodlelib.php

index ae1b1978bac447c68f67da0a5d55efefa2d3a138..e674fb45e2736fd2ff44ef59c0bd0e7343802045 100644 (file)
@@ -1040,10 +1040,23 @@ function get_course_teachers($courseid, $sort="t.authority ASC") {
 }
 
 function get_course_users($courseid, $sort="u.lastaccess DESC") {
-    return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
-                            WHERE (s.course = '$courseid' AND s.user = u.id) OR 
-                                  (t.course = '$courseid' AND t.user = u.id)
-                            ORDER BY $sort");
+// Using this method because the direct SQL just would not always work!
+
+    $teachers = get_course_teachers($courseid, $sort);
+    $students = get_course_students($courseid, $sort);
+
+    if ($teachers and $students) {
+        return array_merge($teachers, $students);
+    } else if ($teachers) {
+        return $teachers;
+    } else {
+        return $students;
+    }
+
+//    return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
+//                            WHERE (s.course = '$courseid' AND s.user = u.id) OR 
+//                                  (t.course = '$courseid' AND t.user = u.id)
+//                            ORDER BY $sort");
 }