MDL-74760 activity web services: refactor duplicate code

This commit is contained in:
Tim Hunt
2022-06-07 12:53:34 +01:00
parent 5500d143f4
commit 6c161f3b99
19 changed files with 290 additions and 452 deletions
+8 -24
View File
@@ -24,6 +24,8 @@
* @since Moodle 3.0
*/
use core_course\external\helper_for_get_mods_by_courses;
defined('MOODLE_INTERNAL') || die;
require_once("$CFG->libdir/externallib.php");
@@ -153,15 +155,7 @@ class mod_folder_external extends external_api {
// We can avoid then additional validate_context calls.
$folders = get_all_instances_in_courses("folder", $courses);
foreach ($folders as $folder) {
$context = context_module::instance($folder->coursemodule);
// Entry to return.
$folder->name = external_format_string($folder->name, $context->id);
$options = array('noclean' => true);
list($folder->intro, $folder->introformat) =
external_format_text($folder->intro, $folder->introformat, $context->id, 'mod_folder', 'intro', null, $options);
$folder->introfiles = external_util::get_area_files($context->id, 'mod_folder', 'intro', false, false);
helper_for_get_mods_by_courses::format_name_and_intro($folder, 'mod_folder');
$returnedfolders[] = $folder;
}
}
@@ -183,27 +177,17 @@ class mod_folder_external extends external_api {
return new external_single_structure(
array(
'folders' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'Module id'),
'coursemodule' => new external_value(PARAM_INT, 'Course module id'),
'course' => new external_value(PARAM_INT, 'Course id'),
'name' => new external_value(PARAM_RAW, 'Page name'),
'intro' => new external_value(PARAM_RAW, 'Summary'),
'introformat' => new external_format_value('intro', 'Summary format'),
'introfiles' => new external_files('Files in the introduction text'),
new external_single_structure(array_merge(
helper_for_get_mods_by_courses::standard_coursemodule_elements_returns(),
[
'revision' => new external_value(PARAM_INT, 'Incremented when after each file changes, to avoid cache'),
'timemodified' => new external_value(PARAM_INT, 'Last time the folder was modified'),
'display' => new external_value(PARAM_INT, 'Display type of folder contents on a separate page or inline'),
'showexpanded' => new external_value(PARAM_INT, '1 = expanded, 0 = collapsed for sub-folders'),
'showdownloadfolder' => new external_value(PARAM_INT, 'Whether to show the download folder button'),
'forcedownload' => new external_value(PARAM_INT, 'Whether file download is forced'),
'section' => new external_value(PARAM_INT, 'Course section id'),
'visible' => new external_value(PARAM_INT, 'Module visibility'),
'groupmode' => new external_value(PARAM_INT, 'Group mode'),
'groupingid' => new external_value(PARAM_INT, 'Grouping id'),
)
)
]
))
),
'warnings' => new external_warnings(),
)