MDL-54910 mod_data: Open dates should be before close dates

This commit is contained in:
Stephen Bourget 2016-06-23 17:32:19 -04:00
parent b8474fe0c7
commit 316f20a0b6
2 changed files with 25 additions and 0 deletions

View File

@ -50,6 +50,7 @@ Fields have the format [[fieldname]]. All other tags have the format ##sometag##
Only the tags that are in the "Available tags" list may be used for the current template.';
$string['availabletodate'] = 'Available to';
$string['availabletodatevalidation'] = 'The available to date cannot be before the available from date.';
$string['blank'] = 'Blank';
$string['buttons'] = 'Actions';
$string['bynameondate'] = 'by {$a->name} - {$a->date}';
@ -368,4 +369,5 @@ $string['usestandard'] = 'Use a preset';
$string['usestandard_help'] = 'To use a preset available to the whole site, select it from the list. (If you have added a preset to the list using the save as preset feature then you have the option of deleting it.)';
$string['viewfromdate'] = 'Read only from';
$string['viewtodate'] = 'Read only to';
$string['viewtodatevalidation'] = 'The read only to date cannot be before the read only from date.';
$string['wrongdataid'] = 'Wrong data id provided';

View File

@ -81,6 +81,29 @@ class mod_data_mod_form extends moodleform_mod {
$this->add_action_buttons();
}
/**
* 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['timeavailablefrom'] && $data['timeavailableto'] &&
$data['timeavailableto'] < $data['timeavailablefrom']) {
$errors['timeavailableto'] = get_string('availabletodatevalidation', 'data');
}
if ($data['timeviewfrom'] && $data['timeviewto'] &&
$data['timeviewto'] < $data['timeviewfrom']) {
$errors['timeviewto'] = get_string('viewtodatevalidation', 'data');
}
return $errors;
}
function data_preprocessing(&$default_values){
parent::data_preprocessing($default_values);
}