OXID eShop CE  4.10.0
 All Classes Namespaces Files Functions Variables Pages
statistic_main_ajax.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
16  protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
17  array('oxtitle', 'oxstat', 1, 0, 0),
18  array('oxid', 'oxstat', 0, 0, 1)
19  ),
20  'container2' => array(
21  array('oxtitle', 'oxstat', 1, 0, 0),
22  array('oxid', 'oxstat', 0, 0, 1)
23  )
24  );
25 
34  protected function _getData($sCountQ, $sQ)
35  {
36  $aResponse['startIndex'] = $this->_getStartIndex();
37  $aResponse['sort'] = '_' . $this->_getSortCol();
38  $aResponse['dir'] = $this->_getSortDir();
39 
40  // all possible reports
41  $aReports = oxRegistry::getSession()->getVariable("allstat_reports");
42  $sSynchId = oxRegistry::getConfig()->getRequestParameter("synchoxid");
43  $sOxId = oxRegistry::getConfig()->getRequestParameter("oxid");
44 
45  $sStatId = $sSynchId ? $sSynchId : $sOxId;
46  $oStat = oxNew('oxstatistic');
47  $oStat->load($sStatId);
48  $aStatData = unserialize($oStat->oxstatistics__oxvalue->value);
49 
50  $aData = array();
51  $iCnt = 0;
52  $oStr = getStr();
53 
54  // filter data
55  $aFilter = oxRegistry::getConfig()->getRequestParameter("aFilter");
56  $sFilter = (is_array($aFilter) && isset($aFilter['_0'])) ? $oStr->preg_replace('/^\*/', '%', $aFilter['_0']) : null;
57 
58  foreach ($aReports as $oReport) {
59 
60  if ($sSynchId) {
61  if (is_array($aStatData) && in_array($oReport->filename, $aStatData)) {
62  continue;
63  }
64  } else {
65  if (!is_array($aStatData) || !in_array($oReport->filename, $aStatData)) {
66  continue;
67  }
68  }
69 
70  // checking filter
71  if ($sFilter && !$oStr->preg_match("/^" . preg_quote($sFilter) . "/i", $oReport->name)) {
72  continue;
73  }
74 
75  $aData[$iCnt]['_0'] = $oReport->name;
76  $aData[$iCnt]['_1'] = $oReport->filename;
77  $iCnt++;
78  }
79 
80  // ordering ...
81  if (oxRegistry::getConfig()->getRequestParameter("dir")) {
82  if ('asc' == oxRegistry::getConfig()->getRequestParameter("dir")) {
83  usort($aData, array($this, "sortAsc"));
84  } else {
85  usort($aData, array($this, "sortDesc"));
86  }
87  } else {
88  usort($aData, array($this, "sortAsc"));
89  }
90 
91  $aResponse['records'] = $aData;
92  $aResponse['totalRecords'] = count($aReports);
93 
94  return $aResponse;
95 
96 
97  }
98 
107  public function sortAsc($oOne, $oSec)
108  {
109  if ($oOne['_0'] == $oSec['_0']) {
110  return 0;
111  }
112 
113  return ($oOne['_0'] < $oSec['_0']) ? -1 : 1;
114  }
115 
125  public function sortDesc($oOne, $oSec)
126  {
127  if ($oOne['_0'] == $oSec['_0']) {
128  return 0;
129  }
130 
131  return ($oOne['_0'] > $oSec['_0']) ? -1 : 1;
132  }
133 
134 
138  public function removeReportFromList()
139  {
140  $aReports = oxRegistry::getSession()->getVariable("allstat_reports");
141  $soxId = oxRegistry::getConfig()->getRequestParameter('oxid');
142 
143  // assigning all items
144  if (oxRegistry::getConfig()->getRequestParameter('all')) {
145  $aStats = array();
146  foreach ($aReports as $oRep) {
147  $aStats[] = $oRep->filename;
148  }
149  } else {
150  $aStats = $this->_getActionIds('oxstat.oxid');
151  }
152 
153  $oStat = oxNew('oxstatistic');
154  if (is_array($aStats) && $oStat->load($soxId)) {
155  $aStatData = $oStat->getReports();
156 
157  // additional check
158  foreach ($aReports as $oRep) {
159  if (in_array($oRep->filename, $aStats) && ($iPos = array_search($oRep->filename, $aStatData)) !== false) {
160  unset($aStatData[$iPos]);
161  }
162  }
163 
164  $oStat->setReports($aStatData);
165  $oStat->save();
166  }
167  }
168 
172  public function addReportToList()
173  {
174  $aReports = oxRegistry::getSession()->getVariable("allstat_reports");
175  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
176 
177  // assigning all items
178  if (oxRegistry::getConfig()->getRequestParameter('all')) {
179  $aStats = array();
180  foreach ($aReports as $oRep) {
181  $aStats[] = $oRep->filename;
182  }
183  } else {
184  $aStats = $this->_getActionIds('oxstat.oxid');
185  }
186 
187  $oStat = oxNew('oxstatistic');
188  if ($oStat->load($soxId)) {
189  $aStatData = (array) $oStat->getReports();
190 
191 
192  // additional check
193  foreach ($aReports as $oRep) {
194  if (in_array($oRep->filename, $aStats) && !in_array($oRep->filename, $aStatData)) {
195  $aStatData[] = $oRep->filename;
196  }
197  }
198 
199  $oStat->setReports($aStatData);
200  $oStat->save();
201  }
202  }
203 }