OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
oxshopviewvalidator.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
11  protected $_aMultiLangTables = array();
12 
13  protected $_aMultiShopTables = array();
14 
15  protected $_aLanguages = array();
16 
17  protected $_aAllShopLanguages = array();
18 
19  protected $_iShopId = null;
20 
21  protected $_aAllViews = array();
22 
23  protected $_aShopViews = array();
24 
25  protected $_aValidShopViews = array();
26 
32  public function setMultiLangTables($aMultiLangTables)
33  {
34  $this->_aMultiLangTables = $aMultiLangTables;
35  }
36 
42  public function getMultiLangTables()
43  {
45  }
46 
47 
53  public function setMultiShopTables($aMultiShopTables)
54  {
55  $this->_aMultiShopTables = $aMultiShopTables;
56  }
57 
63  public function getMultiShopTables()
64  {
66  }
67 
73  public function setLanguages($aLanguages)
74  {
75  $this->_aLanguages = $aLanguages;
76  }
77 
83  public function getLanguages()
84  {
85  return $this->_aLanguages;
86  }
87 
93  public function setAllShopLanguages($aAllShopLanguages)
94  {
95  $this->_aAllShopLanguages = $aAllShopLanguages;
96  }
97 
103  public function getAllShopLanguages()
104  {
106  }
107 
108 
114  public function setShopId($iShopId)
115  {
116  $this->_iShopId = $iShopId;
117  }
118 
124  public function getShopId()
125  {
126  return $this->_iShopId;
127  }
128 
134  protected function _getAllViews()
135  {
136  if (empty($this->_aAllViews)) {
137  $this->_aAllViews = oxDb::getDb()->getCol("SHOW TABLES LIKE 'oxv_%'");
138  }
139 
140  return $this->_aAllViews;
141  }
142 
150  protected function _isCurrentShopView($sViewName)
151  {
152  $blResult = false;
153 
154  $blEndsWithShopId = preg_match("/[_]([0-9]+)$/", $sViewName, $aMatchEndsWithShopId);
155  $blContainsShopId = preg_match("/[_]([0-9]+)[_]/", $sViewName, $aMatchContainsShopId);
156 
157  if ((!$blEndsWithShopId && !$blContainsShopId) ||
158  ($blEndsWithShopId && $aMatchEndsWithShopId[1] == $this->getShopId()) ||
159  ($blContainsShopId && $aMatchContainsShopId[1] == $this->getShopId())
160  ) {
161 
162  $blResult = true;
163  }
164 
165  return $blResult;
166  }
167 
168 
174  protected function _getShopViews()
175  {
176  if (empty($this->_aShopViews)) {
177 
178  $this->_aShopViews = array();
179  $aAllViews = $this->_getAllViews();
180 
181  foreach ($aAllViews as $sView) {
182 
183  if ($this->_isCurrentShopView($sView)) {
184  $this->_aShopViews[] = $sView;
185  }
186  }
187  }
188 
189  return $this->_aShopViews;
190  }
191 
197  protected function _getValidShopViews()
198  {
199  if (empty($this->_aValidShopViews)) {
200 
201  $aTables = $this->getMultilangTables();
202 
203 
204  $this->_aValidShopViews = array();
205 
206  foreach ($aTables as $sTable) {
207  $this->_aValidShopViews[] = 'oxv_' . $sTable;
208 
209  if (in_array($sTable, $this->getMultiLangTables())) {
210  foreach ($this->getAllShopLanguages() as $sLang) {
211  $this->_aValidShopViews[] = 'oxv_' . $sTable . '_' . $sLang;
212  }
213  }
214 
215  }
216  }
217 
219  }
220 
228  protected function _isViewValid($sViewName)
229  {
230  return in_array($sViewName, $this->_getValidShopViews());
231  }
232 
238  public function getInvalidViews()
239  {
240  $aInvalidViews = array();
241  $aShopViews = $this->_getShopViews();
242 
243  foreach ($aShopViews as $sView) {
244  if (!$this->_isViewValid($sView)) {
245  $aInvalidViews[] = $sView;
246  }
247  }
248 
249  return $aInvalidViews;
250  }
251 }