]> git.mjollnir.org Git - moodle.git/commitdiff
calendar/lib: calendar_set_filters() use pre-fetched context and course recs
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:53:33 +0000 (07:53 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:53:33 +0000 (07:53 +0000)
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

index a2869dc8ce836035ad6529139eaa7f6bb6593763..1eac3efa43b107b7c2984a71f0e7d1c2570ae3d7 100644 (file)
@@ -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;