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