summaryrefslogblamecommitdiffstats
path: root/library/Poolctrl/Validate/EventOverlapping.php
blob: f2a077922218a4f4bfc0291f656510ecfe7ba779 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                                                            
                           









                                                               
                                                                  



                                                                                          





                                                                                             

                 

                                            






                                   
                                      
         
                                    











                                                               








                                            


                                       
                                                    
                                                                   
                                                                                                    








                                                                                       
<?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;
	}
}