OXID eShop CE  4.9.7
 All Classes Files Functions Variables Pages
statistic_main.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
18  public function render()
19  {
20  $myConfig = $this->getConfig();
21  $oLang = oxRegistry::getLang();
22 
24 
25  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
26  $aReports = array();
27  if ($soxId != "-1" && isset($soxId)) {
28  // load object
29  $oStat = oxNew("oxstatistic");
30  $oStat->load($soxId);
31 
32  $aReports = $oStat->getReports();
33  $this->_aViewData["edit"] = $oStat;
34  }
35 
36  // setting all reports data: check for reports and load them
37  $sPath = getShopBasePath() . "application/controllers/admin/reports";
38  $iLanguage = (int) oxRegistry::getConfig()->getRequestParameter("editlanguage");
39  $aAllreports = array();
40 
41  $aReportFiles = glob($sPath . "/*.php");
42  foreach ($aReportFiles as $sFile) {
43  if (is_file($sFile) && !is_dir($sFile)) {
44 
45  $sConst = strtoupper(str_replace('.php', '', basename($sFile)));
46 
47  // skipping base report class
48  if ($sConst == 'REPORT_BASE') {
49  continue;
50  }
51 
52  include $sFile;
53 
54  $oItem = new stdClass();
55  $oItem->filename = basename($sFile);
56  $oItem->name = $oLang->translateString($sConst, $iLanguage);
57  $aAllreports[] = $oItem;
58  }
59  }
60 
61  // setting reports data
62  oxRegistry::getSession()->setVariable("allstat_reports", $aAllreports);
63  oxRegistry::getSession()->setVariable("stat_reports_$soxId", $aReports);
64 
65  // passing assigned reports count
66  if (is_array($aReports)) {
67  $this->_aViewData['ireports'] = count($aReports);
68  }
69 
70  if (oxRegistry::getConfig()->getRequestParameter("aoc")) {
71  $oStatisticMainAjax = oxNew('statistic_main_ajax');
72  $this->_aViewData['oxajax'] = $oStatisticMainAjax->getColumns();
73 
74  return "popups/statistic_main.tpl";
75  }
76 
77  return "statistic_main.tpl";
78  }
79 
83  public function save()
84  {
85  $soxId = $this->getEditObjectId();
86  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
87 
88  // shopid
89  $sShopID = oxRegistry::getSession()->getVariable("actshop");
90  $oStat = oxNew("oxstatistic");
91  if ($soxId != "-1") {
92  $oStat->load($soxId);
93  } else {
94  $aParams['oxstatistics__oxid'] = null;
95  }
96 
97  $aParams['oxstatistics__oxshopid'] = $sShopID;
98  $oStat->assign($aParams);
99  $oStat->save();
100 
101  // set oxid if inserted
102  $this->setEditObjectId($oStat->getId());
103  }
104 
108  public function generate()
109  {
110  $myConfig = $this->getConfig();
111 
112  $soxId = $this->getEditObjectId();
113 
114  // load object
115  $oStat = oxNew("oxstatistic");
116  $oStat->load($soxId);
117 
118  $aAllreports = $oStat->getReports();
119 
120  $oShop = oxNew("oxshop");
121  $oShop->load($myConfig->getShopId());
122  $oShop = $this->addGlobalParams($oShop);
123 
124  $sTimeFrom = oxRegistry::getConfig()->getRequestParameter("time_from");
125  $sTimeTo = oxRegistry::getConfig()->getRequestParameter("time_to");
126  if ($sTimeFrom && $sTimeTo) {
127  $sTimeFrom = oxRegistry::get("oxUtilsDate")->formatDBDate($sTimeFrom, true);
128  $sTimeFrom = date("Y-m-d", strtotime($sTimeFrom));
129  $sTimeTo = oxRegistry::get("oxUtilsDate")->formatDBDate($sTimeTo, true);
130  $sTimeTo = date("Y-m-d", strtotime($sTimeTo));
131  } else {
132  $dDays = oxRegistry::getConfig()->getRequestParameter("timeframe");
133  $dNow = time();
134  $sTimeFrom = date("Y-m-d", mktime(0, 0, 0, date("m", $dNow), date("d", $dNow) - $dDays, date("Y", $dNow)));
135  $sTimeTo = date("Y-m-d", time());
136  }
137 
138  $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
139  $oSmarty->assign("time_from", $sTimeFrom . " 23:59:59");
140  $oSmarty->assign("time_to", $sTimeTo . " 23:59:59");
141  $oSmarty->assign("oViewConf", $this->_aViewData["oViewConf"]);
142 
143  echo($oSmarty->fetch("report_pagehead.tpl"));
144  foreach ($aAllreports as $file) {
145  if (($file = trim($file))) {
146  $sClassName = str_replace(".php", "", strtolower($file));
147 
148  $oReport = oxNew($sClassName);
149  $oReport->setSmarty($oSmarty);
150 
151  $oSmarty->assign("oView", $oReport);
152  echo($oSmarty->fetch($oReport->render()));
153  }
154  }
155 
156  oxRegistry::getUtils()->showMessageAndExit($oSmarty->fetch("report_bottomitem.tpl"));
157  }
158 }