statistic_main.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Statistic_Main extends oxAdminDetails
00009 {
00017     public function render()
00018     {
00019         $myConfig  = $this->getConfig();
00020         $oLang = oxRegistry::getLang();
00021 
00022         parent::render();
00023 
00024         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00025         $aReports = array();
00026         if ( $soxId != "-1" && isset( $soxId)) {
00027             // load object
00028             $oStat = oxNew( "oxstatistic" );
00029             $oStat->load( $soxId);
00030 
00031             $aReports = $oStat->getReports();
00032             $this->_aViewData["edit"] =  $oStat;
00033         }
00034 
00035         // setting all reports data: check for reports and load them
00036         //$sPath     = getShopBasePath().$myConfig->getConfigParam( 'sAdminDir' ) . "/reports";
00037         $sPath     = getShopBasePath(). "aplication/controllers/admin/reports";
00038         $iLanguage = (int) oxConfig::getParameter("editlanguage");
00039         $aAllreports = array();
00040 
00041         $aReportFiles = glob( $sPath."/*.php" );
00042         foreach ( $aReportFiles as $sFile ) {
00043             if ( is_file( $sFile ) && !is_dir( $sFile ) ) {
00044 
00045                 $sConst = strtoupper( str_replace( '.php', '', basename( $sFile ) ) );
00046 
00047                 // skipping base report class
00048                 if ( $sConst == 'REPORT_BASE') {
00049                     continue;
00050                 }
00051 
00052                 include $sFile;
00053 
00054                 $oItem = new stdClass();
00055                 $oItem->filename = basename( $sFile );
00056                 $oItem->name     = $oLang->translateString( $sConst, $iLanguage );
00057                 $aAllreports[]   = $oItem;
00058             }
00059         }
00060 
00061         // setting reports data
00062         oxSession::setVar( "allstat_reports", $aAllreports);
00063         oxSession::setVar( "stat_reports_$soxId", $aReports);
00064 
00065         // passing assigned reports count
00066         if ( is_array($aReports) ) {
00067             $this->_aViewData['ireports'] = count($aReports);
00068         }
00069 
00070         if ( oxConfig::getParameter("aoc") ) {
00071             $oStatisticMainAjax = oxNew( 'statistic_main_ajax' );
00072             $this->_aViewData['oxajax'] = $oStatisticMainAjax->getColumns();
00073 
00074             return "popups/statistic_main.tpl";
00075         }
00076 
00077         return "statistic_main.tpl";
00078     }
00079 
00085     public function save()
00086     {
00087         $soxId = $this->getEditObjectId();
00088         $aParams = oxConfig::getParameter( "editval");
00089 
00090         // shopid
00091         $sShopID = oxSession::getVar( "actshop");
00092         $oStat = oxNew( "oxstatistic" );
00093         if ( $soxId != "-1")
00094             $oStat->load( $soxId);
00095         else
00096             $aParams['oxstatistics__oxid'] = null;
00097 
00098         $aParams['oxstatistics__oxshopid'] = $sShopID;
00099         $oStat->assign($aParams);
00100         $oStat->save();
00101 
00102         // set oxid if inserted
00103         $this->setEditObjectId( $oStat->getId() );
00104     }
00105 
00111     public function generate()
00112     {
00113         $myConfig  = $this->getConfig();
00114 
00115         $soxId = $this->getEditObjectId();
00116 
00117         // load object
00118         $oStat = oxNew( "oxstatistic" );
00119         $oStat->load( $soxId );
00120 
00121         $aAllreports = $oStat->getReports();
00122 
00123         $oShop = oxNew( "oxshop" );
00124         $oShop->load( $myConfig->getShopId());
00125         $oShop = $this->addGlobalParams( $oShop );
00126 
00127         $sTimeFrom = oxConfig::getParameter( "time_from" );
00128         $sTimeTo   = oxConfig::getParameter( "time_to" );
00129         if ( $sTimeFrom && $sTimeTo ) {
00130             $sTimeFrom = oxRegistry::get("oxUtilsDate")->formatDBDate( $sTimeFrom, true );
00131             $sTimeFrom = date( "Y-m-d", strtotime( $sTimeFrom ) );
00132             $sTimeTo = oxRegistry::get("oxUtilsDate")->formatDBDate( $sTimeTo, true );
00133             $sTimeTo = date( "Y-m-d", strtotime( $sTimeTo ) );
00134         } else {
00135             $dDays = oxConfig::getParameter( "timeframe" );
00136             $dNow  = time();
00137             $sTimeFrom = date( "Y-m-d", mktime( 0, 0, 0, date( "m", $dNow ), date( "d", $dNow ) - $dDays, date( "Y", $dNow ) ) );
00138             $sTimeTo   = date( "Y-m-d", time() );
00139         }
00140 
00141         $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
00142         $oSmarty->assign( "time_from", $sTimeFrom." 23:59:59" );
00143         $oSmarty->assign( "time_to", $sTimeTo." 23:59:59" );
00144         $oSmarty->assign( "oViewConf", $this->_aViewData["oViewConf"]);
00145 
00146         echo( $oSmarty->fetch( "report_pagehead.tpl" ) );
00147         foreach ( $aAllreports as $file ) {
00148             if ( ( $file = trim( $file ) ) ) {
00149                 $sClassName = str_replace( ".php", "", strtolower( $file ) );
00150 
00151                 $oReport = oxNew( $sClassName );
00152                 $oReport->setSmarty( $oSmarty );
00153 
00154                 $oSmarty->assign( "oView", $oReport );
00155                 echo( $oSmarty->fetch( $oReport->render() ) );
00156             }
00157         }
00158 
00159         oxRegistry::getUtils()->showMessageAndExit( $oSmarty->fetch( "report_bottomitem.tpl" ) );
00160     }
00161 }