oxshop.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxShop extends oxI18n
00009 {
00015     protected $_sClassName = 'oxshop';
00016 
00022     protected $_aMultiShopTables = array();
00023 
00024 
00028     public function __construct()
00029     {
00030         parent::__construct();
00031 
00032 
00033         $this->init( 'oxshops' );
00034 
00035         if ( $iMax = $this->getConfig()->getConfigParam('iMaxShopId') ) {
00036             $this->setMaxShopId( $iMax );
00037         }
00038 
00039     }
00040 
00048     public function setMultiShopTables( $aMultiShopTables )
00049     {
00050         $this->_aMultiShopTables = $aMultiShopTables;
00051     }
00052 
00053 
00062     public function generateViews( $blMultishopInheritCategories = false, $aMallInherit = null )
00063     {
00064         $oDb        = oxDb::getDb();
00065         $aLanguages = oxRegistry::getLang()->getLanguageIds();
00066 
00067         $aTables = $aMultilangTables = oxRegistry::getLang()->getMultiLangTables();
00068 
00069         $aQ = array();
00070 
00071         // Generate multitable views
00072         foreach ( $aTables as $sTable ) {
00073             $aQ[] = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW oxv_'.$sTable.' AS SELECT * FROM '.$sTable.' '.$this->_getViewJoinAll($sTable);
00074 
00075             if (in_array($sTable, $aMultilangTables)) {
00076                 foreach ($aLanguages as $iLang => $sLang) {
00077                     $aQ[] = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW oxv_'.$sTable.'_'.$sLang.' AS SELECT '.$this->_getViewSelect($sTable, $iLang).' FROM '.$sTable.' '.$this->_getViewJoinLang($sTable, $iLang);
00078                 }
00079             }
00080         }
00081 
00082         $bSuccess = true;
00083         foreach ($aQ as $sQ) {
00084             if ( !$oDb->execute( $sQ ) ) {
00085                 $bSuccess = false;
00086             }
00087         }
00088 
00089         $oViewsValidator = oxNew( 'oxShopViewValidator' );
00090 
00091         $oViewsValidator->setShopId( $this->getConfig()->getShopId() );
00092         $oViewsValidator->setLanguages( $aLanguages );
00093         $oViewsValidator->setMultiLangTables( $aMultilangTables );
00094         $oViewsValidator->setMultiShopTables( $aMultishopTables );
00095 
00096         $aViews = $oViewsValidator->getInvalidViews();
00097 
00098         foreach ($aViews as $sView) {
00099             $oDb->execute( 'DROP VIEW IF EXISTS '. $sView );
00100         }
00101 
00102         return $bSuccess;
00103     }
00104 
00113     protected function _getViewSelect($sTable,$iLang)
00114     {
00115         $oMetaData = oxNew('oxDbMetaDataHandler');
00116         $aFields = $oMetaData->getSinglelangFields($sTable, $iLang);
00117         foreach ($aFields as $sCoreField => $sField) {
00118             if ($sCoreField !== $sField) {
00119                 $aFields[$sCoreField] = $sField.' AS '.$sCoreField;
00120             }
00121         }
00122 
00123         return implode(',', $aFields);
00124     }
00125 
00133     protected function _getViewJoinAll($sTable)
00134     {
00135         $sJoin = ' ';
00136         $oMetaData = oxNew('oxDbMetaDataHandler');
00137         $aTables = $oMetaData->getAllMultiTables($sTable);
00138         if (count($aTables)) {
00139             foreach ($aTables as $sTableKey => $sTableName) {
00140                 $sJoin .= "LEFT JOIN {$sTableName} USING (OXID) ";
00141             }
00142         }
00143         return $sJoin;
00144     }
00145 
00154     protected function _getViewJoinLang($sTable,$iLang)
00155     {
00156         $sJoin = ' ';
00157         $sLangTable = getLangTableName($sTable, $iLang);
00158         if ($sLangTable && $sLangTable !== $sTable) {
00159             $sJoin .= "LEFT JOIN {$sLangTable} USING (OXID) ";
00160         }
00161         return $sJoin;
00162     }
00163 
00164 
00170     public function getDefaultCategory()
00171     {
00172         return $this->oxshops__oxdefcat->value;
00173     }
00174 
00175 }