From 5750729092ecf0144379206bc191209792008953 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 2 Aug 2002 17:41:14 +0000 Subject: [PATCH] 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. --- lib/moodlelib.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index ae1b1978ba..e674fb45e2 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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"); } -- 2.39.5