summaryrefslogtreecommitdiffstats
path: root/library/Poolctrl/Validator/DateGreaterThan.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Poolctrl/Validator/DateGreaterThan.php')
-rw-r--r--library/Poolctrl/Validator/DateGreaterThan.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/library/Poolctrl/Validator/DateGreaterThan.php b/library/Poolctrl/Validator/DateGreaterThan.php
new file mode 100644
index 0000000..f6c1316
--- /dev/null
+++ b/library/Poolctrl/Validator/DateGreaterThan.php
@@ -0,0 +1,71 @@
+<?php
+require_once 'Zend/Validate/Abstract.php';
+
+class Poolctrl_Validate_DateGreaterThan extends Zend_Validate_Abstract
+{
+ const NOT_GREATER = 'notGreaterThan';
+
+ protected $_messageTemplates = array(
+ self::NOT_GREATER => "'%value%' has to be greater than '%min%'",
+ );
+
+ protected $_messageVariables = array(
+ 'min' => '_min'
+ );
+
+ protected $_min;
+ protected $_minTimestamp;
+
+ public function __construct($min)
+ {
+ if ($min instanceof Zend_Config) {
+ $min = $min->toArray();
+ }
+
+ if (is_array($min)) {
+ if (array_key_exists('min', $min)) {
+ $min = $min['min'];
+ $minTimestamp = strtotime($min);
+ } else {
+ require_once 'Zend/Validate/Exception.php';
+ throw new Zend_Validate_Exception("Missing option 'min'");
+ }
+ }
+
+ $this->setMin($min);
+ $this->setMinTimestamp($minTimestamp);
+ }
+
+ public function getMin()
+ {
+ return $this->_min;
+ }
+
+ public function setMin($min)
+ {
+ $this->_min = $min;
+ return $this;
+ }
+
+ public function getMinTimestamp()
+ {
+ return $this->_minTimestamp;
+ }
+
+ public function setMinTimestamp($_minTimestamp)
+ {
+ $this->_minTimestamp = $_minTimestamp;
+ }
+
+ public function isValid($value)
+ {
+ $this->_setValue($value);
+ $valueTimestamp = strtotime($value);
+
+ if ($this->getMinTimestamp() >= $valueTimestamp) {
+ $this->_error(self::NOT_GREATER);
+ return false;
+ }
+ return true;
+ }
+} \ No newline at end of file