MDL-41639 tool_uploaduser: Automatically create cohorts if not found
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user