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