]> git.mjollnir.org Git - moodle.git/commitdiff
get_course_users now calls get_site_users if the course is a site.
authormoodler <moodler>
Tue, 20 May 2003 09:33:30 +0000 (09:33 +0000)
committermoodler <moodler>
Tue, 20 May 2003 09:33:30 +0000 (09:33 +0000)
There is something wrong with this SQL still though ... it mostly works
but I'm still getting wierd behaviour with small numbers of users.

Need some help here ...  for example just look at get_site_users()
on your test site.

It's supposed to return a list of users who are admins, creators,
teachers or students

lib/datalib.php
mod/choice/report.php
mod/choice/view.php

index 075a4df76436e795fda8e514ddaed8c71a3a7e0a..4599ef7ebdd7043a960a742ef4e0653e4e474879 100644 (file)
@@ -895,7 +895,16 @@ function get_course_teachers($courseid, $sort="t.authority ASC") {
 }
 
 function get_course_users($courseid, $sort="u.lastaccess DESC") {
-/// Using this method because the direct SQL just would not always work!
+/// Returns all the users of a course: students and teachers
+/// If the "course" is actually the site, then return all site users.
+
+    $site = get_site();
+
+    if ($courseid == $site->id) {
+        return get_site_users($sort);
+    }
+
+    /// Using this method because the single SQL just would not always work!
 
     $teachers = get_course_teachers($courseid, $sort);
     $students = get_course_students($courseid, $sort);
@@ -908,26 +917,34 @@ function get_course_users($courseid, $sort="u.lastaccess DESC") {
         return $students;
     }
 
-///    return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
-///                            WHERE (s.course = '$courseid' AND s.userid = u.id) OR 
-///                                  (t.course = '$courseid' AND t.userid = u.id)
-///                            ORDER BY $sort");
+    /// Why wouldn't this work?
+    ///    return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
+    ///                            WHERE (s.course = '$courseid' AND s.userid = u.id) OR 
+    ///                                  (t.course = '$courseid' AND t.userid = u.id)
+    ///                            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;
+    global $CFG, $db;
+
+    //$db->debug = true;
 
     return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay,
                                    u.email, u.city, u.country, u.lastaccess, u.lastlogin, u.picture
                               FROM {$CFG->prefix}user u, 
                                    {$CFG->prefix}user_students s, 
-                                   {$CFG->prefix}user_teachers t
+                                   {$CFG->prefix}user_teachers t,
+                                   {$CFG->prefix}user_coursecreators c,
+                                   {$CFG->prefix}user_admins a
                              WHERE s.userid = u.id 
                                 OR t.userid = u.id
-                             GROUP BY u.id ORDER BY $sort");
+                                OR a.userid = u.id
+                                OR c.userid = u.id
+                             GROUP BY u.id 
+                             ORDER BY $sort ");
 }
 
 
index 77120d2b233723f635c61c7dd2340d3651ba1efa..842caddcc446a926cb2efa6fbf91c16acce2d49a 100644 (file)
                   <a href=\"view.php?id=$cm->id\">$choice->name</a> -> $strresponses", "");
 
 
-    if ($course->category) {
-        if (! $users = get_course_users($course->id, "u.firstname ASC")) {
-            error("No users found (very strange)");
-        }
-    } else {
-        if (! $users = get_site_users("u.firstname ASC")) {
-            error("No users found (very strange)");
-        }
+    if (! $users = get_course_users($course->id, "u.firstname ASC")) {
+        error("No users found (very strange)");
     }
 
     if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) {
index f71198c1115a7672aaa1afc6463d22619387418c..c8e1432a1e813c6df076f453228ac2a100ccc7b0 100644 (file)
 
         print_heading(get_string("responses", "choice"));
 
-        if ($course->category) {
-            if (! $users = get_course_users($course->id, "u.firstname ASC")) {
-                error("No users found (very strange)");
-            }
-        } else {
-            if (! $users = get_site_users("u.firstname ASC")) {
-                error("No users found (very strange)");
-            }
+        if (! $users = get_course_users($course->id, "u.firstname ASC")) {
+            error("No users found (very strange)");
         }
 
         if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) {