mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-68325 completion: Add validation to course completion form
This commit is contained in:
parent
1d700796ca
commit
a1b38e4f8c
@ -266,4 +266,31 @@ class course_completion_form extends moodleform {
|
||||
$mform->addElement('cancel');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form validation
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return array
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = [];
|
||||
|
||||
if (!isset($data['criteria_course']) || $data['criteria_course'] === 0) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
foreach ($data['criteria_course'] as $courseid) {
|
||||
$course = get_course($courseid);
|
||||
$completioninfo = new completion_info($course);
|
||||
|
||||
if (! $completioninfo->is_enabled()) {
|
||||
$errors[] = get_string('completionnotenabledforcourse', 'completion');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user