MDL-59699 core_calendar: add course link to course events
authorSimey Lameze <simey@moodle.com>
Tue, 8 Aug 2017 07:07:06 +0000 (15:07 +0800)
committerSimey Lameze <simey@moodle.com>
Mon, 21 Aug 2017 05:33:51 +0000 (13:33 +0800)
calendar/classes/external/event_exporter.php
calendar/templates/event_summary_body.mustache

index 7e4bb7c..5fda78a 100644 (file)
@@ -60,6 +60,7 @@ class event_exporter extends event_exporter_base {
             'null' => NULL_ALLOWED
         ];
         $values['isactionevent'] = ['type' => PARAM_BOOL];
+        $values['iscourseevent'] = ['type' => PARAM_BOOL];
         $values['candelete'] = ['type' => PARAM_BOOL];
         $values['url'] = ['type' => PARAM_URL];
         $values['action'] = [
@@ -79,12 +80,15 @@ class event_exporter extends event_exporter_base {
     protected function get_other_values(renderer_base $output) {
         $values = parent::get_other_values($output);
 
+        global $CFG;
+        require_once($CFG->dirroot.'/course/lib.php');
+
         $event = $this->event;
         $legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event);
 
         $context = $this->related['context'];
         $values['isactionevent'] = false;
-
+        $values['iscourseevent'] = false;
         if ($moduleproxy = $event->get_course_module()) {
             $modulename = $moduleproxy->get('modname');
             $moduleid = $moduleproxy->get('id');
@@ -96,13 +100,13 @@ class event_exporter extends event_exporter_base {
             $params = array('update' => $moduleid, 'return' => true, 'sesskey' => sesskey());
             $editurl = new \moodle_url('/course/mod.php', $params);
             $values['editurl'] = $editurl->out(false);
+        } else if ($event->get_type() == 'course') {
+            $values['iscourseevent'] = true;
+            $url = \course_get_url($this->related['course'] ?: SITEID);
         } else {
             // TODO MDL-58866 We do not have any way to find urls for events outside of course modules.
-            global $CFG;
-            require_once($CFG->dirroot.'/course/lib.php');
             $url = \course_get_url($this->related['course'] ?: SITEID);
         }
-
         $values['url'] = $url->out(false);
 
         if ($event instanceof action_event_interface) {
index e5301bd..76dc1f1 100644 (file)
@@ -37,6 +37,9 @@
     {{/description}}
     <h4>{{#str}} eventtype, core_calendar {{/str}}</h4>
     {{eventtype}}
+    {{#iscourseevent}}
+        <a href="{{url}}">{{course.shortname}}</a>
+    {{/iscourseevent}}
     {{#source}}
         <div>{{{source}}}</div>
     {{/source}}