File indexing completed on 2024-05-12 05:59:09

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_DailyController 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         $day = $this->request->getParam(self::DAY);
0065 
0066         $resultSet = $this->tableStatistics->getDailyStatistics($identifier, $year, $month, $day);
0067 
0068         if (empty($resultSet)) {
0069             $this->_helper->json(null);
0070         } else {
0071             $this->_helper->json($this->generateGoogleChartDataSet($resultSet));
0072         }
0073     }
0074 
0075     /**
0076      * @param array $dataSet
0077      *
0078      * @return array
0079      */
0080     protected function generateGoogleChartDataSet($dataSet)
0081     {
0082         $rows = array();
0083         $rows[] = array('Key', 'Quantity');
0084         foreach ($dataSet as $value) {
0085             foreach ($value as $key => $rowElement) {
0086                 $rows[] = array($key, (int)$rowElement);
0087             }
0088         }
0089 
0090         return $rows;
0091     }
0092 
0093 }