mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-32662 Added get_course_groupings method
This commit is contained in:
parent
ed849fbace
commit
85e42d2218
1 changed files with 70 additions and 0 deletions
|
@ -797,6 +797,76 @@ class core_group_external extends external_api {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters
|
||||||
|
* @return external_function_parameters
|
||||||
|
*/
|
||||||
|
public static function get_course_groupings_parameters() {
|
||||||
|
return new external_function_parameters(
|
||||||
|
array(
|
||||||
|
'courseid' => new external_value(PARAM_INT, 'id of course'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all groupings in the specified course
|
||||||
|
* @param int $courseid id of course
|
||||||
|
* @return array of grouping objects (id, courseid, name, enrolmentkey)
|
||||||
|
*/
|
||||||
|
public static function get_course_groupings($courseid) {
|
||||||
|
global $CFG;
|
||||||
|
require_once("$CFG->dirroot/group/lib.php");
|
||||||
|
|
||||||
|
$params = self::validate_parameters(self::get_course_groupings_parameters(), array('courseid'=>$courseid));
|
||||||
|
|
||||||
|
// Now security checks.
|
||||||
|
$context = context_course::instance($params['courseid']);
|
||||||
|
|
||||||
|
try {
|
||||||
|
self::validate_context($context);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$exceptionparam = new stdClass();
|
||||||
|
$exceptionparam->message = $e->getMessage();
|
||||||
|
$exceptionparam->courseid = $params['courseid'];
|
||||||
|
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
|
||||||
|
}
|
||||||
|
require_capability('moodle/course:managegroups', $context);
|
||||||
|
|
||||||
|
$gs = groups_get_all_groupings($params['courseid']);
|
||||||
|
|
||||||
|
$groupings = array();
|
||||||
|
foreach ($gs as $grouping) {
|
||||||
|
$grouping->description = file_rewrite_pluginfile_urls($grouping->description, 'webservice/pluginfile.php', $context->id, 'grouping', 'description', $grouping->id);
|
||||||
|
|
||||||
|
$options = new stdClass;
|
||||||
|
$options->noclean = true;
|
||||||
|
$options->para = false;
|
||||||
|
$grouping->description = format_text($grouping->description, FORMAT_HTML, $options);
|
||||||
|
|
||||||
|
$groupings[] = (array)$grouping;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $groupings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value
|
||||||
|
* @return external_description
|
||||||
|
*/
|
||||||
|
public static function get_course_groupings_returns() {
|
||||||
|
return new external_multiple_structure(
|
||||||
|
new external_single_structure(
|
||||||
|
array(
|
||||||
|
'id' => new external_value(PARAM_INT, 'grouping record id'),
|
||||||
|
'courseid' => new external_value(PARAM_INT, 'id of course'),
|
||||||
|
'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
|
||||||
|
'description' => new external_value(PARAM_CLEANHTML, 'grouping description text')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue