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         return $bSuccess;
00087     }
00088 
00097     protected function _getViewSelect($sTable,$iLang)
00098     {
00099         $oMetaData = oxNew('oxDbMetaDataHandler');
00100         $aFields = $oMetaData->getSinglelangFields($sTable, $iLang);
00101         foreach ($aFields as $sCoreField => $sField) {
00102             if ($sCoreField !== $sField) {
00103                 $aFields[$sCoreField] = $sField.' AS '.$sCoreField;
00104             }
00105         }
00106 
00107         return implode(',', $aFields);
00108     }
00109 
00117     protected function _getViewJoinAll($sTable)
00118     {
00119         $sJoin = ' ';
00120         $oMetaData = oxNew('oxDbMetaDataHandler');
00121         $aTables = $oMetaData->getAllMultiTables($sTable);
00122         if (count($aTables)) {
00123             foreach ($aTables as $sTableKey => $sTableName) {
00124                 $sJoin .= "LEFT JOIN {$sTableName} USING (OXID) ";
00125             }
00126         }
00127         return $sJoin;
00128     }
00129 
00138     protected function _getViewJoinLang($sTable,$iLang)
00139     {
00140         $sJoin = ' ';
00141         $sLangTable = getLangTableName($sTable, $iLang);
00142         if ($sLangTable && $sLangTable !== $sTable) {
00143             $sJoin .= "LEFT JOIN {$sLangTable} USING (OXID) ";
00144         }
00145         return $sJoin;
00146     }
00147 
00148 
00154     public function getDefaultCategory()
00155     {
00156         return $this->oxshops__oxdefcat->value;
00157     }
00158 
00159 }