OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
statistic_main.php
Go to the documentation of this file.
1 <?php
2 
9 {
17  public function render()
18  {
19  $myConfig = $this->getConfig();
20  $oLang = oxRegistry::getLang();
21 
23 
24  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
25  $aReports = array();
26  if ( $soxId != "-1" && isset( $soxId)) {
27  // load object
28  $oStat = oxNew( "oxstatistic" );
29  $oStat->load( $soxId);
30 
31  $aReports = $oStat->getReports();
32  $this->_aViewData["edit"] = $oStat;
33  }
34 
35  // setting all reports data: check for reports and load them
36  $sPath = getShopBasePath(). "application/controllers/admin/reports";
37  $iLanguage = (int) oxConfig::getParameter("editlanguage");
38  $aAllreports = array();
39 
40  $aReportFiles = glob( $sPath."/*.php" );
41  foreach ( $aReportFiles as $sFile ) {
42  if ( is_file( $sFile ) && !is_dir( $sFile ) ) {
43 
44  $sConst = strtoupper( str_replace( '.php', '', basename( $sFile ) ) );
45 
46  // skipping base report class
47  if ( $sConst == 'REPORT_BASE') {
48  continue;
49  }
50 
51  include $sFile;
52 
53  $oItem = new stdClass();
54  $oItem->filename = basename( $sFile );
55  $oItem->name = $oLang->translateString( $sConst, $iLanguage );
56  $aAllreports[] = $oItem;
57  }
58  }
59 
60  // setting reports data
61  oxSession::setVar( "allstat_reports", $aAllreports);
62  oxSession::setVar( "stat_reports_$soxId", $aReports);
63 
64  // passing assigned reports count
65  if ( is_array($aReports) ) {
66  $this->_aViewData['ireports'] = count($aReports);
67  }
68 
69  if ( oxConfig::getParameter("aoc") ) {
70  $oStatisticMainAjax = oxNew( 'statistic_main_ajax' );
71  $this->_aViewData['oxajax'] = $oStatisticMainAjax->getColumns();
72 
73  return "popups/statistic_main.tpl";
74  }
75 
76  return "statistic_main.tpl";
77  }
78 
84  public function save()
85  {
86  $soxId = $this->getEditObjectId();
87  $aParams = oxConfig::getParameter( "editval");
88 
89  // shopid
90  $sShopID = oxSession::getVar( "actshop");
91  $oStat = oxNew( "oxstatistic" );
92  if ( $soxId != "-1")
93  $oStat->load( $soxId);
94  else
95  $aParams['oxstatistics__oxid'] = null;
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 
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 = oxConfig::getParameter( "time_from" );
127  $sTimeTo = oxConfig::getParameter( "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 = oxConfig::getParameter( "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 }