diff --git a/calendar/classes/external/event_action_exporter.php b/calendar/classes/external/event_action_exporter.php index 2002cc3a817..097adbcc825 100644 --- a/calendar/classes/external/event_action_exporter.php +++ b/calendar/classes/external/event_action_exporter.php @@ -90,6 +90,10 @@ class event_action_exporter extends exporter { protected function get_other_values(renderer_base $output) { $event = $this->related['event']; + if (!$event->get_course_module()) { + // TODO MDL-58866 Only activity modules currently support this callback. + return ['showitemcount' => false]; + } $modulename = $event->get_course_module()->get('modname'); $component = 'mod_' . $modulename; $showitemcountcallback = 'core_calendar_event_action_shows_item_count'; diff --git a/calendar/classes/external/event_exporter.php b/calendar/classes/external/event_exporter.php index ade78fa0423..baa73f6a62f 100644 --- a/calendar/classes/external/event_exporter.php +++ b/calendar/classes/external/event_exporter.php @@ -178,10 +178,17 @@ class event_exporter extends exporter { $values = []; $event = $this->event; $context = $this->related['context']; - $modulename = $event->get_course_module()->get('modname'); - $moduleid = $event->get_course_module()->get('id'); + if ($moduleproxy = $event->get_course_module()) { + $modulename = $moduleproxy->get('modname'); + $moduleid = $moduleproxy->get('id'); + $url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]); + } 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); + } $timesort = $event->get_times()->get_sort_time()->getTimestamp(); - $url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]); $iconexporter = new event_icon_exporter($event, ['context' => $context]); $values['url'] = $url->out(false); diff --git a/calendar/classes/external/event_icon_exporter.php b/calendar/classes/external/event_icon_exporter.php index 2895a409b85..5f4bd4dc29e 100644 --- a/calendar/classes/external/event_icon_exporter.php +++ b/calendar/classes/external/event_icon_exporter.php @@ -54,7 +54,7 @@ class event_icon_exporter extends exporter { $userid = $user ? $user->get('id') : null; $isactivityevent = !empty($coursemodule); $isglobalevent = ($course && $courseid == SITEID); - $iscourseevent = ($course && !empty($courseid) && $courseid != SITEID && $group && empty($groupid)); + $iscourseevent = ($course && !empty($courseid) && $courseid != SITEID && empty($groupid)); $isgroupevent = ($group && !empty($groupid)); $isuserevent = ($user && !empty($userid)); diff --git a/calendar/classes/local/event/container.php b/calendar/classes/local/event/container.php index 083b19c5ed5..20b39ec5728 100644 --- a/calendar/classes/local/event/container.php +++ b/calendar/classes/local/event/container.php @@ -132,7 +132,7 @@ class container { $getcallback('action'), $getcallback('visibility'), function ($dbrow) { - // At present we only handle callbacks in course modules. + // At present we only have a bail-out check for events in course modules. if (empty($dbrow->modulename)) { return false; } @@ -246,14 +246,19 @@ class container { // Callbacks will get supplied a "legacy" version // of the event class. $mapper = self::$eventmapper; - $action = component_callback( - 'mod_' . $event->get_course_module()->get('modname'), - 'core_calendar_provide_event_action', - [ - $mapper->from_event_to_legacy_event($event), - self::$actionfactory - ] - ); + $action = null; + if ($event->get_course_module()) { + // TODO MDL-58866 Only activity modules currently support this callback. + // Any other event will not be displayed on the dashboard. + $action = component_callback( + 'mod_' . $event->get_course_module()->get('modname'), + 'core_calendar_provide_event_action', + [ + $mapper->from_event_to_legacy_event($event), + self::$actionfactory + ] + ); + } // If we get an action back, return an action event, otherwise // continue piping through the original event. @@ -266,13 +271,17 @@ class container { // This is enforced by the event_factory. 'visibility' => function (event_interface $event) { $mapper = self::$eventmapper; - $eventvisible = component_callback( - 'mod_' . $event->get_course_module()->get('modname'), - 'core_calendar_is_event_visible', - [ - $mapper->from_event_to_legacy_event($event) - ] - ); + $eventvisible = null; + if ($event->get_course_module()) { + // TODO MDL-58866 Only activity modules currently support this callback. + $eventvisible = component_callback( + 'mod_' . $event->get_course_module()->get('modname'), + 'core_calendar_is_event_visible', + [ + $mapper->from_event_to_legacy_event($event) + ] + ); + } // Do not display the event if there is nothing to action. if ($event instanceof action_event_interface && $event->get_action()->get_item_count() === 0) {