Guest User

Untitled

a guest
Mar 13th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. class My_Validate_Date_LessThan extends My_Validate_Date_Abstract
  3. {
  4. const NOT_LESS = 'notLessThan';
  5.  
  6. /**
  7. * Sets validator options
  8. *
  9. * @param string|Zend_Date $date
  10. * @param string $format OPTIONAL
  11. * @param string|Zend_Locale $locale OPTIONAL
  12. * @param boolean $orEqual OPTIONAL
  13. * @return void
  14. */
  15. public function __construct($date, $format = null, $locale = null,
  16. $orEqual = false)
  17. {
  18. $this->_messageTemplates[self::NOT_LESS] = "'%value%' is not less than '%date%'";
  19. parent::__construct($date, $format, $locale, $orEqual);
  20. }
  21.  
  22. /**
  23. * Defined by Zend_Validate_Interface
  24. *
  25. * Returns true if $value is a valid date and is greater than the specified
  26. * $date. If optional $format or $locale is set the date format is checked
  27. * according to Zend_Date, see Zend_Date::isDate()
  28. *
  29. * @param string|Zend_Date $value
  30. * @return boolean
  31. */
  32. public function isValid($value, $context = null)
  33. {
  34. if (!$this->_setValue($value)) return false;
  35. if (!$this->_parseDate($context)) return false;
  36.  
  37. $compare = $this->_value->compare($this->_date);
  38. $compare = ($this->_orEqual) ? ($compare <= 0) : ($compare < 0);
  39.  
  40. if (!$compare) {
  41. $this->_error(self::NOT_LESS);
  42. return false;
  43. }
  44.  
  45. return true;
  46. }
  47. }
Add Comment
Please, Sign In to add comment