summaryrefslogblamecommitdiffstats
path: root/application/controllers/EventController.php
blob: 74271a3d02c3267831c8a3db9f9b7906f66a62eb (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
     









                                                                           



                                                    




                                    



                                                                         



                                                                                   






                                                         






                                                                                                       
                                                                                               



                                                                                                               








                                                    
                                                                   
                        
                                                                                
































                                                                                            
                                                    








                                                    
                                                                




                                                                   
                                                                                          














                                                                                                    
                                                                             




                                                          
<?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 Application_Form_EventAdd();
		} else {
			$addForm = new Application_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('eventID');
		if(!isset($eventID)) {
			$this->_helper->redirector('add', 'event');
			return;
		} else {
			if (isset($_POST["save"])){
				$editForm = new Application_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 Application_Form_EventEdit();
			}
			$this->view->editForm = $editForm;
		}
	}
}