summaryrefslogtreecommitdiffstats
path: root/library/Poolctrl/Validate
diff options
context:
space:
mode:
authorBjörn Geiger2011-10-24 13:30:25 +0200
committerBjörn Geiger2011-10-24 13:30:25 +0200
commit015cc65efb99d98b5cebc021db50b15ece92e41c (patch)
treeebc5640c01843bac8bd250d19b0e529e3d032abc /library/Poolctrl/Validate
parentMinor (diff)
downloadpoolctrl-015cc65efb99d98b5cebc021db50b15ece92e41c.tar.gz
poolctrl-015cc65efb99d98b5cebc021db50b15ece92e41c.tar.xz
poolctrl-015cc65efb99d98b5cebc021db50b15ece92e41c.zip
weitere korrektur
Diffstat (limited to 'library/Poolctrl/Validate')
-rwxr-xr-xlibrary/Poolctrl/Validate/DateGreaterThan.php108
-rwxr-xr-xlibrary/Poolctrl/Validate/EventOverlapping.php88
-rwxr-xr-xlibrary/Poolctrl/Validate/TitleUnique.php57
3 files changed, 253 insertions, 0 deletions
diff --git a/library/Poolctrl/Validate/DateGreaterThan.php b/library/Poolctrl/Validate/DateGreaterThan.php
new file mode 100755
index 0000000..d7be22d
--- /dev/null
+++ b/library/Poolctrl/Validate/DateGreaterThan.php
@@ -0,0 +1,108 @@
+<?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 must be set to a date later than %compare% date",
+ );
+
+ protected $_messageVariables = array(
+ 'element' => '_element',
+ 'compare' => '_compare',
+ );
+
+ protected $_element;
+ protected $_compare;
+ protected $_min;
+ protected $_minTimestamp;
+
+ public function __construct($option)
+ {
+ if ($option instanceof Zend_Config) {
+ $option = $option->toArray();
+ }
+
+ if (is_array($option)) {
+ if (array_key_exists('min', $option)) {
+ $min = $option['min'];
+ $minTimestamp = strtotime($min);
+ } else {
+ require_once 'Zend/Validate/Exception.php';
+ throw new Zend_Validate_Exception("Missing option 'min'");
+ }
+ if (array_key_exists('element', $option)) {
+ $element = $option['element'];
+ } else {
+ require_once 'Zend/Validate/Exception.php';
+ throw new Zend_Validate_Exception("Missing option 'element'");
+ }
+ if (array_key_exists('compare', $option)) {
+ $compare = $option['compare'];
+ } else {
+ require_once 'Zend/Validate/Exception.php';
+ throw new Zend_Validate_Exception("Missing option 'compare'");
+ }
+ }
+
+ $this->setElement($element);
+ $this->setCompare($compare);
+ $this->setMin($min);
+ $this->setMinTimestamp($minTimestamp);
+ }
+
+ public function getElement()
+ {
+ return $this->_element;
+ }
+
+ public function setElement($element)
+ {
+ $this->_element = $element;
+ }
+
+ public function getCompare()
+ {
+ return $this->_compare;
+ }
+
+ public function setCompare($compare)
+ {
+ $this->_compare = $compare;
+ }
+
+ 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
diff --git a/library/Poolctrl/Validate/EventOverlapping.php b/library/Poolctrl/Validate/EventOverlapping.php
new file mode 100755
index 0000000..f2a0779
--- /dev/null
+++ b/library/Poolctrl/Validate/EventOverlapping.php
@@ -0,0 +1,88 @@
+<?php
+require_once 'Zend/Validate/Abstract.php';
+
+class Poolctrl_Validate_EventOverlapping extends Zend_Validate_Abstract
+{
+ const EVENT_OVERLAPPING = 'overlapping';
+
+ protected $_messageTemplates = array(
+ self::EVENT_OVERLAPPING => "This Event is overlapping the Event %overlappingEvent%",
+ );
+
+ protected $_messageVariables = array(
+ 'overlappingEvent' => '_overlappingEvent',
+ );
+
+ protected $_end;
+ protected $_poolID;
+ protected $_overlappingevent;
+
+ public function __construct($option)
+ {
+ if ($option instanceof Zend_Config) {
+ $option = $option->toArray();
+ }
+
+ if (is_array($option)) {
+ if (array_key_exists('end', $option)) {
+ $_end = strtotime($option['end']);
+ } else {
+ require_once 'Zend/Validate/Exception.php';
+ throw new Zend_Validate_Exception("Missing option 'end'");
+ }
+ if (array_key_exists('poolID', $option)) {
+ $_poolID = $option['poolID'];
+ } else {
+ require_once 'Zend/Validate/Exception.php';
+ throw new Zend_Validate_Exception("Missing option 'poolID'");
+ }
+ }
+
+ $this->_setEnd($_end);
+ $this->_setPoolID($_poolID);
+ }
+
+ public function _getEnd()
+ {
+ return $this->_end;
+ }
+
+ public function _setEnd($_end)
+ {
+ $this->_end = $_end;
+ }
+
+ public function _getOverlappingevent()
+ {
+ return $this->_overlappingevent;
+ }
+
+ public function _setOverlappingevent($overlappingevent)
+ {
+ $this->_overlappingevent = $overlappingevent;
+ }
+
+ public function _getPoolID()
+ {
+ return $this->_poolID;
+ }
+
+ public function _setPoolID($_poolID)
+ {
+ $this->_poolID = $_poolID;
+ }
+
+ public function isValid($value)
+ {
+ $this->_setValue(strtotime($value));
+ $eventMapper = new Application_Model_EventMapper();
+ $overlappingEvents = $eventMapper->getOverlappingEvents($this->_value, $this->_end);
+
+ if (count($overlappingEvents) > 0) {
+ $this->_setOverlappingevent($overlappingEvents[0]->getTitle());
+ $this->_error(self::EVENT_OVERLAPPING);
+ return false;
+ }
+ return true;
+ }
+} \ No newline at end of file
diff --git a/library/Poolctrl/Validate/TitleUnique.php b/library/Poolctrl/Validate/TitleUnique.php
new file mode 100755
index 0000000..f051438
--- /dev/null
+++ b/library/Poolctrl/Validate/TitleUnique.php
@@ -0,0 +1,57 @@
+<?php
+require_once 'Zend/Validate/Abstract.php';
+
+class Poolctrl_Validate_TitleUnique extends Zend_Validate_Abstract
+{
+ const NOT_UNIQUE = 'notUnique';
+
+ protected $_messageTemplates = array(
+ self::NOT_UNIQUE => "Title is already assigned",
+ );
+
+ public function __construct($option)
+ {
+ if ($option instanceof Zend_Config) {
+ $option = $option->toArray();
+ }
+
+ if (is_array($option)) {
+ if (array_key_exists('title', $option)) {
+ $this->oldTitle = $option['title'];
+ }
+ }
+ }
+
+ protected $oldTitle;
+
+ public function isValid($value)
+ {
+ $this->_setValue($value);
+ if(empty($this->oldTitle)) {
+ $eventMapper = new Application_Model_EventMapper();
+ $sameEvent = $eventMapper->findBy(array("title" => $value));
+
+ if (count($sameEvent) > 0) {
+ $this->_error(self::NOT_UNIQUE);
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ if($this->oldTitle == $value) {
+ return true;
+ } else {
+ $eventMapper = new Application_Model_EventMapper();
+ $sameEvent = $eventMapper->findBy(array("title" => $value));
+
+ if (count($sameEvent) > 0) {
+ $this->_error(self::NOT_UNIQUE);
+ return false;
+ } else {
+ return true;
+ }
+
+ }
+ }
+ }
+} \ No newline at end of file