From 257e3f4c61a0e9b2da11aeb85e2ac8ee13fd2b73 Mon Sep 17 00:00:00 2001 From: defacer Date: Tue, 12 Apr 2005 01:09:31 +0000 Subject: [PATCH] Utilize $CFG->calendar_adminseesall and part of Penny's patches (for bug 2804) to improve performance: if the admin wants to see all events, there's no need to make even one query for course groupmode. --- calendar/lib.php | 51 +++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index 3c3ec0fe076..ee6dae131e7 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -980,7 +980,9 @@ function calendar_set_referring_course($courseid) { } function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NULL, $groupeventsfrom = NULL, $ignorefilters = false) { - global $SESSION, $USER; + global $SESSION, $USER, $CFG; + + //$GLOBALS['db']->debug = true; // Insidious bug-wannabe: setting $SESSION->cal_courses_shown to $course->id would cause // the code to function incorrectly UNLESS we convert it to an integer. One case where @@ -1035,33 +1037,42 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU else if(is_array($groupeventsfrom)) { $groupcourses = array_keys($groupeventsfrom); } - $grouparray = array(); - // We already have the courses to examine in $courses - // For each course... - foreach($groupcourses as $courseid) { - // If the user is an editing teacher in there, - if(!empty($USER->id) && isteacheredit($courseid, $USER->id)) { - // Show events from all groups - if(($grouprecords = get_groups($courseid)) !== false) { - $grouparray = array_merge($grouparray, array_keys($grouprecords)); - } - } - // Otherwise show events from the group he is a member of - else if(isset($USER->groupmember[$courseid])) { - $grouparray[] = $USER->groupmember[$courseid]; - } - } - if(empty($grouparray)) { - $group = false; + if(isadmin() && !empty($CFG->calendar_adminseesall)) { + $group = true; } else { - $group = $grouparray; + $grouparray = array(); + + // We already have the courses to examine in $courses + // For each course... + foreach($groupcourses as $courseid) { + // If the user is an editing teacher in there, + if(!empty($USER->id) && isteacheredit($courseid, $USER->id)) { + // Show events from all groups + if(($grouprecords = get_groups($courseid)) !== false) { + $grouparray = array_merge($grouparray, array_keys($grouprecords)); + } + } + // Otherwise show events from the group he is a member of + else if(isset($USER->groupmember[$courseid])) { + $grouparray[] = $USER->groupmember[$courseid]; + } + } + if(empty($grouparray)) { + $group = false; + } + else { + $group = $grouparray; + } } + } else { $group = false; } + + $GLOBALS['db']->debug = false; } function calendar_edit_event_allowed($event) {