OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
oxshopviewvalidator.php
Go to the documentation of this file.
1 <?php
2 
9 
10  protected $_aMultiLangTables = array();
11 
12  protected $_aMultiShopTables = array();
13 
14  protected $_aLanguages = array();
15 
16  protected $_aAllShopLanguages = array();
17 
18  protected $_iShopId = null;
19 
20  protected $_aAllViews = array();
21 
22  protected $_aShopViews = array();
23 
24  protected $_aValidShopViews = array();
25 
29  public function setMultiLangTables( $aMultiLangTables )
30  {
31  $this->_aMultiLangTables = $aMultiLangTables;
32  }
33 
38  public function getMultiLangTables()
39  {
41  }
42 
43 
47  public function setMultiShopTables( $aMultiShopTables )
48  {
49  $this->_aMultiShopTables = $aMultiShopTables;
50  }
51 
56  public function getMultiShopTables()
57  {
59  }
60 
65  public function setLanguages( $aLanguages )
66  {
67  $this->_aLanguages = $aLanguages;
68  }
69 
73  public function getLanguages()
74  {
75  return $this->_aLanguages;
76  }
77 
82  public function setAllShopLanguages( $aAllShopLanguages )
83  {
84  $this->_aAllShopLanguages = $aAllShopLanguages;
85  }
86 
90  public function getAllShopLanguages()
91  {
93  }
94 
95 
99  public function setShopId( $iShopId )
100  {
101  $this->_iShopId = $iShopId;
102  }
103 
108  public function getShopId()
109  {
110  return $this->_iShopId;
111  }
112 
117  protected function _getAllViews()
118  {
119  if ( empty( $this->_aAllViews ) ) {
120  $this->_aAllViews = oxDb::getDb()->getCol( "SHOW TABLES LIKE 'oxv_%'" );
121  }
122 
123  return $this->_aAllViews;
124  }
125 
131  protected function _isCurrentShopView( $sViewName )
132  {
133  $blResult = false;
134 
135  $blEndsWithShopId = preg_match( "/[_]([0-9]+)$/",$sViewName, $aMatchEndsWithShopId );
136  $blContainsShopId = preg_match( "/[_]([0-9]+)[_]/",$sViewName, $aMatchContainsShopId );
137 
138  if ( ( !$blEndsWithShopId && !$blContainsShopId ) ||
139  ( $blEndsWithShopId && $aMatchEndsWithShopId[1] == $this->getShopId() ) ||
140  ( $blContainsShopId && $aMatchContainsShopId[1] == $this->getShopId() ) ) {
141 
142  $blResult = true;
143  }
144 
145  return $blResult;
146  }
147 
148 
153  protected function _getShopViews()
154  {
155  if ( empty( $this->_aShopViews ) ) {
156 
157  $this->_aShopViews = array();
158  $aAllViews = $this->_getAllViews();
159 
160  foreach ( $aAllViews as $sView ) {
161 
162  if ( $this->_isCurrentShopView( $sView ) ){
163  $this->_aShopViews[] = $sView;
164  }
165  }
166  }
167 
168  return $this->_aShopViews;
169  }
170 
175  protected function _getValidShopViews()
176  {
177  if ( empty( $this->_aValidShopViews ) ) {
178 
179  $aTables = $this->getMultilangTables();
180 
181 
182  $this->_aValidShopViews = array();
183 
184  foreach ( $aTables as $sTable ) {
185  $this->_aValidShopViews[] = 'oxv_'.$sTable;;
186 
187  if ( in_array( $sTable, $this->getMultiLangTables() ) ) {
188  foreach ( $this->getAllShopLanguages() as $sLang ) {
189  $this->_aValidShopViews[] ='oxv_'.$sTable.'_'.$sLang;
190  }
191  }
192 
193  }
194  }
195 
197  }
198 
204  protected function _isViewValid( $sViewName ){
205  return in_array( $sViewName, $this->_getValidShopViews() );
206  }
207 
212  public function getInvalidViews()
213  {
214  $aInvalidViews = array();
215  $aShopViews = $this->_getShopViews();
216 
217  foreach ( $aShopViews as $sView ) {
218  if ( !$this->_isViewValid( $sView ) ){
219  $aInvalidViews[] = $sView;
220  }
221  }
222 
223  return $aInvalidViews;
224  }
225 
226 }