summaryrefslogtreecommitdiffstats
path: root/application/controllers/EventController.php
blob: bf10891119009f874dd11986664ab2b14ebe0139 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/*
 * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg
 * This program is free software distributed under the GPL version 2.
 * See http://gpl.openslx.org/
 *
 * If you have any feedback please consult http://feedback.openslx.org/ and
 * send your suggestions, praise, or complaints to feedback@openslx.org
 *
 * General information about OpenSLX can be found at http://openslx.org/
 */

class EventController extends Zend_Controller_Action
{

	protected $eventMapper;
	protected $poolMapper;
	protected $bootosMapper;
	protected $membershipMapper;
	protected $personMapper;

	public function init()
	{
		$this->eventMapper = new Application_Model_EventMapper();
		$this->poolMapper = new Application_Model_PoolMapper();
		$this->bootosMapper = new Application_Model_BootOsMapper();
		$this->membershipMapper = new Application_Model_MembershipMapper();
		$this->personMapper = new Application_Model_PersonMapper();
	}

	public function indexAction()
	{
		$events = $this->eventMapper->fetchAll();
		if(is_array($events)) {
			foreach($events as $event) {
				$event = $event->toArray();
				$bootos = new Application_Model_BootOs();
				$this->bootosMapper->find($event['pbs_bootosID'], $bootos);
				$event['pbs_bootos_title'] = $bootos->getTitle();
				$membership = new Application_Model_Membership();
				$this->membershipMapper->find($event['pbs_membershipID'], $membership);
				$person = new Application_Model_Person();
				$this->personMapper->find($membership->getPersonID(), $person);
				$event['pbs_person_name'] = $person->getFirstname() . " " . $person->getName();
				$pool = new Application_Model_Pool();
				$this->poolMapper->find($event['pbs_poolID'], $pool);
				$eventlist[$pool->getTitle()][] = $event;
			}
		}

		$this->view->eventlist = $eventlist;
	}

	public function addAction()
	{
		if (!isset($_POST["add"])){
			$addForm = new user_Form_EventAdd();
		} else {
			$addForm = new user_Form_EventAdd(array($_POST));

			if ($addForm->isValid($_POST)) {
				$event = new Application_Model_Event($_POST);

				try {
					$eventID = $this->eventMapper->save($event);
				} catch(Zend_Exception $e)
				{
					echo "Caught exception: " . get_class($e) . "<br/>";
					echo "Message: " . $e->getMessage() . "<br/>";
					return;
				}
			}
		}

		$this->view->addForm = $addForm;
	}

	public function deleteAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$eventID = $this->_request->getParam('eventID');
		if(isset($eventID)) {
			$event = new Application_Model_Event();
			$this->eventMapper->find($eventID, $event);
			try {
				$this->eventMapper->delete($event);
			} catch(Zend_Exception $e)
			{
				echo "Caught exception: " . get_class($e) . "<br/>";
				echo "Message: " . $e->getMessage() . "<br/>";
				return;
			}
			$this->_redirect('/event/');
		} else {
			$this->_redirect('/event/');
			return;

		}
	}

	public function editAction()
	{
		$eventID = $this->_request->getParam('groupID');
		if(!isset($eventID)) {
			$this->_helper->redirector('add', 'event');
			return;
		} else {
			if (isset($_POST["save"])){
				$editForm = new user_Form_EventEdit(array($_POST));
				if ($editForm->isValid($_POST)) {
					$event = new Application_Model_Event($_POST);
					$event->setID($eventID);
					try {
						$this->eventMapper->save($event);
					} catch(Zend_Exception $e)
					{
						echo "Caught exception: " . get_class($e) . "<br/>";
						echo "Message: " . $e->getMessage() . "<br/>";
						return;
					}
				}
			} else {
				$event = new Application_Model_Event();
				$this->eventMapper->find($eventID, $event);
				$editForm = new user_Form_EventEdit();
			}
			$this->view->editForm = $editForm;
		}
	}
}