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 
00043         // filter data
00044         $aFilter = oxConfig::getParameter( "aFilter" );
00045         $sFilter = (is_array( $aFilter ) && isset( $aFilter['_0'] ) )? preg_replace( '/^\*/', '%', $aFilter['_0'] ) : null;
00046 
00047         foreach ( $aReports as $oReport ) {
00048 
00049             if ( $sSynchId ) {
00050                 if ( is_array($aStatData) && in_array( $oReport->filename, $aStatData ) )
00051                     continue;
00052             } else {
00053                 if ( !is_array( $aStatData ) ||  !in_array( $oReport->filename, $aStatData ) )
00054                     continue;
00055             }
00056 
00057             // checking filter
00058             if ( $sFilter && !preg_match( "/^" . preg_quote( $sFilter ) . "/i", $oReport->name) ) {
00059                 continue;
00060             }
00061 
00062             $aData[$iCnt]['_0'] = $oReport->name;
00063             $aData[$iCnt]['_1'] = $oReport->filename;
00064             $iCnt++;
00065         }
00066 
00067         // ordering ...
00068         if ( oxConfig::getParameter( "dir" ) ) {
00069             if ( 'asc' == oxConfig::getParameter( "dir" ) )
00070                 usort( $aData, array( $this, "sortAsc" ) );
00071             else
00072                 usort( $aData, array( $this, "sortDesc" ) );
00073         } else {
00074             usort( $aData, array( $this, "sortAsc" ) );
00075         }
00076 
00077         $aResponse['records'] = $aData;
00078         $aResponse['totalRecords'] = count( $aReports );
00079 
00080         return $aResponse;
00081 
00082 
00083     }
00084 
00093     public function sortAsc( $oOne, $oSec )
00094     {
00095         if ( $oOne['_0'] == $oSec['_0'] ) {
00096             return 0;
00097         }
00098         return ( $oOne['_0'] < $oSec['_0'] ) ? -1 : 1;
00099     }
00100 
00110     public function sortDesc( $oOne, $oSec )
00111     {
00112         if ( $oOne['_0'] == $oSec['_0'] ) {
00113             return 0;
00114         }
00115         return ( $oOne['_0'] > $oSec['_0'] ) ? -1 : 1;
00116     }
00117 
00118 
00124     public function removereportfromlist()
00125     {
00126         $aReports = oxSession::getVar( "allstat_reports" );
00127         $soxId    = oxConfig::getParameter( 'oxid');
00128 
00129         // assigning all items
00130         if ( oxConfig::getParameter( 'all' ) ) {
00131             $aStats = array();
00132             foreach ( $aReports as $oRep ) {
00133                 $aStats[] = $oRep->filename;
00134             }
00135         } else {
00136             $aStats = $this->_getActionIds( 'oxstat.oxid' );
00137         }
00138 
00139         $oStat = oxNew( 'oxstatistic' );
00140         if ( is_array( $aStats ) && $oStat->load( $soxId ) ) {
00141             $aStatData = $oStat->getReports();
00142 
00143             // additional check
00144             foreach ( $aReports as $oRep ) {
00145                 if ( in_array( $oRep->filename, $aStats ) && ($iPos = array_search( $oRep->filename, $aStatData ) ) !== false )
00146                     unset( $aStatData[$iPos] );
00147             }
00148 
00149             $oStat->setReports( $aStatData );
00150             $oStat->save();
00151         }
00152     }
00153 
00159     public function addreporttolist()
00160     {
00161         $aReports = oxSession::getVar( "allstat_reports" );
00162         $soxId    = oxConfig::getParameter( 'synchoxid' );
00163 
00164         // assigning all items
00165         if ( oxConfig::getParameter( 'all' ) ) {
00166             $aStats = array();
00167             foreach ( $aReports as $oRep ) {
00168                 $aStats[] = $oRep->filename;
00169             }
00170         } else {
00171             $aStats = $this->_getActionIds( 'oxstat.oxid' );
00172         }
00173 
00174         $oStat = oxNew( 'oxstatistic' );
00175         if ( $oStat->load( $soxId ) ) {
00176             $aStatData = (array) $oStat->getReports();
00177 
00178 
00179             // additional check
00180             foreach ( $aReports as $oRep ) {
00181                 if ( in_array( $oRep->filename, $aStats ) && !in_array( $oRep->filename, $aStatData ) )
00182                     $aStatData[] = $oRep->filename;
00183             }
00184 
00185             $oStat->setReports( $aStatData );
00186             $oStat->save();
00187         }
00188     }
00189 }

Generated by  doxygen 1.6.2