(C) Moorfields Eye Hospital NHS Foundation Trust, 2008-2011
(C) OpenEyes Foundation, 2011-2013
This file is part of OpenEyes.
OpenEyes is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
OpenEyes is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with OpenEyes in a file titled COPYING. If not, see .
/** * Perform form data validation. * * @param $form_data * * @return array */ public function validate($form_data) { $errs = array(); if (!@$form_data['appointment_date']) { $errs['appointment_date'] = 'Please enter an appointment date'; } $appointment_date = \Helper::convertNHS2MySQL($form_data['appointment_date']); $date_validator = new \OEDateValidator(); if (!$date_validator->validateValue($appointment_date)) { if (strtotime($appointment_date) != false) { $errs['appointment_date'] = 'Appointment date is not in valid format'; } else { $errs['appointment_date'] = 'Appointment date is not a valid date'; } } else { $not_historical_validator = new \OEDateValidatorNotHistorical(); if ($not_historical_validator->validateValue($appointment_date) == false) { $errs['appointment_date'] = 'Appointment date cannot be in the past'; } } if ($appointment_time = @$form_data['appointment_time']) { $time_validator = new \OETimeValidator(); if (!$time_validator->validateValue($appointment_time)) { $errs['appointment_time'] = 'Appointment time is not valid'; } } return $errs; }
public function validateAttribute($object, $attribute) { if (parent::validateAttribute($object, $attribute)) { if ($this->validateValue($object->{$attribute})) { $this->addError($object, $attribute, $object->getAttributeLabel($attribute) . ' cannot be in the past.'); } } }
public function validateAttribute($object, $attribute) { if (parent::validateAttribute($object, $attribute)) { if (strtotime($object->{$attribute}) > strtotime(date('Y-m-d H:i:s'))) { $this->addError($object, $attribute, $object->getAttributeLabel($attribute) . ' cannot be in the future.'); } } }
/** * checks if the given attribute on the element is today or in the future. * * @param string $attribute * @param array $params */ public function todayOrFutureValidation($attribute, $params) { $min_date = $this->id ? date('Y-m-d', strtotime($this->created_date)) : date('Y-m-d'); if (!@$params['message']) { $params['message'] = '{attribute} cannot be in the past'; } $params['{attribute}'] = $this->getAttributeLabel($attribute); $date_validator = new OEDateValidator(); if ($date_validator->validateAttribute($this, $attribute)) { if ($this->{$attribute} < $min_date) { $this->addError($attribute, strtr($params['message'], $params)); } } }