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