summaryrefslogblamecommitdiffstats
path: root/application/controllers/StatisticsController.php
blob: 66141c8981a3ae09e511ec87dcf1d8d32abb3b09 (plain) (tree)
1
2
3
4
5
6
7
8
9


                                                         

                            
                           


                                       
                       



                              


                                                                
                                                                     


















                                                                                                                                                                                                             



                                                   

         
                                              


                                                   










                                                                                                                                    
                              

                                                                                      
                                                                                            




                                       
                                             


                                                   










                                                                                                                             
                              

                                                                                     




                                       
                                             


                                                   










                                                                                                                                    
                              

                                                                                            




                                       
                                          


                                                   










                                                                                                                                    
                              

                                                                                  





                                          


                                                   


                                         


                                                   


                                         


                                                   


                                      


                                                   


         
<?php
class StatisticsController extends Zend_Controller_Action
{
	protected $config;
	protected $pbs2host;
	protected $pbs2Api;
	protected $eventMapper;
	protected $eventcategoryMapper;
	protected $eventreportMapper;
	protected $acl;


	public function init()
	{
		$bootstrap = $this->getInvokeArg('bootstrap');
		$this->config = $bootstrap->getOptions();
		$this->pbs2host = $this->config['pbs2']['host'];
		$this->pbs2Api = new Poolctrl_Pbs2Api($this->config);
		$this->eventMapper = new Application_Model_EventMapper();
		$this->eventcategoryMapper = new Application_Model_EventcategoryMapper();
		$this->eventreportMapper = new Application_Model_EventreportMapper();

	 if (Zend_Auth::getInstance()->hasIdentity()) {
	 	$this->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
	 	if(isset($this->userIDsNamespace['apikey'])) {
	 		$this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
	 	}
	 	if(!$this->userIDsNamespace['membershipID'] !='') {
	 		$this->_helper->redirector('selectmembership', 'person');
	 		return;
	 	}
	 } else {
	 	$this->_helper->redirector('login', 'auth');
	 	return;
	 }
	}

	public function indexAction() {
		if(!$this->acl->checkRight('eo')) {
			$this->_redirect('/');
		}
	}

	public function categoryplotAction() {
		if(!$this->acl->checkRight('eo')) {
			$this->_redirect('/');
		}
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		$poolID = $this->getRequest()->getParam('poolID');
		$userIDsSession = new Zend_Session_Namespace('userIDs');
		$userIDsSession->poolID = $poolID;

		if($this->acl->checkRight('eoo')) {
			$eventList = $this->eventMapper->fetchAll();
		} else {
			$eventList = $this->eventMapper->findBy(array("pbs_membershipID", $this->userIDsNamespace['membershipID']));
		}
    // 1 = barPlot 2 = piePlot
		$ret['dataBar'] = $this->eventMapper->getCategoryPlotdata($poolID, 1);
		$ret['dataPie'] = $this->eventMapper->getCategoryPlotdata($poolID, 2);
		$ret['color'] = $this->eventcategoryMapper->getCategoryColor($poolID, null);

		echo json_encode($ret);

	}

	public function runningplotAction() {
		if(!$this->acl->checkRight('er')) {
			$this->_redirect('/');
		}
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		$poolID = $this->getRequest()->getParam('poolID');
		$userIDsSession = new Zend_Session_Namespace('userIDs');
		$userIDsSession->poolID = $poolID;

		if($this->acl->checkRight('eoo')) {
		 $eventList = $this->eventMapper->fetchAll();
		} else {
		 $eventList = $this->eventMapper->findBy(array("pbs_membershipID", $this->userIDsNamespace['membershipID']));
		}
    // 1 = barPlot 2 = piePlot
		$ret['dataBar'] = $this->eventMapper->getRunningPlotdata($poolID, 1);
		$ret['dataPie'] = $this->eventMapper->getRunningPlotdata($poolID, 2);

		echo json_encode($ret);

	}

	public function successplotAction() {
		if(!$this->acl->checkRight('er')) {
			$this->_redirect('/');
		}
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		$poolID = $this->getRequest()->getParam('poolID');
		$userIDsSession = new Zend_Session_Namespace('userIDs');
		$userIDsSession->poolID = $poolID;

		if($this->acl->checkRight('eoo')) {
			$eventList = $this->eventMapper->fetchAll();
		} else {
			$eventList = $this->eventMapper->findBy(array("pbs_membershipID", $this->userIDsNamespace['membershipID']));
		}
    // 1 = barPlot 2 = piePlot
		$ret['dataBar'] = $this->eventreportMapper->getSuccessPlotdata($poolID, 1);
		$ret['dataPieS'] = $this->eventreportMapper->getSuccessPlotdata($poolID, 2);

		echo json_encode($ret);

	}

	public function typeplotAction() {
		if(!$this->acl->checkRight('eo')) {
			$this->_redirect('/');
		}
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		$poolID = $this->getRequest()->getParam('poolID');
		$userIDsSession = new Zend_Session_Namespace('userIDs');
		$userIDsSession->poolID = $poolID;

		if($this->acl->checkRight('eoo')) {
			$eventList = $this->eventMapper->fetchAll();
		} else {
			$eventList = $this->eventMapper->findBy(array("pbs_membershipID", $this->userIDsNamespace['membershipID']));
		}
    // 1 = barPlot 2 = piePlot
		$ret['dataBar'] = $this->eventMapper->getTypePlotdata($poolID, 1);
		$ret['dataPie'] = $this->eventMapper->getTypePlotdata($poolID, 2);

		echo json_encode($ret);

	}

	public function categoryAction() {
		if(!$this->acl->checkRight('eo')) {
			$this->_redirect('/');
		}
	}

	public function runningAction() {
		if(!$this->acl->checkRight('er')) {
			$this->_redirect('/');
		}
	}

	public function successAction() {
		if(!$this->acl->checkRight('er')) {
			$this->_redirect('/');
		}
	}

	public function typeAction() {
		if(!$this->acl->checkRight('eo')) {
			$this->_redirect('/');
		}
	}

}