summaryrefslogtreecommitdiffstats
path: root/library/Poolctrl/Validator/EventOverlapping.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Poolctrl/Validator/EventOverlapping.php')
-rwxr-xr-xlibrary/Poolctrl/Validator/EventOverlapping.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/library/Poolctrl/Validator/EventOverlapping.php b/library/Poolctrl/Validator/EventOverlapping.php
new file mode 100755
index 0000000..6e095e5
--- /dev/null
+++ b/library/Poolctrl/Validator/EventOverlapping.php
@@ -0,0 +1,72 @@
+<?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 $_overlappingevent;
+
+ public function __construct($option)
+ {
+ if ($option instanceof Zend_Config) {
+ $option = $option->toArray();
+ }
+
+ if (is_array($option)) {
+ if (array_key_exists('end', $option)) {
+ $end = $option['end'];
+ $endTimestamp = strtotime($end);
+ } else {
+ require_once 'Zend/Validate/Exception.php';
+ throw new Zend_Validate_Exception("Missing option 'end'");
+ }
+ }
+
+ $this->_setEnd($end);
+ }
+
+ 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 isValid($value)
+ {
+ $this->_setValue($value);
+ $eventMapper = new Application_Model_EventMapper();
+ $overlappingEvents = $eventMapper->getOverlappingEvents($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