MDL-52568 core_cohort: added ability to return all cohorts in WS

This commit is contained in:
Kevin Bruton 2016-01-10 00:12:58 +01:00
parent e8d5100212
commit cfd8c0fe09
2 changed files with 16 additions and 9 deletions

View File

@ -208,7 +208,7 @@ class core_cohort_external extends external_api {
return new external_function_parameters(
array(
'cohortids' => new external_multiple_structure(new external_value(PARAM_INT, 'Cohort ID')
, 'List of cohort id. A cohort id is an integer.'),
, 'List of cohort id. A cohort id is an integer.', VALUE_DEFAULT, array()),
)
);
}
@ -220,16 +220,19 @@ class core_cohort_external extends external_api {
* @return array of cohort objects (id, courseid, name)
* @since Moodle 2.5
*/
public static function get_cohorts($cohortids) {
public static function get_cohorts($cohortids = array()) {
global $DB;
$params = self::validate_parameters(self::get_cohorts_parameters(), array('cohortids' => $cohortids));
$cohorts = array();
foreach ($params['cohortids'] as $cohortid) {
// Validate params.
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
if (empty($cohortids)) {
$cohorts = $DB->get_records('cohort');
} else {
$cohorts = $DB->get_records_list('cohort', 'id', $params['cohortids']);
}
$cohortsinfo = array();
foreach ($cohorts as $cohort) {
// Now security checks.
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
@ -244,12 +247,12 @@ class core_cohort_external extends external_api {
external_format_text($cohort->description, $cohort->descriptionformat,
$context->id, 'cohort', 'description', $cohort->id);
$cohorts[] = (array) $cohort;
$cohortsinfo[] = (array) $cohort;
}
return $cohorts;
return $cohortsinfo;
}
/**
* Returns description of method result value
*

View File

@ -1,6 +1,10 @@
This files describes API changes in /cohort/ information provided here is intended
especially for developers.
=== 3.1 ===
* The Webservice core_cohort_get_cohorts now has the added functionality of getting all cohorts
by not passing any parameters
=== 2.6 ===
* Webservice core_cohort_update_cohorts was incorrectly specifiying float as the parameter type
for cohort id. This field is actually int and input is now reported and processed as such.