oxshopviewvalidator.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxShopViewValidator
00009 {
00010 
00011     protected $_aMultiLangTables = array();
00012 
00013     protected $_aMultiShopTables = array();
00014 
00015     protected $_aLanguages = array();
00016 
00017     protected $_aAllShopLanguages = array();
00018 
00019     protected $_iShopId = null;
00020 
00021     protected $_aAllViews = array();
00022 
00023     protected $_aShopViews = array();
00024 
00025     protected $_aValidShopViews = array();
00026 
00032     public function setMultiLangTables($aMultiLangTables)
00033     {
00034         $this->_aMultiLangTables = $aMultiLangTables;
00035     }
00036 
00042     public function getMultiLangTables()
00043     {
00044         return $this->_aMultiLangTables;
00045     }
00046 
00047 
00053     public function setMultiShopTables($aMultiShopTables)
00054     {
00055         $this->_aMultiShopTables = $aMultiShopTables;
00056     }
00057 
00063     public function getMultiShopTables()
00064     {
00065         return $this->_aMultiShopTables;
00066     }
00067 
00073     public function setLanguages($aLanguages)
00074     {
00075         $this->_aLanguages = $aLanguages;
00076     }
00077 
00083     public function getLanguages()
00084     {
00085         return $this->_aLanguages;
00086     }
00087 
00093     public function setAllShopLanguages($aAllShopLanguages)
00094     {
00095         $this->_aAllShopLanguages = $aAllShopLanguages;
00096     }
00097 
00103     public function getAllShopLanguages()
00104     {
00105         return $this->_aAllShopLanguages;
00106     }
00107 
00108 
00114     public function setShopId($iShopId)
00115     {
00116         $this->_iShopId = $iShopId;
00117     }
00118 
00124     public function getShopId()
00125     {
00126         return $this->_iShopId;
00127     }
00128 
00134     protected function _getAllViews()
00135     {
00136         if (empty($this->_aAllViews)) {
00137             $this->_aAllViews = oxDb::getDb()->getCol("SHOW TABLES LIKE  'oxv_%'");
00138         }
00139 
00140         return $this->_aAllViews;
00141     }
00142 
00150     protected function _isCurrentShopView($sViewName)
00151     {
00152         $blResult = false;
00153 
00154         $blEndsWithShopId = preg_match("/[_]([0-9]+)$/", $sViewName, $aMatchEndsWithShopId);
00155         $blContainsShopId = preg_match("/[_]([0-9]+)[_]/", $sViewName, $aMatchContainsShopId);
00156 
00157         if ((!$blEndsWithShopId && !$blContainsShopId) ||
00158             ($blEndsWithShopId && $aMatchEndsWithShopId[1] == $this->getShopId()) ||
00159             ($blContainsShopId && $aMatchContainsShopId[1] == $this->getShopId())
00160         ) {
00161 
00162             $blResult = true;
00163         }
00164 
00165         return $blResult;
00166     }
00167 
00168 
00174     protected function _getShopViews()
00175     {
00176         if (empty($this->_aShopViews)) {
00177 
00178             $this->_aShopViews = array();
00179             $aAllViews = $this->_getAllViews();
00180 
00181             foreach ($aAllViews as $sView) {
00182 
00183                 if ($this->_isCurrentShopView($sView)) {
00184                     $this->_aShopViews[] = $sView;
00185                 }
00186             }
00187         }
00188 
00189         return $this->_aShopViews;
00190     }
00191 
00197     protected function _getValidShopViews()
00198     {
00199         if (empty($this->_aValidShopViews)) {
00200 
00201             $aTables = $this->getMultilangTables();
00202 
00203 
00204             $this->_aValidShopViews = array();
00205 
00206             foreach ($aTables as $sTable) {
00207                 $this->_aValidShopViews[] = 'oxv_' . $sTable;
00208 
00209                 if (in_array($sTable, $this->getMultiLangTables())) {
00210                     foreach ($this->getAllShopLanguages() as $sLang) {
00211                         $this->_aValidShopViews[] = 'oxv_' . $sTable . '_' . $sLang;
00212                     }
00213                 }
00214 
00215             }
00216         }
00217 
00218         return $this->_aValidShopViews;
00219     }
00220 
00228     protected function _isViewValid($sViewName)
00229     {
00230         return in_array($sViewName, $this->_getValidShopViews());
00231     }
00232 
00238     public function getInvalidViews()
00239     {
00240         $aInvalidViews = array();
00241         $aShopViews = $this->_getShopViews();
00242 
00243         foreach ($aShopViews as $sView) {
00244             if (!$this->_isViewValid($sView)) {
00245                 $aInvalidViews[] = $sView;
00246             }
00247         }
00248 
00249         return $aInvalidViews;
00250     }
00251 }