Merge branch 'wip-MDL-58867-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Dan Poltawski 2017-05-10 11:16:19 +01:00
commit ef1a227e38
4 changed files with 40 additions and 20 deletions

View File

@ -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';

View File

@ -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);

View File

@ -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));

View File

@ -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) {