oxshop.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxShop extends oxI18n
00009 {
00015     protected $_sCoreTbl = 'oxshops';
00016 
00022     protected $_sClassName = 'oxshop';
00023 
00029     protected $_aMultiShopTables = array();
00030 
00031 
00035     public function __construct()
00036     {
00037         parent::__construct();
00038         $this->init( 'oxshops' );
00039     }
00040 
00048     public function setMultiShopTables( $aMultiShopTables )
00049     {
00050         $this->_aMultiShopTables = $aMultiShopTables;
00051     }
00052 
00053 
00062     public function generateViews( $blMultishopInherit = false, $aMallInherit = null )
00063     {
00064         $oDB        = oxDb::getDb();
00065         $aLanguages = oxLang::getInstance()->getLanguageIds();
00066 
00067         $aTables = $aMultilangTables = oxLang::getInstance()->getMultiLangTables();
00068 
00069         $aQ = array();
00070 
00071         // Generate multitable views
00072         foreach ( $aTables as $sTable ) {
00073             $aQ[] = 'CREATE OR REPLACE 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 VIEW oxv_'.$sTable.'_'.$sLang.' AS SELECT '.$this->_getViewSelect($sTable, $iLang).' FROM '.$sTable.' '.$this->_getViewJoinLang($sTable, $iLang);
00078                 }
00079             }
00080         }
00081 
00082         foreach ($aQ as $sQ) {
00083             $oDB->execute( $sQ );
00084         }
00085     }
00086 
00095     protected function _getViewSelect($sTable,$iLang)
00096     {
00097         $oMetaData = oxNew('oxDbMetaDataHandler');
00098         $aFields = $oMetaData->getSinglelangFields($sTable, $iLang);
00099         foreach ($aFields as $sCoreField => $sField) {
00100             if ($sCoreField !== $sField) {
00101                 $aFields[$sCoreField] = $sField.' AS '.$sCoreField;
00102             }
00103         }
00104 
00105         return implode(',', $aFields);
00106     }
00107 
00115     protected function _getViewJoinAll($sTable)
00116     {
00117         $sJoin = ' ';
00118         $oMetaData = oxNew('oxDbMetaDataHandler');
00119         $aTables = $oMetaData->getAllMultiTables($sTable);
00120         if (count($aTables)) {
00121             foreach ($aTables as $sTableKey => $sTableName) {
00122                 $sJoin .= "LEFT JOIN {$sTableName} USING (OXID) ";
00123             }
00124         }
00125         return $sJoin;
00126     }
00127 
00136     protected function _getViewJoinLang($sTable,$iLang)
00137     {
00138         $sJoin = ' ';
00139         $sLangTable = getLangTableName($sTable, $iLang);
00140         if ($sLangTable && $sLangTable !== $sTable) {
00141             $sJoin .= "LEFT JOIN {$sLangTable} USING (OXID) ";
00142         }
00143         return $sJoin;
00144     }
00145 
00146 }