File indexing completed on 2024-12-22 05:33:57

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class Statistics_MonthlyController extends Zend_Controller_Action
0024 {
0025 
0026     const PROJECT_ID = 'project_id';
0027     const YEAR = 'year';
0028     const MONTH = 'month';
0029     const DAY = 'day';
0030 
0031     /** @var Statistics_Model_GoalStatistics */
0032     protected $tableStatistics;
0033     /** @var Zend_Auth */
0034     protected $authorization;
0035     /** @var Zend_Controller_Request_Abstract */
0036     protected $request;
0037     /** @var mixed */
0038     protected $loginMemberId;
0039 
0040     public function init()
0041     {
0042         parent::init();
0043 
0044         $this->tableStatistics = new Statistics_Model_GoalStatistics();
0045         $this->authorization = Zend_Auth::getInstance();
0046         $this->loginMemberId =
0047             $this->authorization->hasIdentity() ? $this->authorization->getStorage()->read()->member_id : 0;
0048         $this->request = $this->getRequest();
0049     }
0050 
0051     public function showAction()
0052     {
0053         $this->_helper->layout->disableLayout();
0054     }
0055 
0056     public function ajaxAction()
0057     {
0058         $this->_helper->layout->disableLayout();
0059         $this->_helper->viewRenderer->setNoRender(true);
0060 
0061         $identifier = $this->request->getParam(self::PROJECT_ID);
0062         $year = $this->request->getParam(self::YEAR);
0063         $month = $this->request->getParam(self::MONTH);
0064 
0065         $resultSet = $this->tableStatistics->getMonthlyStatistics($identifier, $year, $month);
0066 
0067         if (empty($resultSet)) {
0068             $this->_helper->json(null);
0069         } else {
0070             $this->_helper->json($this->generateGoogleChartDataSet($resultSet));
0071         }
0072     }
0073 
0074     /**
0075      * @param array $dataSet
0076      *
0077      * @return array
0078      */
0079     protected function generateGoogleChartDataSet($dataSet)
0080     {
0081         $rows = array();
0082         $rows[] = array_keys($dataSet[0]);
0083         foreach ($dataSet as $value) {
0084             $row = array();
0085             foreach ($value as $key => $rowElement) {
0086                 $row[] = (int)$rowElement;
0087             }
0088             $rows[] = $row;
0089         }
0090 
0091         return $rows;
0092     }
0093 
0094 }