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 
00066         $aLanguages = $this->_getLanguageIds();
00067 
00068         $aTables = $aMultilangTables = oxRegistry::getLang()->getMultiLangTables();
00069 
00070         $aQ = array();
00071 
00072         // Generate multitable views
00073         foreach ( $aTables as $sTable ) {
00074             $aQ[] = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW oxv_'.$sTable.' AS SELECT * FROM '.$sTable.' '.$this->_getViewJoinAll($sTable);
00075 
00076             if (in_array($sTable, $aMultilangTables)) {
00077                 foreach ($aLanguages as $iLang => $sLang) {
00078                     $aQ[] = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW oxv_'.$sTable.'_'.$sLang.' AS SELECT '.$this->_getViewSelect($sTable, $iLang).' FROM '.$sTable.' '.$this->_getViewJoinLang($sTable, $iLang);
00079                 }
00080             }
00081         }
00082 
00083         $bSuccess = true;
00084         foreach ($aQ as $sQ) {
00085             if ( !$oDb->execute( $sQ ) ) {
00086                 $bSuccess = false;
00087             }
00088         }
00089 
00090         $oViewsValidator = oxNew( 'oxShopViewValidator' );
00091 
00092         $oViewsValidator->setShopId( $this->getId() );
00093         $oViewsValidator->setLanguages( $aLanguages );
00094         $oViewsValidator->setMultiLangTables( $aMultilangTables );
00095         $oViewsValidator->setMultiShopTables( $aMultishopTables );
00096 
00097         $aViews = $oViewsValidator->getInvalidViews();
00098 
00099         foreach ($aViews as $sView) {
00100             $oDb->execute( 'DROP VIEW IF EXISTS '. $sView );
00101         }
00102 
00103         return $bSuccess;
00104     }
00105 
00114     protected function _getViewSelect($sTable,$iLang)
00115     {
00116         $oMetaData = oxNew('oxDbMetaDataHandler');
00117         $aFields = $oMetaData->getSinglelangFields($sTable, $iLang);
00118         foreach ($aFields as $sCoreField => $sField) {
00119             if ($sCoreField !== $sField) {
00120                 $aFields[$sCoreField] = $sField.' AS '.$sCoreField;
00121             }
00122         }
00123 
00124         return implode(',', $aFields);
00125     }
00126 
00134     protected function _getViewJoinAll($sTable)
00135     {
00136         $sJoin = ' ';
00137         $oMetaData = oxNew('oxDbMetaDataHandler');
00138         $aTables = $oMetaData->getAllMultiTables($sTable);
00139         if (count($aTables)) {
00140             foreach ($aTables as $sTableKey => $sTableName) {
00141                 $sJoin .= "LEFT JOIN {$sTableName} USING (OXID) ";
00142             }
00143         }
00144         return $sJoin;
00145     }
00146 
00155     protected function _getViewJoinLang($sTable,$iLang)
00156     {
00157         $sJoin = ' ';
00158         $sLangTable = getLangTableName($sTable, $iLang);
00159         if ($sLangTable && $sLangTable !== $sTable) {
00160             $sJoin .= "LEFT JOIN {$sLangTable} USING (OXID) ";
00161         }
00162         return $sJoin;
00163     }
00164 
00165 
00171     public function getDefaultCategory()
00172     {
00173         return $this->oxshops__oxdefcat->value;
00174     }
00175 
00181     private function _getLanguageIds()
00182     {
00183             $aLanguages = oxRegistry::getLang()->getLanguageIds();
00184 
00185         return $aLanguages;
00186     }
00187 
00188 }