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