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         $this->init( 'oxshops' );
00032 
00033         if ( $iMax = $this->getConfig()->getConfigParam('iMaxShopId') ) {
00034             $this->setMaxShopId( $iMax );
00035         }
00036 
00037     }
00038 
00046     public function setMultiShopTables( $aMultiShopTables )
00047     {
00048         $this->_aMultiShopTables = $aMultiShopTables;
00049     }
00050 
00051 
00060     public function generateViews( $blMultishopInheritCategories = false, $aMallInherit = null )
00061     {
00062         $oDb        = oxDb::getDb();
00063         $aLanguages = oxRegistry::getLang()->getLanguageIds();
00064 
00065         $aTables = $aMultilangTables = oxRegistry::getLang()->getMultiLangTables();
00066 
00067         $aQ = array();
00068 
00069         // Generate multitable views
00070         foreach ( $aTables as $sTable ) {
00071             $aQ[] = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW oxv_'.$sTable.' AS SELECT * FROM '.$sTable.' '.$this->_getViewJoinAll($sTable);
00072 
00073             if (in_array($sTable, $aMultilangTables)) {
00074                 foreach ($aLanguages as $iLang => $sLang) {
00075                     $aQ[] = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW oxv_'.$sTable.'_'.$sLang.' AS SELECT '.$this->_getViewSelect($sTable, $iLang).' FROM '.$sTable.' '.$this->_getViewJoinLang($sTable, $iLang);
00076                 }
00077             }
00078         }
00079 
00080         $bSuccess = true;
00081         foreach ($aQ as $sQ) {
00082             if ( !$oDb->execute( $sQ ) ) {
00083                 $bSuccess = false;
00084             }
00085         }
00086 
00087         $oViewsValidator = oxNew( 'oxShopViewValidator' );
00088 
00089         $oViewsValidator->setShopId( $this->getConfig()->getShopId() );
00090         $oViewsValidator->setLanguages( $aLanguages );
00091         $oViewsValidator->setMultiLangTables( $aMultilangTables );
00092         $oViewsValidator->setMultiShopTables( $aMultishopTables );
00093 
00094         $aViews = $oViewsValidator->getInvalidViews();
00095 
00096         foreach ($aViews as $sView) {
00097             $oDb->execute( 'DROP VIEW IF EXISTS '. $sView );
00098         }
00099 
00100         return $bSuccess;
00101     }
00102 
00111     protected function _getViewSelect($sTable,$iLang)
00112     {
00113         $oMetaData = oxNew('oxDbMetaDataHandler');
00114         $aFields = $oMetaData->getSinglelangFields($sTable, $iLang);
00115         foreach ($aFields as $sCoreField => $sField) {
00116             if ($sCoreField !== $sField) {
00117                 $aFields[$sCoreField] = $sField.' AS '.$sCoreField;
00118             }
00119         }
00120 
00121         return implode(',', $aFields);
00122     }
00123 
00131     protected function _getViewJoinAll($sTable)
00132     {
00133         $sJoin = ' ';
00134         $oMetaData = oxNew('oxDbMetaDataHandler');
00135         $aTables = $oMetaData->getAllMultiTables($sTable);
00136         if (count($aTables)) {
00137             foreach ($aTables as $sTableKey => $sTableName) {
00138                 $sJoin .= "LEFT JOIN {$sTableName} USING (OXID) ";
00139             }
00140         }
00141         return $sJoin;
00142     }
00143 
00152     protected function _getViewJoinLang($sTable,$iLang)
00153     {
00154         $sJoin = ' ';
00155         $sLangTable = getLangTableName($sTable, $iLang);
00156         if ($sLangTable && $sLangTable !== $sTable) {
00157             $sJoin .= "LEFT JOIN {$sLangTable} USING (OXID) ";
00158         }
00159         return $sJoin;
00160     }
00161 
00162 
00168     public function getDefaultCategory()
00169     {
00170         return $this->oxshops__oxdefcat->value;
00171     }
00172 
00173 }