MDL-58048 calendar: Show itemcount conditionally

Part of MDL-55611 epic.
This commit is contained in:
Jun Pataleta 2017-03-07 16:50:52 +08:00 committed by Damyon Wiese
parent 1dd4375f2f
commit 6b7b39fe3a
2 changed files with 45 additions and 4 deletions

View File

@ -26,8 +26,10 @@ namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use \core\external\exporter;
use \core_calendar\local\interfaces\action_interface;
use core\external\exporter;
use core_calendar\local\event\core_container;
use core_calendar\local\interfaces\action_interface;
use renderer_base;
/**
* Class for displaying a calendar event's action.
@ -67,6 +69,41 @@ class event_action_exporter extends exporter {
];
}
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return [
'showitemcount' => ['type' => PARAM_BOOL, 'default' => false]
];
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
$event = $this->related['event'];
$modulename = $event->get_course_module()->get('modname');
$component = 'mod_' . $modulename;
$showitemcountcallback = 'core_calendar_event_action_shows_item_count';
$mapper = core_container::get_event_mapper();
$calevent = $mapper->from_event_to_legacy_event($event);
$params = [$calevent, $this->data->itemcount];
$showitemcount = component_callback($component, $showitemcountcallback, $params, false);
// Prepare other values data.
$data = [
'showitemcount' => $showitemcount
];
return $data;
}
/**
* Returns a list of objects that are related.
*
@ -75,6 +112,7 @@ class event_action_exporter extends exporter {
protected static function define_related() {
return [
'context' => 'context',
'event' => '\\core_calendar\\local\\interfaces\\event_interface'
];
}
}

View File

@ -189,8 +189,11 @@ class event_exporter extends exporter {
$values['icon'] = $iconexporter->export($output);
if ($event instanceof action_event_interface) {
$actionexporter = new event_action_exporter($event->get_action(),
['context' => $context]);
$actionrelated = [
'context' => $context,
'event' => $event
];
$actionexporter = new event_action_exporter($event->get_action(), $actionrelated);
$values['action'] = $actionexporter->export($output);
}