Warning, file /webapps/ocs-webserver/application/modules/statistics/controllers/WeeklyController.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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_WeeklyController 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     const YEARWEEK = 'yearweek';
0031 
0032     /** @var Statistics_Model_GoalStatistics */
0033     protected $tableStatistics;
0034     /** @var Zend_Auth */
0035     protected $authorization;
0036     /** @var Zend_Controller_Request_Abstract */
0037     protected $request;
0038     /** @var mixed */
0039     protected $loginMemberId;
0040 
0041     public function init()
0042     {
0043         parent::init();
0044 
0045         $this->tableStatistics = new Statistics_Model_GoalStatistics();
0046         $this->authorization = Zend_Auth::getInstance();
0047         $this->loginMemberId =
0048             $this->authorization->hasIdentity() ? $this->authorization->getStorage()->read()->member_id : 0;
0049         $this->request = $this->getRequest();
0050     }
0051 
0052     public function showAction()
0053     {
0054         $this->_helper->layout->disableLayout();
0055     }
0056 
0057     public function ajaxAction()
0058     {
0059         $this->_helper->layout->disableLayout();
0060         $this->_helper->viewRenderer->setNoRender(true);
0061 
0062         $identifier = $this->request->getParam(self::PROJECT_ID);
0063         $yearWeek = $this->request->getParam(self::YEARWEEK);
0064 
0065         $resultSet = $this->tableStatistics->getWeeklyStatistics($identifier, $yearWeek);
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 }