MDL-59750 calendar: organise exporters code

This commit is contained in:
Simey Lameze
2017-09-20 12:50:52 +08:00
parent 5a35675e53
commit 63b13467a9
4 changed files with 47 additions and 30 deletions
+18 -4
View File
@@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die();
use \core_course\external\course_summary_exporter;
use \renderer_base;
require_once($CFG->dirroot . '/course/lib.php');
/**
* Class for displaying a calendar event.
*
@@ -71,12 +71,26 @@ class calendar_event_exporter extends event_exporter_base {
global $CFG;
$values = parent::get_other_values($output);
$event = $this->event;
$eventid = $this->event->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]);
$url = new \moodle_url($this->related['daylink'], [], "event_{$eventid}");
// Build edit event url for action events.
$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') {
$url = course_get_url($event->get_course()->get('id') ?: SITEID);
} else {
// TODO MDL-58866 We do not have any way to find urls for events outside of course modules.
$course = $event->get_course()->get('id') ?: SITEID;
$url = course_get_url($course);
}
$values['url'] = $url->out(false);
$values['islastday'] = false;
$today = $this->related['type']->timestamp_to_date_array($this->related['today']);
-2
View File
@@ -202,8 +202,6 @@ class day_exporter extends exporter {
return $exporter->export($output);
}, $eventexporters);
$return['calendareventtypes'] = array_map(function($exporter) {
return $exporter->get_calendar_event_type();
}, $eventexporters);
-23
View File
@@ -50,10 +50,6 @@ class event_exporter extends event_exporter_base {
protected static function define_other_properties() {
$values = parent::define_other_properties();
$values['isactionevent'] = ['type' => PARAM_BOOL];
$values['iscourseevent'] = ['type' => PARAM_BOOL];
$values['candelete'] = ['type' => PARAM_BOOL];
$values['url'] = ['type' => PARAM_URL];
$values['action'] = [
'type' => event_action_exporter::read_properties_definition(),
@@ -63,12 +59,6 @@ class event_exporter extends event_exporter_base {
'type' => PARAM_URL,
'optional' => true,
];
$values['groupname'] = [
'type' => PARAM_RAW,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
];
return $values;
}
@@ -87,21 +77,16 @@ class event_exporter extends event_exporter_base {
$event = $this->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');
$url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]);
$values['isactionevent'] = true;
// Build edit event url for action events.
$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.
@@ -118,15 +103,7 @@ class event_exporter extends event_exporter_base {
$values['action'] = $actionexporter->export($output);
}
if ($course = $this->related['course']) {
$coursesummaryexporter = new course_summary_exporter($course, ['context' => $context]);
$values['course'] = $coursesummaryexporter->export($output);
}
if ($group = $event->get_group()) {
$values['groupname'] = format_string($group->get('name'), true,
['context' => \context_course::instance($event->get_course()->get('id'))]);
}
return $values;
}
+29 -1
View File
@@ -197,7 +197,19 @@ class event_exporter_base extends exporter {
],
'formattedtime' => [
'type' => PARAM_RAW,
]
],
'isactionevent' => [
'type' => PARAM_BOOL
],
'iscourseevent' => [
'type' => PARAM_BOOL
],
'groupname' => [
'type' => PARAM_RAW,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
];
}
@@ -212,6 +224,13 @@ class event_exporter_base extends exporter {
$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()) {
$values['isactionevent'] = true;
} else if ($event->get_type() == 'course') {
$values['iscourseevent'] = true;
}
$timesort = $event->get_times()->get_sort_time()->getTimestamp();
$iconexporter = new event_icon_exporter($event, ['context' => $context]);
@@ -238,6 +257,15 @@ class event_exporter_base extends exporter {
$values['formattedtime'] = calendar_format_event_time($legacyevent, time(), null, false,
$timesort);
if ($course = $this->related['course']) {
$coursesummaryexporter = new course_summary_exporter($course, ['context' => $context]);
$values['course'] = $coursesummaryexporter->export($output);
}
if ($group = $event->get_group()) {
$values['groupname'] = format_string($group->get('name'), true,
['context' => \context_course::instance($event->get_course()->get('id'))]);
}
return $values;
}