Permalink
Browse files

get_course_users was buggy when teachers or students was empty.

The SQL looked good to me, but I had to do it another way to make
it work.
  • Loading branch information...
martin
martin committed Aug 2, 2002
1 parent 9084509 commit 5750729092ecf0144379206bc191209792008953
Showing with 17 additions and 4 deletions.
  1. +17 −4 lib/moodlelib.php
View
@@ -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");
}

0 comments on commit 5750729

Please sign in to comment.