mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-55415 course: New WS core_course_get_user_administration_options
This commit is contained in:
parent
b2392037e7
commit
b9050b106e
3 changed files with 134 additions and 0 deletions
|
@ -2701,4 +2701,70 @@ class core_course_external extends external_api {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 3.2
|
||||
*/
|
||||
public static function get_user_administration_options_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'courseids' => new external_multiple_structure(new external_value(PARAM_INT, 'Course id.')),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of administration options in a set of courses that are available or not for the current user.
|
||||
*
|
||||
* @param array $courseids a list of course ids
|
||||
* @return array of warnings and the options availability
|
||||
* @since Moodle 3.2
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function get_user_administration_options($courseids) {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/course/lib.php');
|
||||
|
||||
// Parameter validation.
|
||||
$params = self::validate_parameters(self::get_user_administration_options_parameters(), array('courseids' => $courseids));
|
||||
$courseoptions = array();
|
||||
|
||||
list($courses, $warnings) = external_util::validate_courses($params['courseids'], array(), true);
|
||||
|
||||
if (!empty($courses)) {
|
||||
foreach ($courses as $course) {
|
||||
$adminoptions = course_get_user_administration_options($course, $course->context);
|
||||
$options = array();
|
||||
foreach ($adminoptions as $name => $available) {
|
||||
$options[] = array(
|
||||
'name' => $name,
|
||||
'available' => $available,
|
||||
);
|
||||
}
|
||||
|
||||
$courseoptions[] = array(
|
||||
'id' => $course->id,
|
||||
'options' => $options
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'courses' => $courseoptions,
|
||||
'warnings' => $warnings
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
*
|
||||
* @return external_description
|
||||
* @since Moodle 3.2
|
||||
*/
|
||||
public static function get_user_administration_options_returns() {
|
||||
return self::get_user_navigation_options_returns();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue