From 767620295b5144d82edff74016a8722c3349e6d0 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Mon, 24 Oct 2011 13:01:31 +0200 Subject: verschiedenes --- application/forms/EventAdd.php | 4 +- application/forms/EventEdit.php | 2 + application/models/EventMapper.php | 17 ++++++ library/Poolctrl/Validator/DateGreaterThan.php | 2 +- library/Poolctrl/Validator/EventOverlapping.php | 72 +++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100755 library/Poolctrl/Validator/EventOverlapping.php diff --git a/application/forms/EventAdd.php b/application/forms/EventAdd.php index 0aee9e0..6f579b5 100755 --- a/application/forms/EventAdd.php +++ b/application/forms/EventAdd.php @@ -168,7 +168,7 @@ class Application_Form_EventAdd extends Zend_Form 'label' => 'Immediate Event:', 'value' => array(0,1), )); - + $this->addElement('checkbox', 'force', array( 'required' => false, 'label' => 'Force event:', @@ -185,6 +185,7 @@ class Application_Form_EventAdd extends Zend_Form 'label' => 'Start:', 'value' => $this->start, )); + $this->getElement('start')->addPrefixPath('Poolctrl_Validate', 'Poolctrl/Validator/', 'validate'); $this->addElement('text', 'end', array( 'filters' => array('StringTrim'), @@ -198,6 +199,7 @@ class Application_Form_EventAdd extends Zend_Form 'value' => $this->end, )); $this->getElement('end')->addPrefixPath('Poolctrl_Validate', 'Poolctrl/Validator/', 'validate'); + $this->getElement('start')->addValidator(new Poolctrl_Validate_EventOverlapping(), array('end' => $this->getElement('end')->getValue())); $this->addElement('checkbox', 'repeat', array( 'onchange' => 'repeatChanged("repeat")', diff --git a/application/forms/EventEdit.php b/application/forms/EventEdit.php index 00eb210..baee5b4 100755 --- a/application/forms/EventEdit.php +++ b/application/forms/EventEdit.php @@ -156,6 +156,7 @@ class Application_Form_EventEdit extends Zend_Form 'label' => 'Start:', 'value' => date ('m/d/Y h:i a', strtotime( $this->params['start'])), )); + $this->getElement('start')->addPrefixPath('Poolctrl_Validate', 'Poolctrl/Validator/', 'validate'); if(isset($this->params['end'])) { $this->addElement('text', 'end', array( @@ -184,6 +185,7 @@ class Application_Form_EventEdit extends Zend_Form )); $this->getElement('end')->addPrefixPath('Poolctrl_Validate', 'Poolctrl/Validator/', 'validate'); } + $this->getElement('start')->addValidator(new Poolctrl_Validate_EventOverlapping(array('end' => $this->getElement('end')->getValue()))); if( $this->params['repeat'] == 1) { $this->addElement('checkbox', 'repeat', array( diff --git a/application/models/EventMapper.php b/application/models/EventMapper.php index 8bad409..7e5f41a 100755 --- a/application/models/EventMapper.php +++ b/application/models/EventMapper.php @@ -465,4 +465,21 @@ class Application_Model_EventMapper } + public function getOverlappingEvents($start, $end) { + $db = Zend_Db_Table::getDefaultAdapter(); + $select = "SELECT * FROM poolctrl_event WHERE ( start < '" . $start . "' ) AND ( end BETWEEN '" . $end . "' AND '" . $start . "' )"; + $stmt1 = $db->query($select); + $result1 = $stmt1->fetchAll(); + $select = "SELECT * FROM poolctrl_event WHERE ( start BEETWEEN '" . $start . "' AND '" . $end . "' ) AND ( end BEETWEEN '" . $start . "' AND '" . $end . "' )"; + $stmt2 = $db->query($select); + $result2 = $stmt2->fetchAll(); + $merge = array_merge($result1, $result2); + $select = "SELECT * FROM poolctrl_event WHERE ( start BEETWEEN '" . $start . "' AND '" . $end . "' ) AND ( end > '" . $end . "' )"; + $stmt3 = $db->query($select); + $result3 = $stmt3->fetchAll(); + $return = array_merge($merge, $result3); + + return $return; + } + } \ No newline at end of file diff --git a/library/Poolctrl/Validator/DateGreaterThan.php b/library/Poolctrl/Validator/DateGreaterThan.php index d326f0d..d7be22d 100755 --- a/library/Poolctrl/Validator/DateGreaterThan.php +++ b/library/Poolctrl/Validator/DateGreaterThan.php @@ -37,7 +37,7 @@ class Poolctrl_Validate_DateGreaterThan extends Zend_Validate_Abstract $element = $option['element']; } else { require_once 'Zend/Validate/Exception.php'; - throw new Zend_Validate_Exception("Missing option 'compare'"); + throw new Zend_Validate_Exception("Missing option 'element'"); } if (array_key_exists('compare', $option)) { $compare = $option['compare']; 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 @@ + "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 -- cgit v1.2.3-55-g7522