Skip to content

Commit

Permalink
MDL-77444 communication: Initial mobile app support
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Nov 27, 2023
1 parent b58d1fd commit a8150ea
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
17 changes: 17 additions & 0 deletions course/externallib.php
Expand Up @@ -2793,6 +2793,8 @@ protected static function get_course_structure($onlypublicdata = true) {
),
'Additional options for particular course format.', VALUE_OPTIONAL
),
'communicationroomname' => new external_value(PARAM_TEXT, 'Communication tool room name.', VALUE_OPTIONAL),
'communicationroomurl' => new external_value(PARAM_RAW, 'Communication tool room URL.', VALUE_OPTIONAL),
);
$coursestructure = array_merge($coursestructure, $extra);
}
Expand Down Expand Up @@ -3273,6 +3275,8 @@ public static function get_courses_by_field($field = '', $value = '') {
}
}

$iscommapiavailable = \core_communication\api::is_available();

$coursesdata = array();
foreach ($courses as $course) {
$context = context_course::instance($course->id);
Expand Down Expand Up @@ -3334,6 +3338,19 @@ public static function get_courses_by_field($field = '', $value = '') {
'value' => $value
);
}

// Communication tools for the course.
if ($iscommapiavailable) {
$communication = \core_communication\api::load_by_instance(
context: $context,
component: 'core_course',
instancetype: 'coursecommunication',
instanceid: $course->id
);
$coursesdata[$course->id]['communicationroomname'] = \core_external\util::format_string($communication->get_room_name(), $context);
// This will be usually an URL, however, it is better to consider that can be anything a plugin might return, this is why we will use PARAM_RAW.
$coursesdata[$course->id]['communicationroomurl'] = $communication->get_communication_room_url();
}
}

return array(
Expand Down
35 changes: 35 additions & 0 deletions course/tests/externallib_test.php
Expand Up @@ -3029,6 +3029,41 @@ public function test_get_courses_by_field_customfields(): void {
], reset($course['customfields']));
}

/**
* Test retrieving courses by field returning communication tools.
*/
public function test_get_courses_by_field_communication(): void {
$this->resetAfterTest();
$this->setAdminUser();

// Create communication tool in course.
set_config('enablecommunicationsubsystem', 1);

$roomname = 'Course chat';
$telegramlink = 'https://my.telegram.chat/120';
$record = [
'selectedcommunication' => 'communication_customlink',
'communicationroomname' => $roomname,
'customlinkurl' => $telegramlink,
];
$course = $this->getDataGenerator()->create_course($record);
$communication = \core_communication\api::load_by_instance(
context: \core\context\course::instance($course->id),
component: 'core_course',
instancetype: 'coursecommunication',
instanceid: $course->id,
);

$result = external_api::clean_returnvalue(
core_course_external::get_courses_by_field_returns(),
core_course_external::get_courses_by_field('id', $course->id)
);

$course = reset($result['courses']);
$this->assertEquals($roomname, $course['communicationroomname']);
$this->assertEquals($telegramlink, $course['communicationroomurl']);
}

public function test_get_courses_by_field_invalid_field() {
$this->expectException('invalid_parameter_exception');
$result = core_course_external::get_courses_by_field('zyx', 'x');
Expand Down
3 changes: 3 additions & 0 deletions course/upgrade.txt
Expand Up @@ -5,6 +5,9 @@ information provided here is intended especially for developers.
* set_coursemodule_visible() has a new $rebuildcache parameter. If this is being called multiple times in the same request,
consider passing `false` for this parameter and rebuilding the cache once after all the course modules have been updated.
See course_update_section() for an example.
* The external function core_course::get_courses_by_field now returns the communication tool configuration for the course.
- communicationroomname: the room name
- communicationroomurl: the tool url

=== 4.3 ===
* The `core_course_renderer::course_section_cm_completion` method has been removed, and can no longer be used
Expand Down

0 comments on commit a8150ea

Please sign in to comment.