From a1b38e4f8c2335d6a70dc7effe49db2c4d359015 Mon Sep 17 00:00:00 2001 From: Odei Alba Date: Thu, 19 Aug 2021 17:24:14 +0200 Subject: [PATCH] MDL-68325 completion: Add validation to course completion form --- course/completion_form.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/course/completion_form.php b/course/completion_form.php index 937a0eee150..def50c66aa6 100644 --- a/course/completion_form.php +++ b/course/completion_form.php @@ -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; + } }