Skip to content

Commit

Permalink
MDL-54910 mod_data: Open dates should be before close dates
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourget committed Jun 23, 2016
1 parent eb36cfc commit 2d0bbd3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mod/data/lang/en/data.php
Expand Up @@ -50,6 +50,7 @@
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}';
Expand Down Expand Up @@ -368,4 +369,5 @@
$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';
23 changes: 23 additions & 0 deletions mod/data/mod_form.php
Expand Up @@ -81,6 +81,29 @@ function definition() {
$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);
}
Expand Down

0 comments on commit 2d0bbd3

Please sign in to comment.