MDL-60587 calendar: Switch to new helper in main view
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 27 Oct 2017 02:27:03 +0000 (10:27 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Thu, 2 Nov 2017 13:49:28 +0000 (21:49 +0800)
calendar/view.php

index 52a713b..f6b0e6f 100644 (file)
@@ -77,34 +77,20 @@ $url->param('time', $time);
 
 $PAGE->set_url($url);
 
+$course = get_course($courseid);
+
 if ($courseid != SITEID && !empty($courseid)) {
-    // Course ID must be valid and existing.
-    $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
-    $courses = array($course->id => $course);
     navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
+} else if (!empty($categoryid)) {
+    $PAGE->set_category_by_id($categoryid);
+    navigation_node::override_active_url(new moodle_url('/course/index.php', array('categoryid' => $categoryid)));
 } else {
-    $course = get_site();
-    $courses = calendar_get_default_courses();
-    if ($categoryid) {
-        $PAGE->set_category_by_id($categoryid);
-    } else {
-        $PAGE->set_context(context_system::instance());
-    }
-    if ($PAGE->context->contextlevel === CONTEXT_COURSECAT) {
-        // Restrict to categories, and their parents, and the courses that the user is enrolled in within those
-        // categories.
-        $categories = array_keys($PAGE->categories);
-        $courses = array_filter($courses, function($course) use ($categories) {
-            return array_search($course->category, $categories) !== false;
-        });
-        navigation_node::override_active_url(new moodle_url('/course/index.php', array('categoryid' => $categoryid)));
-    }
+    $PAGE->set_context(context_system::instance());
 }
 
 require_login($course, false);
 
-$calendar = new calendar_information(0, 0, 0, $time);
-$calendar->set_sources($course, $courses, $PAGE->category);
+$calendar = calendar_information::create($time, $courseid, $categoryid);
 
 $pagetitle = '';