1. sfValidatorDateRange.class.php
  2. /** * sfValidatorDateRange validates a range of date. It also converts the input values to valid dates. * * @package symfony * @subpackage validator * @author Fabien Potencier * @version SVN: $Id: sfValidatorDateRange.class.php 15966 2009-03-03 17:29:06Z hartym $ */
  3. class sfValidatorDateRange extends sfValidatorBase
  4. {
  5. /**
  6. * Configures the current validator.
  7. *
  8. * Available options:
  9. *
  10. * * from_date: The from date validator (required)
  11. * * to_date: The to date validator (required)
  12. * * from_field: The name of the "from" date field (optional, default: from)
  13. * * to_field: The name of the "to" date field (optional, default: to)
  14. *
  15. * @param array $options An array of options
  16. * @param array $messages An array of error messages
  17. *
  18. * @see sfValidatorBase
  19. */
  20. protected function configure($options = array(), $messages = array())
  21. {
  22. $this->addMessage('invalid', 'The begin date must be before the end date.');
  23. $this->addRequiredOption('from_date');
  24. $this->addRequiredOption('to_date');
  25. $this->addOption('from_field', 'from');
  26. $this->addOption('to_field', 'to');
  27. }
  28. /**
  29. * @see sfValidatorBase
  30. */
  31. protected function doClean($value)
  32. {
  33. $fromField = $this->getOption('from_field');
  34. $toField = $this->getOption('to_field');
  35. $value[$fromField] = $this->getOption('from_date')->clean(isset($value[$fromField]) ? $value[$fromField] : null);
  36. $value[$toField] = $this->getOption('to_date')->clean(isset($value[$toField]) ? $value[$toField] : null);
  37. if ($value[$fromField] && $value[$toField])
  38. {
  39. $v = new sfValidatorSchemaCompare($fromField, sfValidatorSchemaCompare::LESS_THAN_EQUAL, $toField, array('throw_global_error' => true), array('invalid' => $this->getMessage('invalid')));
  40. $v->clean($value);
  41. }
  42. return $value;
  43. }
  44. }

Debug toolbar