]> git.mjollnir.org Git - moodle.git/commitdiff
What was I thinking? This is much cleaner (and no duplicates).
authormoodler <moodler>
Sat, 29 Mar 2003 04:08:51 +0000 (04:08 +0000)
committermoodler <moodler>
Sat, 29 Mar 2003 04:08:51 +0000 (04:08 +0000)
lib/datalib.php
mod/forum/lib.php

index e5755fc82fb33a1579a6dbc350fe797e420f0e30..73a544e7d5e5a2765320c723a9e5396e5c4a63d8 100644 (file)
@@ -818,35 +818,25 @@ function get_teacher($courseid) {
     }
 }
 
-function get_course_students($courseid=0, $sort="u.lastaccess DESC") {
+function get_course_students($courseid, $sort="u.lastaccess DESC") {
 /// Returns list of all students in this course
 /// if courseid = 0 then return ALL students in all courses
 
     global $CFG;
 
-    $selectcourse = "";
-    if (!empty($courseid)) {
-        $selectcourse = "s.course = '$courseid' AND ";
-    }
-
     return get_records_sql("SELECT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}user_students s
-                            WHERE $selectcourse s.userid = u.id AND u.deleted = '0'
+                            WHERE s.course = '$courseid' AND s.userid = u.id AND u.deleted = '0'
                             ORDER BY $sort");
 }
 
-function get_course_teachers($courseid=0, $sort="t.authority ASC") {
+function get_course_teachers($courseid, $sort="t.authority ASC") {
 /// Returns list of all teachers in this course
 /// if courseid = 0 then return ALL teachers in all courses
 
     global $CFG;
 
-    $selectcourse = "";
-    if (!empty($courseid)) {
-        $selectcourse = "t.course = '$courseid' AND ";
-    }
-
     return get_records_sql("SELECT u.*,t.authority,t.role FROM {$CFG->prefix}user u, {$CFG->prefix}user_teachers t
-                            WHERE $selectcourse t.userid = u.id AND u.deleted = '0'
+                            WHERE t.course = '$courseid' AND t.userid = u.id AND u.deleted = '0'
                             ORDER BY $sort");
 }
 
@@ -870,6 +860,20 @@ function get_course_users($courseid, $sort="u.lastaccess DESC") {
 ///                            ORDER BY $sort");
 }
 
+function get_site_users($sort="u.lastaccess DESC") {
+/// Returns a list of all active users who are enrolled 
+/// or teaching in courses on this server
+
+    global $CFG;
+
+    return get_records_sql("SELECT u.* FROM {$CFG->prefix}user u, 
+                                            {$CFG->prefix}user_students s, 
+                                            {$CFG->prefix}user_teachers t
+                            WHERE s.userid = u.id 
+                               OR t.userid = u.id
+                            GROUP BY u.id ORDER BY $sort");
+}
+
 function get_users_search($search, $sort="u.firstname ASC") {
     global $CFG;
 
index 76fbcc1445140254926572f2b3019def17a34972..b8f995ef9c2e79ae007436bc0a82cb1d6c3457cd 100644 (file)
@@ -623,7 +623,7 @@ function forum_subscribed_users($course, $forum) {
         if ($course->category) {
             return get_course_users($course->id);
         } else {
-            return get_course_users(0);   // ALL SITE USERS
+            return get_site_users();
         }
     }
     return get_records_sql("SELECT u.*