oxshopviewvalidator.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxShopViewValidator {
00009 
00010     protected $_aMultiLangTables = array();
00011 
00012     protected $_aMultiShopTables = array();
00013 
00014     protected $_aLanguages = array();
00015 
00016     protected $_iShopId = null;
00017 
00018     protected $_aAllViews = array();
00019 
00020     protected $_aShopViews = array();
00021 
00022     protected $_aValidShopViews = array();
00023 
00027     public function setMultiLangTables( $aMultiLangTables )
00028     {
00029         $this->_aMultiLangTables = $aMultiLangTables;
00030     }
00031 
00036     public function getMultiLangTables()
00037     {
00038         return $this->_aMultiLangTables;
00039     }
00040 
00041 
00045     public function setMultiShopTables( $aMultiShopTables )
00046     {
00047         $this->_aMultiShopTables = $aMultiShopTables;
00048     }
00049 
00054     public function getMultiShopTables()
00055     {
00056         return $this->_aMultiShopTables;
00057     }
00058 
00063     public function setLanguages( $aLanguages )
00064     {
00065         $this->_aLanguages = $aLanguages;
00066     }
00067 
00071     public function getLanguages()
00072     {
00073         return $this->_aLanguages;
00074     }
00075 
00076 
00080     public function setShopId( $iShopId )
00081     {
00082         $this->_iShopId = $iShopId;
00083     }
00084 
00089     public function getShopId()
00090     {
00091         return $this->_iShopId;
00092     }
00093 
00098     protected function _getAllViews()
00099     {
00100         if ( empty( $this->_aAllViews ) ) {
00101             $this->_aAllViews = oxDb::getDb()->getCol( "SHOW TABLES LIKE  'oxv_%'" );
00102         }
00103 
00104         return  $this->_aAllViews;
00105     }
00106 
00112     protected function _isCurrentShopView( $sViewName )
00113     {
00114         $blResult = false;
00115 
00116         $blEndsWithShopId = preg_match( "/[_]([0-9]+)$/",$sViewName, $aMatchEndsWithShopId );
00117         $blContainsShopId = preg_match( "/[_]([0-9]+)[_]/",$sViewName, $aMatchContainsShopId );
00118 
00119         if ( ( !$blEndsWithShopId && !$blContainsShopId ) ||
00120              ( $blEndsWithShopId && $aMatchEndsWithShopId[1] == $this->getShopId() ) ||
00121              ( $blContainsShopId && $aMatchContainsShopId[1] == $this->getShopId() ) ) {
00122 
00123             $blResult = true;
00124         }
00125 
00126         return $blResult;
00127     }
00128 
00129 
00134     protected function _getShopViews()
00135     {
00136         if ( empty( $this->_aShopViews ) ) {
00137 
00138             $this->_aShopViews = array();
00139             $aAllViews = $this->_getAllViews();
00140 
00141             foreach ( $aAllViews as $sView ) {
00142 
00143                 if ( $this->_isCurrentShopView( $sView ) ){
00144                     $this->_aShopViews[] = $sView;
00145                 }
00146             }
00147         }
00148 
00149         return $this->_aShopViews;
00150     }
00151 
00156     protected function _getValidShopViews()
00157     {
00158         if ( empty( $this->_aValidShopViews ) ) {
00159 
00160             $aTables = $this->getMultilangTables();
00161 
00162 
00163             $this->_aValidShopViews = array();
00164 
00165             foreach ( $aTables as $sTable ) {
00166                 $this->_aValidShopViews[] = 'oxv_'.$sTable;;
00167 
00168                 if ( in_array( $sTable, $this->getMultiLangTables() ) ) {
00169                     foreach ( $this->_getAllShopLanguageIds() as $sLang ) {
00170                         $this->_aValidShopViews[] ='oxv_'.$sTable.'_'.$sLang;
00171                     }
00172                 }
00173 
00174             }
00175         }
00176 
00177         return $this->_aValidShopViews;
00178     }
00179 
00185     protected function _isViewValid( $sViewName ){
00186         return in_array( $sViewName, $this->_getValidShopViews() );
00187     }
00188 
00193     public function getInvalidViews()
00194     {
00195         $aInvalidViews = array();
00196         $aShopViews = $this->_getShopViews();
00197 
00198         foreach ( $aShopViews as $sView ) {
00199             if ( !$this->_isViewValid( $sView ) ){
00200                 $aInvalidViews[] = $sView;
00201             }
00202         }
00203 
00204         return $aInvalidViews;
00205     }
00206 
00212     private function _getAllShopLanguageIds()
00213     {
00214             $aLanguages = oxRegistry::getLang()->getLanguageIds();
00215 
00216         return $aLanguages;
00217     }
00218 
00226     private function _getAllLanguageParamValues( $sParamName )
00227     {
00228         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
00229         $oConfig = oxRegistry::getConfig();
00230 
00231         $sQuery = "
00232             select ".$oConfig->getDecodeValueQuery()." as oxvarvalue
00233             from oxconfig
00234             where oxvarname = '{$sParamName}' ";
00235 
00236         return $oDb->getArray( $sQuery );
00237     }
00238 
00244     private function _getConfigLanguageParamValues()
00245     {
00246         $aConfigValues = $this->_getAllLanguageParamValues( 'aLanguageParams' );
00247         $aConfigDecodedValues = array();
00248 
00249         foreach ( $aConfigValues as $sConfigValue )
00250         {
00251             $aConfigLanguageParams = unserialize( $sConfigValue['oxvarvalue'] );
00252             $aLanguages = $this->_processLanguageParamsArray( $aConfigLanguageParams );
00253 
00254             $aConfigDecodedValues = array_unique( array_merge( $aConfigDecodedValues, $aLanguages ) );
00255         }
00256 
00257         return $aConfigDecodedValues;
00258     }
00259 
00267     private function _processLanguageParamsArray( $aLanguageParams )
00268     {
00269         $aLanguages = array();
00270         foreach ( $aLanguageParams as $sAbbr => $aValue ) {
00271             $iBaseId = (int) $aValue[ 'baseId' ];
00272             $aLanguages[ $iBaseId ] = $sAbbr;
00273         }
00274 
00275         return $aLanguages;
00276     }
00277 
00278 
00284     private function _getConfigLanguageValues()
00285     {
00286         $aConfigValues = $this->_getAllLanguageParamValues( 'aLanguages' );
00287         $aConfigDecodedValues = array();
00288 
00289         foreach ( $aConfigValues as $sConfigValue )
00290         {
00291             $aConfigLanguages = unserialize( $sConfigValue['oxvarvalue'] );
00292 
00293             $aLanguages = array_keys( $aConfigLanguages );
00294 
00295             $aConfigDecodedValues = array_unique( array_merge( $aConfigDecodedValues, $aLanguages ) );
00296         }
00297 
00298         return $aConfigDecodedValues;
00299     }
00300 
00301 
00302 }