Skip to content

Commit

Permalink
Merge branch 'MDL-52568_master' of https://github.com/kevin-bruton/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jan 19, 2016
2 parents 31ed36f + cfd8c0f commit c8c9055
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cohort/externallib.php
Expand Up @@ -208,7 +208,7 @@ public static function get_cohorts_parameters() {
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()),
)
);
}
Expand All @@ -220,16 +220,19 @@ public static function get_cohorts_parameters() {
* @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) {
Expand All @@ -244,12 +247,12 @@ public static function get_cohorts($cohortids) {
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
*
Expand Down
4 changes: 4 additions & 0 deletions cohort/upgrade.txt
@@ -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.
Expand Down

0 comments on commit c8c9055

Please sign in to comment.