);
return new external_single_structure($userfields);
}
+
+ /**
+ * Returns description of method result value
+ *
+ * @return external_description
+ */
+ public static function fetch_modules_activity_chooser_returns() {
+ return new external_single_structure([
+ 'allmodules' => new external_multiple_structure(
+ new external_single_structure([
+ 'label' => new external_value(PARAM_TEXT, 'Human readable module name', VALUE_OPTIONAL),
+ 'modulename' => new external_value(PARAM_TEXT, 'Module name', VALUE_OPTIONAL),
+ 'description' => new external_value(PARAM_RAW, 'Help panel information', VALUE_OPTIONAL),
+ 'urls' => new external_single_structure([
+ 'addoption' => new external_value(PARAM_URL, 'The edit link for the module', VALUE_OPTIONAL),
+ ]),
+ 'icon' => new external_single_structure([
+ 'attributes' => new external_multiple_structure(
+ new external_single_structure([
+ 'name' => new external_value(PARAM_RAW, 'HTML attr', VALUE_OPTIONAL),
+ 'value' => new external_value(PARAM_RAW, 'Value of the HTML attr', VALUE_OPTIONAL),
+ ])
+ ),
+ 'extraclasses' => new external_value(PARAM_RAW, 'Anything extra the module defines', VALUE_OPTIONAL),
+ ]),
+ ])
+ ),
+ 'warnings' => new external_warnings()
+ ]);
+ }
+
+ /**
+ * Returns description of method parameters
+ *
+ * @return external_function_parameters
+ */
+ public static function fetch_modules_activity_chooser_parameters() {
+ return new external_function_parameters([
+ 'courseid' => new external_value(PARAM_INT, 'ID of the course', VALUE_REQUIRED),
+ ]);
+ }
+
+ /**
+ * Given a course ID fetch all accessible modules for that course
+ *
+ * @param int $courseid The course we want to fetch the modules for
+ * @return array Contains array of modules and their metadata
+ * @throws moodle_exception
+ */
+ public static function fetch_modules_activity_chooser(int $courseid) {
+ global $DB, $OUTPUT;
+ [
+ 'courseid' => $courseid,
+ ] = self::validate_parameters(self::fetch_modules_activity_chooser_parameters(), [
+ 'courseid' => $courseid,
+ ]);
+ $warnings = array();
+
+ // Validate the course context.
+ $coursecontext = context_course::instance($courseid);
+ self::validate_context($coursecontext);
+ // Check to see if user can add menus and there are modules to add.
+ if (!has_capability('moodle/course:manageactivities', $coursecontext)
+ || !($modnames = get_module_types_names()) || empty($modnames)) {
+ return '';
+ }
+
+ $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+ // Retrieve all modules with associated metadata.
+ $modules = get_module_metadata($course, $modnames, null);
+ $related = [
+ 'context' => $coursecontext
+ ];
+ // Export the module chooser data.
+ $modchooserdata = new \core_course\external\course_module_chooser_exporter($modules, $related);
+
+ $result = [];
+ $result['allmodules'] = $modchooserdata->export($OUTPUT)->options;
+ $result['warnings'] = $warnings;
+ return $result;
+ }
+
}