mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
Merge branch 'MDL-81365-main' of https://github.com/ilyatregubov/moodle
This commit is contained in:
commit
61c8cdaf11
@ -620,19 +620,15 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||
* @return lang_string|null Error
|
||||
*/
|
||||
public function validate_plugin_data_context(array $enrolmentdata, ?int $courseid = null): ?lang_string {
|
||||
$error = null;
|
||||
if (isset($enrolmentdata['customint1'])) {
|
||||
$cohortid = $enrolmentdata['customint1'];
|
||||
$coursecontext = \context_course::instance($courseid);
|
||||
if (!cohort_get_cohort($cohortid, $coursecontext)) {
|
||||
return new lang_string('contextcohortnotallowed', 'cohort', $enrolmentdata['cohortidnumber']);
|
||||
$error = new lang_string('contextcohortnotallowed', 'cohort', $enrolmentdata['cohortidnumber']);
|
||||
}
|
||||
}
|
||||
$enrolmentdata += [
|
||||
'customint1' => null,
|
||||
'customint2' => null,
|
||||
'roleid' => 0,
|
||||
];
|
||||
return parent::validate_plugin_data_context($enrolmentdata, $courseid);
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3548,33 +3548,13 @@ abstract class enrol_plugin {
|
||||
* This is called from the tool_uploadcourse if the plugin supports instance creation in
|
||||
* upload course ({@see self::is_csv_upload_supported()})
|
||||
*
|
||||
* The fallback is to call the edit_instance_validation() but it will be better if the plugins
|
||||
* implement this method to return better error messages.
|
||||
* Override it if plugin can validate provided data in relevant context.
|
||||
*
|
||||
* @param array $enrolmentdata enrolment data to validate.
|
||||
* @param int|null $courseid Course ID.
|
||||
* @return lang_string|null Error
|
||||
*/
|
||||
public function validate_plugin_data_context(array $enrolmentdata, ?int $courseid = null): ?lang_string {
|
||||
global $DB;
|
||||
|
||||
if ($courseid) {
|
||||
$enrolmentdata += ['courseid' => $courseid, 'id' => 0, 'status' => ENROL_INSTANCE_ENABLED];
|
||||
$instance = (object)[
|
||||
'id' => null,
|
||||
'courseid' => $courseid,
|
||||
'status' => $enrolmentdata['status'],
|
||||
'type' => $this->get_name(),
|
||||
];
|
||||
if (array_key_exists('role', $enrolmentdata)) {
|
||||
$instance->roleid = $DB->get_field('role', 'id', ['shortname' => $enrolmentdata['role']]);
|
||||
}
|
||||
$formerrors = $this->edit_instance_validation($enrolmentdata, [], $instance, context_course::instance($courseid));
|
||||
if (!empty($formerrors)) {
|
||||
$errors = array_map(fn($key) => "{$key}: {$formerrors[$key]}", array_keys($formerrors));
|
||||
return new lang_string('errorcannotcreateorupdateenrolment', 'tool_uploadcourse', $errors);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user