Skip to content

Commit

Permalink
MDL-81089 calendar: Return if module is branded
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Mar 7, 2024
1 parent 1e87c99 commit d271925
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions calendar/classes/external/event_exporter_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ protected static function define_other_properties() {
'purpose' => [
'type' => PARAM_TEXT
],
'branded' => [
'type' => PARAM_BOOL,
'optional' => true,
],
];
}

Expand Down Expand Up @@ -335,10 +339,13 @@ protected function get_other_values(renderer_base $output) {
$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);

Expand Down
35 changes: 35 additions & 0 deletions calendar/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3257,4 +3257,39 @@ public function test_get_timestamps_no_keys() {
$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']);
}
}
11 changes: 11 additions & 0 deletions calendar/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d271925

Please sign in to comment.