From dd171628ea30b181fe3400a65039422e84d46dc2 Mon Sep 17 00:00:00 2001 From: Stephen Bourget Date: Thu, 23 Jun 2016 17:22:02 -0400 Subject: [PATCH] MDL-32135 mod_choice: Open time should be before close time --- mod/choice/lang/en/choice.php | 1 + mod/choice/mod_form.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/mod/choice/lang/en/choice.php b/mod/choice/lang/en/choice.php index e977d97e1d1..d7d4df09a59 100644 --- a/mod/choice/lang/en/choice.php +++ b/mod/choice/lang/en/choice.php @@ -28,6 +28,7 @@ $string['allowupdate'] = 'Allow choice to be updated'; $string['allowmultiple'] = 'Allow more than one choice to be selected'; $string['answered'] = 'Answered'; $string['cannotsubmit'] = 'Sorry, there was a problem submitting your choice. Please try again.'; +$string['closebeforeopen'] = 'You have specified a close date before the open date.'; $string['completionsubmit'] = 'Show as complete when user makes a choice'; $string['displayhorizontal'] = 'Display horizontally'; $string['displaymode'] = 'Display mode for the options'; diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index 756a79b1123..e15ad2df714 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -139,6 +139,25 @@ class mod_choice_mod_form extends moodleform_mod { return $data; } + /** + * Enforce validation rules here + * + * @param array $data array of ("fieldname"=>value) of submitted data + * @param array $files array of uploaded files "element_name"=>tmp_file_path + * @return array + **/ + public function validation($data, $files) { + $errors = parent::validation($data, $files); + + // Check open and close times are consistent. + if ($data['timeopen'] && $data['timeclose'] && + $data['timeclose'] < $data['timeopen']) { + $errors['timeclose'] = get_string('closebeforeopen', 'choice'); + } + + return $errors; + } + function add_completion_rules() { $mform =& $this->_form;