statistic_main.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Statistic_Main extends oxAdminDetails
00009 {
00010 
00018     public function render()
00019     {
00020         $myConfig = $this->getConfig();
00021         $oLang = oxRegistry::getLang();
00022 
00023         parent::render();
00024 
00025         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00026         $aReports = array();
00027         if ($soxId != "-1" && isset($soxId)) {
00028             // load object
00029             $oStat = oxNew("oxstatistic");
00030             $oStat->load($soxId);
00031 
00032             $aReports = $oStat->getReports();
00033             $this->_aViewData["edit"] = $oStat;
00034         }
00035 
00036         // setting all reports data: check for reports and load them
00037         $sPath = getShopBasePath() . "application/controllers/admin/reports";
00038         $iLanguage = (int) oxRegistry::getConfig()->getRequestParameter("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         oxRegistry::getSession()->setVariable("allstat_reports", $aAllreports);
00063         oxRegistry::getSession()->setVariable("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 (oxRegistry::getConfig()->getRequestParameter("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 
00083     public function save()
00084     {
00085         $soxId = $this->getEditObjectId();
00086         $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00087 
00088         // shopid
00089         $sShopID = oxRegistry::getSession()->getVariable("actshop");
00090         $oStat = oxNew("oxstatistic");
00091         if ($soxId != "-1") {
00092             $oStat->load($soxId);
00093         } else {
00094             $aParams['oxstatistics__oxid'] = null;
00095         }
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 
00108     public function generate()
00109     {
00110         $myConfig = $this->getConfig();
00111 
00112         $soxId = $this->getEditObjectId();
00113 
00114         // load object
00115         $oStat = oxNew("oxstatistic");
00116         $oStat->load($soxId);
00117 
00118         $aAllreports = $oStat->getReports();
00119 
00120         $oShop = oxNew("oxshop");
00121         $oShop->load($myConfig->getShopId());
00122         $oShop = $this->addGlobalParams($oShop);
00123 
00124         $sTimeFrom = oxRegistry::getConfig()->getRequestParameter("time_from");
00125         $sTimeTo = oxRegistry::getConfig()->getRequestParameter("time_to");
00126         if ($sTimeFrom && $sTimeTo) {
00127             $sTimeFrom = oxRegistry::get("oxUtilsDate")->formatDBDate($sTimeFrom, true);
00128             $sTimeFrom = date("Y-m-d", strtotime($sTimeFrom));
00129             $sTimeTo = oxRegistry::get("oxUtilsDate")->formatDBDate($sTimeTo, true);
00130             $sTimeTo = date("Y-m-d", strtotime($sTimeTo));
00131         } else {
00132             $dDays = oxRegistry::getConfig()->getRequestParameter("timeframe");
00133             $dNow = time();
00134             $sTimeFrom = date("Y-m-d", mktime(0, 0, 0, date("m", $dNow), date("d", $dNow) - $dDays, date("Y", $dNow)));
00135             $sTimeTo = date("Y-m-d", time());
00136         }
00137 
00138         $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
00139         $oSmarty->assign("time_from", $sTimeFrom . " 23:59:59");
00140         $oSmarty->assign("time_to", $sTimeTo . " 23:59:59");
00141         $oSmarty->assign("oViewConf", $this->_aViewData["oViewConf"]);
00142 
00143         echo($oSmarty->fetch("report_pagehead.tpl"));
00144         foreach ($aAllreports as $file) {
00145             if (($file = trim($file))) {
00146                 $sClassName = str_replace(".php", "", strtolower($file));
00147 
00148                 $oReport = oxNew($sClassName);
00149                 $oReport->setSmarty($oSmarty);
00150 
00151                 $oSmarty->assign("oView", $oReport);
00152                 echo($oSmarty->fetch($oReport->render()));
00153             }
00154         }
00155 
00156         oxRegistry::getUtils()->showMessageAndExit($oSmarty->fetch("report_bottomitem.tpl"));
00157     }
00158 }