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