MDL-81089 calendar: Return if module is branded

This commit is contained in:
Juan Leyva 2024-02-29 15:36:39 +01:00
parent 1e87c997df
commit d271925d56
3 changed files with 53 additions and 0 deletions

View File

@ -293,6 +293,10 @@ class event_exporter_base extends exporter {
'purpose' => [
'type' => PARAM_TEXT
],
'branded' => [
'type' => PARAM_BOOL,
'optional' => true,
],
];
}
@ -335,10 +339,13 @@ class event_exporter_base extends exporter {
$values['normalisedeventtypetext'] = $stringexists ? get_string($identifier, 'calendar') : '';
$purpose = 'none';
$isbranded = false;
if ($moduleproxy) {
$purpose = plugin_supports('mod', $moduleproxy->get('modname'), FEATURE_MOD_PURPOSE, 'none');
$isbranded = component_callback('mod_' . $moduleproxy->get('modname'), 'is_branded') !== null ? : false;
}
$values['purpose'] = $purpose;
$values['branded'] = $isbranded;
$values['icon'] = $iconexporter->export($output);

View File

@ -3257,4 +3257,39 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertEquals($expectedtimestamps[$data['key']], $data['timestamp']);
}
}
/**
* Test for checking if we receive the correct icon branding.
*
* @covers \core_calendar_external::get_calendar_action_events_by_timesort
*/
public function test_get_calendar_event_branded(): void {
$this->resetAfterTest(true);
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$this->setUser($user);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$assign = $generator->create_instance(['course' => $course->id]);
$params = [
'type' => CALENDAR_EVENT_TYPE_ACTION,
'instance' => $assign->id,
'courseid' => $course->id,
'modulename' => 'assign',
'timesort' => 1,
];
$event1 = $this->create_calendar_event('Event 1', $user->id, 'user', 0, 1, $params);
$result = core_calendar_external::get_calendar_action_events_by_timesort(0);
$result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
$this->assertCount(1, $result['events']);
$this->assertFalse($result['events'][0]['branded']);
}
}

View File

@ -5,6 +5,17 @@ information provided here is intended especially for developers.
* The following previously deprecated methods have been removed and can no longer be used:
- `calendar_process_subscription_row`
- `calendar_import_icalendar_events`
* The event_exporter_base class now returns a field called "branded" indicating whether the module is branded or not.
All the external functions using the exporter will now return the new field:
- core_calendar_get_action_events_by_course
- core_calendar_get_action_events_by_courses
- core_calendar_get_action_events_by_timesort
- core_calendar_get_calendar_day_view
- core_calendar_get_calendar_event_by_id
- core_calendar_get_calendar_monthly_view
- core_calendar_get_calendar_upcoming_view
- core_calendar_submit_create_update_form
- core_calendar_update_event_start_day
=== 4.3 ===
* The `navigation` property has been removed from `\core_calendar\external\day_exporter` as it is not being used by any of the