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

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 Backend_IndexController extends Local_Controller_Action_Backend
0024 {
0025     
0026 
0027     public function indexAction()
0028     {
0029 
0030     }
0031 
0032     public function metaAction()
0033     {
0034 
0035     }
0036 
0037     public function settingsAction()
0038     {
0039 
0040     }
0041 
0042     public function filebrowserAction()
0043     {
0044 
0045     }
0046 
0047     public function getnewmemberstatsAction()
0048     {
0049 
0050         $this->_helper->layout->disableLayout();
0051         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0052         $this->sendJson($modelData->getNewmemberstats());
0053     }
0054 
0055     public function sendJson($result)
0056     {
0057         if ($result) {
0058             $msg = array(
0059                 'status'  => 'ok',
0060                 'msg'     => '',
0061                 'results' => $result
0062             );
0063 
0064             return $this->_helper->json->sendJson($msg);
0065         } else {
0066             return $this->_helper->json->sendJson(array(
0067                 'status'  => 'not found',
0068                 'msg'     => 'data with given id could not be found.',
0069                 'results' => ''
0070             ));
0071         }
0072     }
0073 
0074     public function getpayoutgroupbyamountAction()
0075     {
0076         $this->_helper->layout->disableLayout();
0077         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->resources->toArray());
0078         $this->sendJson($modelData->getPayoutgroupbyamountProduct());
0079     }
0080 
0081     public function getpayoutgroupbyamountmemberAction()
0082     {
0083         $this->_helper->layout->disableLayout();
0084         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->resources->toArray());
0085                 
0086         $this->sendJson($modelData->getPayoutgroupbyamountMember());
0087     }
0088 
0089     public function getnewprojectstatsAction()
0090     {
0091         $this->_helper->layout->disableLayout();
0092         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0093         $this->sendJson($modelData->getNewprojectstats());
0094     }
0095 
0096     public function getpayoutAction()
0097     {
0098 
0099         $this->_helper->layout->disableLayout();
0100         $yyyymm = $this->getParam('yyyymm', '201708');
0101         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0102         $data = $modelData->getPayout($yyyymm);
0103         $m = new Default_Model_DbTable_ProjectPlings();
0104         $plings = $m->getAllPlingListReceived();
0105         foreach ($data as &$d) {
0106             $d['plings'] = 0;
0107             foreach ($plings as $p) {
0108                 if($p['member_id'] == $d['member_id'])
0109                 {
0110                     $d['plings'] = $p['plings'];
0111                     break;
0112                 }
0113             }
0114         }
0115         $this->sendJson($data);
0116     }
0117 
0118     public function getdownloadsdailyAction()
0119     {
0120 
0121         $this->_helper->layout->disableLayout();
0122         $numofmonthback = $this->getParam('numofmonthback', '3');
0123         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0124         $this->sendJson($modelData->getDownloadsDaily($numofmonthback));
0125     }
0126 
0127     public function getdownloadsundpayoutsdailyAction()
0128     {
0129 
0130         $this->_helper->layout->disableLayout();
0131         $yyyymm = $this->getParam('yyyymm');
0132         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0133         $this->sendJson($modelData->getDownloadsUndPayoutsDaily($yyyymm));
0134     }
0135 
0136     public function gettopdownloadsperdateAction()
0137     {
0138 
0139         $this->_helper->layout->disableLayout();
0140         $date = $this->getParam('date');
0141         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0142         $this->sendJson($modelData->getTopDownloadsPerDate($date));
0143     }
0144 
0145     public function getproductmonthlyAction()
0146     {
0147 
0148         $this->_helper->layout->disableLayout();
0149         $project_id = $this->getParam('project_id');
0150         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0151         $this->sendJson($modelData->getProductMonthly($project_id));
0152     }
0153 
0154     public function getproductdaylyAction()
0155     {
0156 
0157         $this->_helper->layout->disableLayout();
0158         $project_id = $this->getParam('project_id');
0159         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0160         $this->sendJson($modelData->getProductDayly($project_id));
0161     }
0162 
0163 
0164     public function gettopdownloadspermonthAction()
0165     {
0166 
0167         $this->_helper->layout->disableLayout();
0168         $month = $this->getParam('month');
0169         $catid = $this->getParam('catid');
0170         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0171         $this->sendJson($modelData->getTopDownloadsPerMonth($month,$catid));
0172     }
0173 
0174     public function getdownloadsdomainAction()
0175     {
0176 
0177         $this->_helper->layout->disableLayout();
0178         $dateBegin = $this->getParam('dateBegin');
0179         $dateEnd = $this->getParam('dateEnd');
0180         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0181         $this->sendJson($modelData->getDownloadsDomainStati($dateBegin, $dateEnd));
0182     }
0183  
0184     public function getpayoutmemberAction()
0185     {
0186 
0187         $this->_helper->layout->disableLayout();
0188         $member = $this->getParam('member', '1');
0189         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0190         $this->sendJson($modelData->getPayoutOfMember($member));
0191     }
0192 
0193     public function getpayoutyearAction()
0194     {
0195         $this->_helper->layout->disableLayout();
0196         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0197         $this->sendJson($modelData->getPayoutyear());
0198     }
0199 
0200     public function getpayoutcategorymonthlyAction()
0201     {
0202         $this->_helper->layout->disableLayout();
0203         $yyyymm = $this->getParam('yyyymm', '201708');
0204         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0205         $this->sendJson($modelData->getPayoutCategoryMonthly($yyyymm));
0206     }
0207 
0208     public function getpayoutmemberpercategoryAction()
0209     {
0210         $this->_helper->layout->disableLayout();
0211         $yyyymm = $this->getParam('yyyymm', '201708');
0212         $catid = (int)$this->getParam('catid', 0);
0213         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0214         $this->sendJson($modelData->getPayoutMemberPerCategory($yyyymm,$catid));
0215     }
0216 
0217     public function getpayoutcategoryAction()
0218     {   
0219 
0220         $this->_helper->layout->disableLayout();
0221         $catid = (int)$this->getParam('catid', 0);
0222         
0223         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0224 
0225         $result = $modelData->getPayoutCategory($catid);
0226         if($catid==0)
0227         {
0228             $modelCategoryStore = new Default_Model_DbTable_ConfigStoreCategory();
0229             $pids = $modelCategoryStore->fetchCatIdsForStore(Statistics_Model_Data::DEFAULT_STORE_ID);
0230         }else{
0231             $modelCategoriesTable = new Default_Model_DbTable_ProjectCategory();
0232             $pids = $modelCategoriesTable->fetchImmediateChildrenIds($catid,$modelCategoriesTable::ORDERED_TITLE);
0233         }
0234         
0235         if($pids)
0236         {
0237             $modelCategories = new Default_Model_ProjectCategory();
0238            $pidsname = $modelCategories->fetchCatNamesForID($pids);    
0239         }else
0240         {
0241             $pidsname=[];
0242         }
0243         
0244 
0245         $msg = array(
0246             'status'  => 'ok',
0247             'msg'     => '',
0248             'pids'     => $pids,
0249             'pidsname' => $pidsname,
0250             'results' => $result
0251         );
0252         return $this->_helper->json->sendJson($msg);
0253 
0254         //$this->sendJson($modelData->getPayoutCategory($catid));
0255     }
0256 
0257     public function newcomerAction()
0258     {
0259         $this->_helper->layout->disableLayout();
0260         $yyyymm = $this->getParam('yyyymm', '1');
0261         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0262         $this->sendJson($modelData->getNewcomer($yyyymm));
0263     }
0264 
0265     public function newloserAction()
0266     {
0267         $this->_helper->layout->disableLayout();
0268         $yyyymm = $this->getParam('yyyymm', '1');
0269         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0270         $this->sendJson($modelData->getNewloser($yyyymm));
0271     }
0272 
0273     public function monthdiffAction()
0274     {
0275         $this->_helper->layout->disableLayout();
0276         $yyyymm = $this->getParam('yyyymm', '1');
0277         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0278         $this->sendJson($modelData->getMonthDiff($yyyymm));
0279     }
0280 
0281 
0282     public function newproductsweeklyAction()
0283     {
0284         $this->_helper->layout->disableLayout();
0285         // $yyyymm = $this->getParam('yyyymm', '1');
0286         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0287         // $list = array_reverse($modelData->getNewprojectWeeklystats());
0288         // $this->sendJson($list);
0289 
0290         $listwallpapers = $modelData->getNewprojectWeeklystatsWallpapers();
0291         $listNowallpapers = $modelData->getNewprojectWeeklystatsWithoutWallpapers();
0292 
0293         $map1 = array();
0294         foreach($listwallpapers as $value) {          
0295             $map1[$value['yyyykw']] = $value['amount'];
0296         }
0297 
0298         $map2 = array();
0299         foreach($listNowallpapers as $value) {          
0300             $map2[$value['yyyykw']] = $value['amount'];
0301         }
0302 
0303         $datetime = new DateTime();
0304         $result = array();
0305         for ($i = 1; $i < 60; $i++) {
0306             $w = '-1 week';
0307             $datetime->modify($w);    
0308             $month = $datetime->format('YW');
0309 
0310             $value1=0;
0311             if(isset($map1[$month])){
0312                 $value1 = $map1[$month];
0313             }
0314             $value2=0;
0315             if(isset($map2[$month])){
0316                 $value2 = $map2[$month];
0317             }
0318             $result[] = array('yyyykw'=>$month,
0319                             'amountnowallpapers'=>$value2,
0320                             'amountwallpapers' =>$value1
0321                             );
0322         }
0323         $list = array_reverse($result);
0324         $this->sendJson($list);        
0325 
0326         // $this->_helper->json($list);
0327        
0328     }
0329 
0330     public function getnewmembersprojectsAction()
0331     {
0332 
0333         $this->_helper->layout->disableLayout();
0334         $modelData = new Statistics_Model_Data(Zend_Registry::get('config')->settings->dwh->toArray());
0335 
0336         try {
0337             $result = array();
0338 
0339             $m = $modelData->getNewmemberstats();
0340             $p = $modelData->getNewprojectstats();
0341             foreach ($m as $member) {
0342                 $date = $member['memberdate'];
0343                 $t = array(
0344                     'date'     => $date,
0345                     'members'  => $member['daycount'],
0346                     'projects' => 0
0347                 );
0348                 foreach ($p as $project) {
0349                     $d = $project['projectdate'];
0350                     if ($d == $date) {
0351                         $t['projects'] = $project['daycount'];
0352                         break;
0353                     }
0354                 }
0355                 $result [] = $t;
0356             }
0357         } catch (Exception $e) {
0358             Zend_Registry::get('logger')->error($e->getMessage());
0359 
0360             return $this->_helper->json->sendJson(array(
0361                 'status'  => 'error',
0362                 'msg'     => 'error while processing request',
0363                 'results' => ''
0364             ));
0365         }
0366 
0367         if ($result) {
0368             $msg = array(
0369                 'status'  => 'ok',
0370                 'msg'     => '',
0371                 'results' => array_reverse($result)
0372             );
0373 
0374             return $this->_helper->json->sendJson($msg);
0375         }
0376 
0377         return $this->_helper->json->sendJson(array(
0378             'status'  => 'not found',
0379             'msg'     => 'data with given id could not be found.',
0380             'results' => ''
0381         ));
0382     }
0383 
0384 }