summaryrefslogtreecommitdiffstats
path: root/library/Poolctrl/Validator/EventOverlapping.php
blob: 6e095e54a329de66b07c50dc541874bc5aa60256 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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;
	}
}