OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
compare.php
Go to the documentation of this file.
1 <?php
2 
7 class Compare extends oxUBase
8 {
13  protected $_iCntPages = 1;
14 
19  protected $_iOrderCnt = null;
20 
25  protected $_iArticlesPerPage = 3;
26 
31  protected $_iCompItemsCnt = null;
32 
37  protected $_aCompItems = null;
38 
43  protected $_oArtList = null;
44 
49  protected $_oAttributeList = null;
50 
55  protected $_oRecommList = null;
56 
61  protected $_oPageNavigation = null;
62 
67  protected $_blBargainAction = true;
68 
73  protected $_blShowTagCloud = false;
74 
75 
80  protected $_sThisTemplate = 'page/compare/compare.tpl';
81 
87  protected $_aSimilarRecommListIds = null;
88 
89 
95  public function moveLeft() //#777C
96  {
97  $sArticleId = oxConfig::getParameter( 'aid' );
98  if ( $sArticleId && ( $aItems = $this->getCompareItems() ) ) {
99  $sPrevArticleId = null;
100 
101  $blFound = false;
102  foreach ( $aItems as $sOxid => $sVal ) {
103  if ( $sOxid == $sArticleId ) {
104  $blFound = true;
105  }
106  if ( !$blFound ) {
107  $sPrevArticleId = $sOxid;
108  }
109  }
110 
111  if ( $sPrevArticleId ) {
112 
113  $aNewItems = array();
114  foreach ( $aItems as $sOxid => $sVal ) {
115  if ( $sOxid == $sPrevArticleId ) {
116  $aNewItems[$sArticleId] = true;
117  } elseif ( $sOxid == $sArticleId ) {
118  $aNewItems[$sPrevArticleId] = true;
119  } else {
120  $aNewItems[$sOxid] = true;
121  }
122  }
123 
124  $this->setCompareItems($aNewItems);
125  }
126  }
127  }
128 
134  public function moveRight() //#777C
135  {
136  $sArticleId = oxConfig::getParameter( 'aid' );
137  if ( $sArticleId && ( $aItems = $this->getCompareItems() ) ) {
138  $sNextArticleId = 0;
139 
140  $blFound = false;
141  foreach ( $aItems as $sOxid => $sVal ) {
142  if ( $blFound ) {
143  $sNextArticleId = $sOxid;
144  $blFound = false;
145  }
146  if ( $sOxid == $sArticleId ) {
147  $blFound = true;
148  }
149  }
150 
151  if ( $sNextArticleId ) {
152 
153  $aNewItems = array();
154  foreach ( $aItems as $sOxid => $sVal ) {
155  if ( $sOxid == $sArticleId ) {
156  $aNewItems[$sNextArticleId] = true;
157  } elseif ( $sOxid == $sNextArticleId ) {
158  $aNewItems[$sArticleId] = true;
159  } else {
160  $aNewItems[$sOxid] = true;
161  }
162  }
163  $this->setCompareItems($aNewItems);
164  }
165  }
166  }
167 
173  public function inPopup() // #777C
174  {
175  $this->_sThisTemplate = 'compare_popup.tpl';
176  $this->_iArticlesPerPage = -1;
177  }
178 
186  public function setCompareItemsCnt( $iCount )
187  {
188  $this->_iCompItemsCnt = $iCount;
189  }
190 
196  public function getCompareItemsCnt()
197  {
198  if ( $this->_iCompItemsCnt === null ) {
199  $this->_iCompItemsCnt = 0;
200  if ( $aItems = $this->getCompareItems() ) {
201  $this->_iCompItemsCnt = count( $aItems );
202  }
203  }
204  return $this->_iCompItemsCnt;
205  }
206 
212  public function getCompareItems()
213  {
214  if ( $this->_aCompItems === null ) {
215  $aItems = oxSession::getVar( 'aFiltcompproducts' );
216  if ( is_array($aItems) && count($aItems) ) {
217  $this->_aCompItems = $aItems;
218  }
219  }
220  return $this->_aCompItems;
221  }
222 
230  public function setCompareItems( $aItems)
231  {
232  $this->_aCompItems = $aItems;
233  oxSession::setVar( 'aFiltcompproducts', $aItems );
234  }
235 
243  protected function _setArticlesPerPage( $iNumber)
244  {
245  $this->_iArticlesPerPage = $iNumber;
246  }
247 
253  public function setNoPaging()
254  {
255  $this->_setArticlesPerPage(0);
256  }
257 
258 
265  public function getCompArtList()
266  {
267  if ( $this->_oArtList === null ) {
268  if ( ( $aItems = $this->getCompareItems() ) ) {
269  // counts how many pages
270  $oList = oxNew( 'oxarticlelist' );
271  $oList->loadIds( array_keys( $aItems ) );
272 
273  // cut page articles
274  if ( $this->_iArticlesPerPage > 0 ) {
275  $this->_iCntPages = round( $oList->count() / $this->_iArticlesPerPage + 0.49 );
276  $aItems = $this->_removeArticlesFromPage( $aItems, $oList );
277  }
278 
279  $this->_oArtList = $this->_changeArtListOrder( $aItems, $oList );
280  }
281  }
282 
283  return $this->_oArtList;
284  }
285 
291  public function getAttributeList()
292  {
293  if ( $this->_oAttributeList === null ) {
294  $this->_oAttributeList = false;
295  if ( $oArtList = $this->getCompArtList()) {
296  $oAttributeList = oxNew( 'oxattributelist' );
297  $this->_oAttributeList = $oAttributeList->loadAttributesByIds( array_keys( $oArtList ) );
298  }
299  }
300  return $this->_oAttributeList;
301  }
302 
308  public function getSimilarRecommListIds()
309  {
310  if ( $this->_aSimilarRecommListIds === null ) {
311  $this->_aSimilarRecommListIds = false;
312 
313  if ( $oArtList = $this->getCompArtList() ) {
314  $this->_aSimilarRecommListIds = array_keys( $oArtList );
315  }
316  }
318  }
319 
325  public function getPageNavigation()
326  {
327  if ( $this->_oPageNavigation === null ) {
328  $this->_oPageNavigation = false;
329  $this->_oPageNavigation = $this->generatePageNavigation();
330  }
332  }
333 
342  protected function _removeArticlesFromPage( $aItems, $oList )
343  {
344  //#1106S $aItems changed to $oList.
345  //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
346  $aListKeys = $oList->arrayKeys();
347  $aItemKeys = array_keys($aItems);
348  $aKeys = array_intersect( $aItemKeys, $aListKeys );
349  $aNewItems = array();
350  $iActPage = $this->getActPage();
351  for ( $i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++ ) {
352  if ( !isset($aKeys[$i])) {
353  break;
354  }
355  $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
356  }
357  return $aNewItems;
358  }
359 
368  protected function _changeArtListOrder( $aItems, $oList )
369  {
370  // #777C changing order of list elements, according to $aItems
371  $oNewList = array();
372  $iCnt = 0;
373  $iActPage = $this->getActPage();
374  foreach ( $aItems as $sOxid => $sVal ) {
375 
376  //#4391T, skipping non loaded products
377  if (!isset ($oList[$sOxid]) ) {
378  continue;
379  }
380 
381  $iCnt++;
382  $oNewList[$sOxid] = $oList[$sOxid];
383 
384  // hide arrow if article is first in the list
385  $oNewList[$sOxid]->hidePrev = false;
386  if ( $iActPage == 0 && $iCnt==1 ) {
387  $oNewList[$sOxid]->hidePrev = true;
388  }
389 
390  // hide arrow if article is last in the list
391  $oNewList[$sOxid]->hideNext = false;
392  if ( ( $iActPage + 1 ) == $this->_iCntPages && $iCnt == count( $aItems ) ) {
393  $oNewList[$sOxid]->hideNext = true;
394  }
395  }
396  return $oNewList;
397  }
398 
404  public function getOrderCnt()
405  {
406  if ( $this->_iOrderCnt === null ) {
407  $this->_iOrderCnt = 0;
408  if ( $oUser = $this->getUser() ) {
409  $this->_iOrderCnt = $oUser->getOrderCount();
410  }
411  }
412  return $this->_iOrderCnt;
413  }
414 
420  public function getBreadCrumb()
421  {
422  $aPaths = array();
423  $aPath = array();
424 
425  $aPath['title'] = oxRegistry::getLang()->translateString( 'MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false );
426  $aPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
427  $aPaths[] = $aPath;
428 
429  $aPath['title'] = oxRegistry::getLang()->translateString( 'PRODUCT_COMPARISON', oxRegistry::getLang()->getBaseLanguage(), false );
430  $aPath['link'] = $this->getLink();
431  $aPaths[] = $aPath;
432 
433  return $aPaths;
434  }
435 }