MDL-77444 communication: Initial mobile app support

This commit is contained in:
Juan Leyva
2023-11-27 10:59:23 +01:00
parent b58d1fd4e2
commit a8150ea45f
3 changed files with 55 additions and 0 deletions
+17
View File
@@ -2793,6 +2793,8 @@ class core_course_external extends external_api {
),
'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);
}
@@ -3273,6 +3275,8 @@ class core_course_external extends external_api {
}
}
$iscommapiavailable = \core_communication\api::is_available();
$coursesdata = array();
foreach ($courses as $course) {
$context = context_course::instance($course->id);
@@ -3334,6 +3338,19 @@ class core_course_external extends external_api {
'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(
+35
View File
@@ -3029,6 +3029,41 @@ class externallib_test extends externallib_advanced_testcase {
], 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');
+3
View File
@@ -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