statistic_main.inc.php

Go to the documentation of this file.
00001 <?php
00002 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00003                                         array( 'oxtitle', 'oxstat', 1, 0, 0 ),
00004                                         array( 'oxid',    'oxstat', 0, 0, 1 )
00005                                         ),
00006                      'container2' => array(
00007                                         array( 'oxtitle',  'oxstat', 1, 0, 0 ),
00008                                         array( 'oxid',    'oxstat', 0, 0, 1 )
00009                                         )
00010                     );
00014 class ajaxComponent extends ajaxListComponent
00015 {
00024     protected function _getData( $sCountQ, $sQ )
00025     {
00026         $aResponse['startIndex'] = $this->_getStartIndex();
00027         $aResponse['sort'] = '_' . $this->_getSortCol();
00028         $aResponse['dir']  = $this->_getSortDir();
00029 
00030         // all possible reports
00031         $aReports = oxSession::getVar( "allstat_reports" );
00032         $sSynchId = oxConfig::getParameter( "synchoxid" );
00033         $sOxId    = oxConfig::getParameter( "oxid" );
00034 
00035         $sStatId = $sSynchId?$sSynchId:$sOxId;
00036         $oStat = oxNew( 'oxstatistic' );
00037         $oStat->load( $sStatId );
00038         $aStatData = unserialize( $oStat->oxstatistics__oxvalue->value );
00039 
00040         $aData = array();
00041         $iCnt = 0;
00042         $oStr = getStr();
00043 
00044         // filter data
00045         $aFilter = oxConfig::getParameter( "aFilter" );
00046         $sFilter = (is_array( $aFilter ) && isset( $aFilter['_0'] ) )? $oStr->preg_replace( '/^\*/', '%', $aFilter['_0'] ) : null;
00047 
00048         foreach ( $aReports as $oReport ) {
00049 
00050             if ( $sSynchId ) {
00051                 if ( is_array($aStatData) && in_array( $oReport->filename, $aStatData ) )
00052                     continue;
00053             } else {
00054                 if ( !is_array( $aStatData ) ||  !in_array( $oReport->filename, $aStatData ) )
00055                     continue;
00056             }
00057 
00058             // checking filter
00059             if ( $sFilter && !$oStr->preg_match( "/^" . preg_quote( $sFilter ) . "/i", $oReport->name) ) {
00060                 continue;
00061             }
00062 
00063             $aData[$iCnt]['_0'] = $oReport->name;
00064             $aData[$iCnt]['_1'] = $oReport->filename;
00065             $iCnt++;
00066         }
00067 
00068         // ordering ...
00069         if ( oxConfig::getParameter( "dir" ) ) {
00070             if ( 'asc' == oxConfig::getParameter( "dir" ) )
00071                 usort( $aData, array( $this, "sortAsc" ) );
00072             else
00073                 usort( $aData, array( $this, "sortDesc" ) );
00074         } else {
00075             usort( $aData, array( $this, "sortAsc" ) );
00076         }
00077 
00078         $aResponse['records'] = $aData;
00079         $aResponse['totalRecords'] = count( $aReports );
00080 
00081         return $aResponse;
00082 
00083 
00084     }
00085 
00094     public function sortAsc( $oOne, $oSec )
00095     {
00096         if ( $oOne['_0'] == $oSec['_0'] ) {
00097             return 0;
00098         }
00099         return ( $oOne['_0'] < $oSec['_0'] ) ? -1 : 1;
00100     }
00101 
00111     public function sortDesc( $oOne, $oSec )
00112     {
00113         if ( $oOne['_0'] == $oSec['_0'] ) {
00114             return 0;
00115         }
00116         return ( $oOne['_0'] > $oSec['_0'] ) ? -1 : 1;
00117     }
00118 
00119 
00125     public function removereportfromlist()
00126     {
00127         $aReports = oxSession::getVar( "allstat_reports" );
00128         $soxId    = oxConfig::getParameter( 'oxid');
00129 
00130         // assigning all items
00131         if ( oxConfig::getParameter( 'all' ) ) {
00132             $aStats = array();
00133             foreach ( $aReports as $oRep ) {
00134                 $aStats[] = $oRep->filename;
00135             }
00136         } else {
00137             $aStats = $this->_getActionIds( 'oxstat.oxid' );
00138         }
00139 
00140         $oStat = oxNew( 'oxstatistic' );
00141         if ( is_array( $aStats ) && $oStat->load( $soxId ) ) {
00142             $aStatData = $oStat->getReports();
00143 
00144             // additional check
00145             foreach ( $aReports as $oRep ) {
00146                 if ( in_array( $oRep->filename, $aStats ) && ($iPos = array_search( $oRep->filename, $aStatData ) ) !== false )
00147                     unset( $aStatData[$iPos] );
00148             }
00149 
00150             $oStat->setReports( $aStatData );
00151             $oStat->save();
00152         }
00153     }
00154 
00160     public function addreporttolist()
00161     {
00162         $aReports = oxSession::getVar( "allstat_reports" );
00163         $soxId    = oxConfig::getParameter( 'synchoxid' );
00164 
00165         // assigning all items
00166         if ( oxConfig::getParameter( 'all' ) ) {
00167             $aStats = array();
00168             foreach ( $aReports as $oRep ) {
00169                 $aStats[] = $oRep->filename;
00170             }
00171         } else {
00172             $aStats = $this->_getActionIds( 'oxstat.oxid' );
00173         }
00174 
00175         $oStat = oxNew( 'oxstatistic' );
00176         if ( $oStat->load( $soxId ) ) {
00177             $aStatData = (array) $oStat->getReports();
00178 
00179 
00180             // additional check
00181             foreach ( $aReports as $oRep ) {
00182                 if ( in_array( $oRep->filename, $aStats ) && !in_array( $oRep->filename, $aStatData ) )
00183                     $aStatData[] = $oRep->filename;
00184             }
00185 
00186             $oStat->setReports( $aStatData );
00187             $oStat->save();
00188         }
00189     }
00190 }