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->getLanguages() 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 
00207 }