MDL-41639 tool_uploaduser: Automatically create cohorts if not found

This commit is contained in:
Marina Glancy
2014-07-23 14:56:52 +08:00
parent ec36fafc0f
commit e7bc91579b
+9
View File
@@ -850,6 +850,15 @@ if ($formdata = $mform2->is_cancelled()) {
$cohort = $DB->get_record('cohort', array('id'=>$addcohort));
} else {
$cohort = $DB->get_record('cohort', array('idnumber'=>$addcohort));
if (empty($cohort) && has_capability('moodle/cohort:manage', context_system::instance())) {
// Cohort was not found. Create a new one.
$cohortid = cohort_add_cohort((object)array(
'idnumber' => $addcohort,
'name' => $addcohort,
'contextid' => context_system::instance()->id
));
$cohort = $DB->get_record('cohort', array('id'=>$cohortid));
}
}
if (empty($cohort)) {