statistic_main_ajax.php

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