From: moodler Date: Tue, 20 May 2003 09:33:30 +0000 (+0000) Subject: get_course_users now calls get_site_users if the course is a site. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=353d033843a51af951c2f3a56756724289b445db;p=moodle.git get_course_users now calls get_site_users if the course is a site. 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 --- diff --git a/lib/datalib.php b/lib/datalib.php index 075a4df764..4599ef7ebd 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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 "); } diff --git a/mod/choice/report.php b/mod/choice/report.php index 77120d2b23..842caddcc4 100644 --- a/mod/choice/report.php +++ b/mod/choice/report.php @@ -35,14 +35,8 @@ id\">$choice->name -> $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)) { diff --git a/mod/choice/view.php b/mod/choice/view.php index f71198c111..c8e1432a1e 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -101,14 +101,8 @@ 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)) {