From 37875ac5b748b5ddfd208860f2d9aed45de6c68a Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:53:33 +0000 Subject: [PATCH] calendar/lib: calendar_set_filters() use pre-fetched context and course recs Showing the calendar block was causing 2 DB queries per course the user is enrolled in. Instead, use the data available in the array that is passed as a parameter, and spare the DB a ton of needless traffic. Fixes MDL-11221 Calendar not using context stuff from get_my_courses Author: Martin Dougiamas --- calendar/lib.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/calendar/lib.php b/calendar/lib.php index a2869dc8ce..1eac3efa43 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -1314,10 +1314,19 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU foreach($groupcourses as $courseid) { + if (!isset($courseeventsfrom[$courseid]->context)) { // SHOULD be set MDL-11221 + $courseeventsfrom[$courseid]->context = get_context_instance(CONTEXT_COURSE, $courseid); + } + // If the user is an editing teacher in there, - if(!empty($USER->id) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $courseid))) { + if (!empty($USER->id) && has_capability('moodle/calendar:manageentries', $courseeventsfrom[$courseid]->context)) { // If this course has groups, show events from all of them if(is_int($groupeventsfrom)) { + if (is_object($courseeventsfrom[$courseid])) { // SHOULD be set MDL-11221 + $courserecord = $courseeventsfrom[$courseid]; + } else { + $courserecord = get_record('course', 'id', $courseid); + } $courserecord = get_record('course', 'id', $courseid); if ($courserecord->groupmode != NOGROUPS || !$courserecord->groupmodeforce) { $groupids[] = $courseid; -- 2.39.5