OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxshop.php
Go to the documentation of this file.
1 <?php
2 
8 class oxShop extends oxI18n
9 {
15  protected $_sClassName = 'oxshop';
16 
22  protected $_aMultiShopTables = array();
23 
24 
28  public function __construct()
29  {
31 
32 
33  $this->init( 'oxshops' );
34 
35  if ( $iMax = $this->getConfig()->getConfigParam('iMaxShopId') ) {
36  $this->setMaxShopId( $iMax );
37  }
38 
39  }
40 
48  public function setMultiShopTables( $aMultiShopTables )
49  {
50  $this->_aMultiShopTables = $aMultiShopTables;
51  }
52 
53 
62  public function generateViews( $blMultishopInheritCategories = false, $aMallInherit = null )
63  {
64  $oDb = oxDb::getDb();
65  $oLang = oxRegistry::getLang();
66  $aLanguages = $oLang->getLanguageIds( $this->getId() );
67  $aAllShopLanguages = $oLang->getAllShopLanguageIds();
68 
69  $aTables = $aMultilangTables = oxRegistry::getLang()->getMultiLangTables();
70 
71  $aQueries = array();
72 
73  // Generate multitable views
74  foreach ( $aTables as $sTable ) {
75  $aQueries[] = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW oxv_'.$sTable.' AS SELECT * FROM '.$sTable.' '.$this->_getViewJoinAll($sTable);
76 
77  if (in_array($sTable, $aMultilangTables)) {
78  foreach ($aLanguages as $iLang => $sLang) {
79  $aQueries[] = 'CREATE OR REPLACE SQL SECURITY INVOKER VIEW oxv_'.$sTable.'_'.$sLang.' AS SELECT '.$this->_getViewSelect($sTable, $iLang).' FROM '.$sTable.' '.$this->_getViewJoinLang($sTable, $iLang);
80  }
81  }
82  }
83 
84  $bSuccess = true;
85  foreach ($aQueries as $sQuery) {
86  if ( !$oDb->execute( $sQuery ) ) {
87  $bSuccess = false;
88  }
89  }
90 
91  $oViewsValidator = oxNew( 'oxShopViewValidator' );
92 
93  $oViewsValidator->setShopId( $this->getId() );
94  $oViewsValidator->setLanguages( $aLanguages );
95  $oViewsValidator->setAllShopLanguages( $aAllShopLanguages );
96  $oViewsValidator->setMultiLangTables( $aMultilangTables );
97  $oViewsValidator->setMultiShopTables( $aMultishopTables );
98 
99  $aViews = $oViewsValidator->getInvalidViews();
100 
101  foreach ($aViews as $sView) {
102  $oDb->execute( 'DROP VIEW IF EXISTS '. $sView );
103  }
104 
105  return $bSuccess;
106  }
107 
116  protected function _getViewSelect($sTable,$iLang)
117  {
118  $oMetaData = oxNew('oxDbMetaDataHandler');
119  $aFields = $oMetaData->getSinglelangFields($sTable, $iLang);
120  foreach ($aFields as $sCoreField => $sField) {
121  if ($sCoreField !== $sField) {
122  $aFields[$sCoreField] = $sField.' AS '.$sCoreField;
123  }
124  }
125 
126  return implode(',', $aFields);
127  }
128 
136  protected function _getViewJoinAll($sTable)
137  {
138  $sJoin = ' ';
139  $oMetaData = oxNew('oxDbMetaDataHandler');
140  $aTables = $oMetaData->getAllMultiTables($sTable);
141  if (count($aTables)) {
142  foreach ($aTables as $sTableKey => $sTableName) {
143  $sJoin .= "LEFT JOIN {$sTableName} USING (OXID) ";
144  }
145  }
146  return $sJoin;
147  }
148 
157  protected function _getViewJoinLang($sTable,$iLang)
158  {
159  $sJoin = ' ';
160  $sLangTable = getLangTableName($sTable, $iLang);
161  if ($sLangTable && $sLangTable !== $sTable) {
162  $sJoin .= "LEFT JOIN {$sLangTable} USING (OXID) ";
163  }
164  return $sJoin;
165  }
166 
167 
173  public function getDefaultCategory()
174  {
175  return $this->oxshops__oxdefcat->value;
176  }
177 
183  public function isProductiveMode()
184  {
185  return (bool) $this->oxshops__oxproductive->value;
186  }
187 
188 }