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 $_aAllShopLanguages = array();
00017 
00018     protected $_iShopId = null;
00019 
00020     protected $_aAllViews = array();
00021 
00022     protected $_aShopViews = array();
00023 
00024     protected $_aValidShopViews = array();
00025 
00029     public function setMultiLangTables( $aMultiLangTables )
00030     {
00031         $this->_aMultiLangTables = $aMultiLangTables;
00032     }
00033 
00038     public function getMultiLangTables()
00039     {
00040         return $this->_aMultiLangTables;
00041     }
00042 
00043 
00047     public function setMultiShopTables( $aMultiShopTables )
00048     {
00049         $this->_aMultiShopTables = $aMultiShopTables;
00050     }
00051 
00056     public function getMultiShopTables()
00057     {
00058         return $this->_aMultiShopTables;
00059     }
00060 
00065     public function setLanguages( $aLanguages )
00066     {
00067         $this->_aLanguages = $aLanguages;
00068     }
00069 
00073     public function getLanguages()
00074     {
00075         return $this->_aLanguages;
00076     }
00077 
00082     public function setAllShopLanguages( $aAllShopLanguages )
00083     {
00084         $this->_aAllShopLanguages = $aAllShopLanguages;
00085     }
00086 
00090     public function getAllShopLanguages()
00091     {
00092         return $this->_aAllShopLanguages;
00093     }
00094 
00095 
00099     public function setShopId( $iShopId )
00100     {
00101         $this->_iShopId = $iShopId;
00102     }
00103 
00108     public function getShopId()
00109     {
00110         return $this->_iShopId;
00111     }
00112 
00117     protected function _getAllViews()
00118     {
00119         if ( empty( $this->_aAllViews ) ) {
00120             $this->_aAllViews = oxDb::getDb()->getCol( "SHOW TABLES LIKE  'oxv_%'" );
00121         }
00122 
00123         return  $this->_aAllViews;
00124     }
00125 
00131     protected function _isCurrentShopView( $sViewName )
00132     {
00133         $blResult = false;
00134 
00135         $blEndsWithShopId = preg_match( "/[_]([0-9]+)$/",$sViewName, $aMatchEndsWithShopId );
00136         $blContainsShopId = preg_match( "/[_]([0-9]+)[_]/",$sViewName, $aMatchContainsShopId );
00137 
00138         if ( ( !$blEndsWithShopId && !$blContainsShopId ) ||
00139              ( $blEndsWithShopId && $aMatchEndsWithShopId[1] == $this->getShopId() ) ||
00140              ( $blContainsShopId && $aMatchContainsShopId[1] == $this->getShopId() ) ) {
00141 
00142             $blResult = true;
00143         }
00144 
00145         return $blResult;
00146     }
00147 
00148 
00153     protected function _getShopViews()
00154     {
00155         if ( empty( $this->_aShopViews ) ) {
00156 
00157             $this->_aShopViews = array();
00158             $aAllViews = $this->_getAllViews();
00159 
00160             foreach ( $aAllViews as $sView ) {
00161 
00162                 if ( $this->_isCurrentShopView( $sView ) ){
00163                     $this->_aShopViews[] = $sView;
00164                 }
00165             }
00166         }
00167 
00168         return $this->_aShopViews;
00169     }
00170 
00175     protected function _getValidShopViews()
00176     {
00177         if ( empty( $this->_aValidShopViews ) ) {
00178 
00179             $aTables = $this->getMultilangTables();
00180 
00181 
00182             $this->_aValidShopViews = array();
00183 
00184             foreach ( $aTables as $sTable ) {
00185                 $this->_aValidShopViews[] = 'oxv_'.$sTable;;
00186 
00187                 if ( in_array( $sTable, $this->getMultiLangTables() ) ) {
00188                     foreach ( $this->getAllShopLanguages() as $sLang ) {
00189                         $this->_aValidShopViews[] ='oxv_'.$sTable.'_'.$sLang;
00190                     }
00191                 }
00192 
00193             }
00194         }
00195 
00196         return $this->_aValidShopViews;
00197     }
00198 
00204     protected function _isViewValid( $sViewName ){
00205         return in_array( $sViewName, $this->_getValidShopViews() );
00206     }
00207 
00212     public function getInvalidViews()
00213     {
00214         $aInvalidViews = array();
00215         $aShopViews = $this->_getShopViews();
00216 
00217         foreach ( $aShopViews as $sView ) {
00218             if ( !$this->_isViewValid( $sView ) ){
00219                 $aInvalidViews[] = $sView;
00220             }
00221         }
00222 
00223         return $aInvalidViews;
00224     }
00225 
00226 }