statistic_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class statistic_main_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00015         array('oxtitle', 'oxstat', 1, 0, 0),
00016         array('oxid', 'oxstat', 0, 0, 1)
00017     ),
00018                                  'container2' => array(
00019                                      array('oxtitle', 'oxstat', 1, 0, 0),
00020                                      array('oxid', 'oxstat', 0, 0, 1)
00021                                  )
00022     );
00023 
00032     protected function _getData($sCountQ, $sQ)
00033     {
00034         $aResponse['startIndex'] = $this->_getStartIndex();
00035         $aResponse['sort'] = '_' . $this->_getSortCol();
00036         $aResponse['dir'] = $this->_getSortDir();
00037 
00038         // all possible reports
00039         $aReports = oxRegistry::getSession()->getVariable("allstat_reports");
00040         $sSynchId = oxRegistry::getConfig()->getRequestParameter("synchoxid");
00041         $sOxId = oxRegistry::getConfig()->getRequestParameter("oxid");
00042 
00043         $sStatId = $sSynchId ? $sSynchId : $sOxId;
00044         $oStat = oxNew('oxstatistic');
00045         $oStat->load($sStatId);
00046         $aStatData = unserialize($oStat->oxstatistics__oxvalue->value);
00047 
00048         $aData = array();
00049         $iCnt = 0;
00050         $oStr = getStr();
00051 
00052         // filter data
00053         $aFilter = oxRegistry::getConfig()->getRequestParameter("aFilter");
00054         $sFilter = (is_array($aFilter) && isset($aFilter['_0'])) ? $oStr->preg_replace('/^\*/', '%', $aFilter['_0']) : null;
00055 
00056         foreach ($aReports as $oReport) {
00057 
00058             if ($sSynchId) {
00059                 if (is_array($aStatData) && in_array($oReport->filename, $aStatData)) {
00060                     continue;
00061                 }
00062             } else {
00063                 if (!is_array($aStatData) || !in_array($oReport->filename, $aStatData)) {
00064                     continue;
00065                 }
00066             }
00067 
00068             // checking filter
00069             if ($sFilter && !$oStr->preg_match("/^" . preg_quote($sFilter) . "/i", $oReport->name)) {
00070                 continue;
00071             }
00072 
00073             $aData[$iCnt]['_0'] = $oReport->name;
00074             $aData[$iCnt]['_1'] = $oReport->filename;
00075             $iCnt++;
00076         }
00077 
00078         // ordering ...
00079         if (oxRegistry::getConfig()->getRequestParameter("dir")) {
00080             if ('asc' == oxRegistry::getConfig()->getRequestParameter("dir")) {
00081                 usort($aData, array($this, "sortAsc"));
00082             } else {
00083                 usort($aData, array($this, "sortDesc"));
00084             }
00085         } else {
00086             usort($aData, array($this, "sortAsc"));
00087         }
00088 
00089         $aResponse['records'] = $aData;
00090         $aResponse['totalRecords'] = count($aReports);
00091 
00092         return $aResponse;
00093 
00094 
00095     }
00096 
00105     public function sortAsc($oOne, $oSec)
00106     {
00107         if ($oOne['_0'] == $oSec['_0']) {
00108             return 0;
00109         }
00110 
00111         return ($oOne['_0'] < $oSec['_0']) ? -1 : 1;
00112     }
00113 
00123     public function sortDesc($oOne, $oSec)
00124     {
00125         if ($oOne['_0'] == $oSec['_0']) {
00126             return 0;
00127         }
00128 
00129         return ($oOne['_0'] > $oSec['_0']) ? -1 : 1;
00130     }
00131 
00132 
00136     public function removeReportFromList()
00137     {
00138         $aReports = oxRegistry::getSession()->getVariable("allstat_reports");
00139         $soxId = oxRegistry::getConfig()->getRequestParameter('oxid');
00140 
00141         // assigning all items
00142         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00143             $aStats = array();
00144             foreach ($aReports as $oRep) {
00145                 $aStats[] = $oRep->filename;
00146             }
00147         } else {
00148             $aStats = $this->_getActionIds('oxstat.oxid');
00149         }
00150 
00151         $oStat = oxNew('oxstatistic');
00152         if (is_array($aStats) && $oStat->load($soxId)) {
00153             $aStatData = $oStat->getReports();
00154 
00155             // additional check
00156             foreach ($aReports as $oRep) {
00157                 if (in_array($oRep->filename, $aStats) && ($iPos = array_search($oRep->filename, $aStatData)) !== false) {
00158                     unset($aStatData[$iPos]);
00159                 }
00160             }
00161 
00162             $oStat->setReports($aStatData);
00163             $oStat->save();
00164         }
00165     }
00166 
00170     public function addReportToList()
00171     {
00172         $aReports = oxRegistry::getSession()->getVariable("allstat_reports");
00173         $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00174 
00175         // assigning all items
00176         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00177             $aStats = array();
00178             foreach ($aReports as $oRep) {
00179                 $aStats[] = $oRep->filename;
00180             }
00181         } else {
00182             $aStats = $this->_getActionIds('oxstat.oxid');
00183         }
00184 
00185         $oStat = oxNew('oxstatistic');
00186         if ($oStat->load($soxId)) {
00187             $aStatData = (array) $oStat->getReports();
00188 
00189 
00190             // additional check
00191             foreach ($aReports as $oRep) {
00192                 if (in_array($oRep->filename, $aStats) && !in_array($oRep->filename, $aStatData)) {
00193                     $aStatData[] = $oRep->filename;
00194                 }
00195             }
00196 
00197             $oStat->setReports($aStatData);
00198             $oStat->save();
00199         }
00200     }
00201 }