OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
compare.php
Go to the documentation of this file.
1 <?php
2 
7 class Compare extends oxUBase
8 {
9 
15  protected $_iCntPages = 1;
16 
22  protected $_iOrderCnt = null;
23 
29  protected $_iArticlesPerPage = 3;
30 
36  protected $_iCompItemsCnt = null;
37 
43  protected $_aCompItems = null;
44 
50  protected $_oArtList = null;
51 
57  protected $_oAttributeList = null;
58 
66  protected $_oRecommList = null;
67 
73  protected $_oPageNavigation = null;
74 
80  protected $_blBargainAction = true;
81 
89  protected $_blShowTagCloud = false;
90 
91 
97  protected $_sThisTemplate = 'page/compare/compare.tpl';
98 
106  protected $_aSimilarRecommListIds = null;
107 
108 
112  public function moveLeft() //#777C
113  {
114  $sArticleId = oxRegistry::getConfig()->getRequestParameter('aid');
115  if ($sArticleId && ($aItems = $this->getCompareItems())) {
116  $sPrevArticleId = null;
117 
118  $blFound = false;
119  foreach ($aItems as $sOxid => $sVal) {
120  if ($sOxid == $sArticleId) {
121  $blFound = true;
122  }
123  if (!$blFound) {
124  $sPrevArticleId = $sOxid;
125  }
126  }
127 
128  if ($sPrevArticleId) {
129 
130  $aNewItems = array();
131  foreach ($aItems as $sOxid => $sVal) {
132  if ($sOxid == $sPrevArticleId) {
133  $aNewItems[$sArticleId] = true;
134  } elseif ($sOxid == $sArticleId) {
135  $aNewItems[$sPrevArticleId] = true;
136  } else {
137  $aNewItems[$sOxid] = true;
138  }
139  }
140 
141  $this->setCompareItems($aNewItems);
142  }
143  }
144  }
145 
149  public function moveRight() //#777C
150  {
151  $sArticleId = oxRegistry::getConfig()->getRequestParameter('aid');
152  if ($sArticleId && ($aItems = $this->getCompareItems())) {
153  $sNextArticleId = 0;
154 
155  $blFound = false;
156  foreach ($aItems as $sOxid => $sVal) {
157  if ($blFound) {
158  $sNextArticleId = $sOxid;
159  $blFound = false;
160  }
161  if ($sOxid == $sArticleId) {
162  $blFound = true;
163  }
164  }
165 
166  if ($sNextArticleId) {
167 
168  $aNewItems = array();
169  foreach ($aItems as $sOxid => $sVal) {
170  if ($sOxid == $sArticleId) {
171  $aNewItems[$sNextArticleId] = true;
172  } elseif ($sOxid == $sNextArticleId) {
173  $aNewItems[$sArticleId] = true;
174  } else {
175  $aNewItems[$sOxid] = true;
176  }
177  }
178  $this->setCompareItems($aNewItems);
179  }
180  }
181  }
182 
186  public function inPopup() // #777C
187  {
188  $this->_sThisTemplate = 'compare_popup.tpl';
189  $this->_iArticlesPerPage = -1;
190  }
191 
197  public function setCompareItemsCnt($iCount)
198  {
199  $this->_iCompItemsCnt = $iCount;
200  }
201 
207  public function getCompareItemsCnt()
208  {
209  if ($this->_iCompItemsCnt === null) {
210  $this->_iCompItemsCnt = 0;
211  if ($aItems = $this->getCompareItems()) {
212  $this->_iCompItemsCnt = count($aItems);
213  }
214  }
215 
216  return $this->_iCompItemsCnt;
217  }
218 
224  public function getCompareItems()
225  {
226  if ($this->_aCompItems === null) {
227  $aItems = oxRegistry::getSession()->getVariable('aFiltcompproducts');
228  if (is_array($aItems) && count($aItems)) {
229  $this->_aCompItems = $aItems;
230  }
231  }
232 
233  return $this->_aCompItems;
234  }
235 
241  public function setCompareItems($aItems)
242  {
243  $this->_aCompItems = $aItems;
244  oxRegistry::getSession()->setVariable('aFiltcompproducts', $aItems);
245  }
246 
252  protected function _setArticlesPerPage($iNumber)
253  {
254  $this->_iArticlesPerPage = $iNumber;
255  }
256 
260  public function setNoPaging()
261  {
262  $this->_setArticlesPerPage(0);
263  }
264 
265 
272  public function getCompArtList()
273  {
274  if ($this->_oArtList === null) {
275  if (($aItems = $this->getCompareItems())) {
276  // counts how many pages
277  $oList = oxNew('oxarticlelist');
278  $oList->loadIds(array_keys($aItems));
279 
280  // cut page articles
281  if ($this->_iArticlesPerPage > 0) {
282  $this->_iCntPages = round($oList->count() / $this->_iArticlesPerPage + 0.49);
283  $aItems = $this->_removeArticlesFromPage($aItems, $oList);
284  }
285 
286  $this->_oArtList = $this->_changeArtListOrder($aItems, $oList);
287  }
288  }
289 
290  return $this->_oArtList;
291  }
292 
298  public function getAttributeList()
299  {
300  if ($this->_oAttributeList === null) {
301  $this->_oAttributeList = false;
302  if ($oArtList = $this->getCompArtList()) {
303  $oAttributeList = oxNew('oxattributelist');
304  $this->_oAttributeList = $oAttributeList->loadAttributesByIds(array_keys($oArtList));
305  }
306  }
307 
308  return $this->_oAttributeList;
309  }
310 
318  public function getSimilarRecommListIds()
319  {
320  if ($this->_aSimilarRecommListIds === null) {
321  $this->_aSimilarRecommListIds = false;
322 
323  if ($oArtList = $this->getCompArtList()) {
324  $this->_aSimilarRecommListIds = array_keys($oArtList);
325  }
326  }
327 
329  }
330 
336  public function getPageNavigation()
337  {
338  if ($this->_oPageNavigation === null) {
339  $this->_oPageNavigation = false;
340  $this->_oPageNavigation = $this->generatePageNavigation();
341  }
342 
344  }
345 
354  protected function _removeArticlesFromPage($aItems, $oList)
355  {
356  //#1106S $aItems changed to $oList.
357  //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
358  $aListKeys = $oList->arrayKeys();
359  $aItemKeys = array_keys($aItems);
360  $aKeys = array_intersect($aItemKeys, $aListKeys);
361  $aNewItems = array();
362  $iActPage = $this->getActPage();
363  for ($i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++) {
364  if (!isset($aKeys[$i])) {
365  break;
366  }
367  $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
368  }
369 
370  return $aNewItems;
371  }
372 
381  protected function _changeArtListOrder($aItems, $oList)
382  {
383  // #777C changing order of list elements, according to $aItems
384  $oNewList = array();
385  $iCnt = 0;
386  $iActPage = $this->getActPage();
387  foreach ($aItems as $sOxid => $sVal) {
388 
389  //#4391T, skipping non loaded products
390  if (!isset ($oList[$sOxid])) {
391  continue;
392  }
393 
394  $iCnt++;
395  $oNewList[$sOxid] = $oList[$sOxid];
396 
397  // hide arrow if article is first in the list
398  $oNewList[$sOxid]->hidePrev = false;
399  if ($iActPage == 0 && $iCnt == 1) {
400  $oNewList[$sOxid]->hidePrev = true;
401  }
402 
403  // hide arrow if article is last in the list
404  $oNewList[$sOxid]->hideNext = false;
405  if (($iActPage + 1) == $this->_iCntPages && $iCnt == count($aItems)) {
406  $oNewList[$sOxid]->hideNext = true;
407  }
408  }
409 
410  return $oNewList;
411  }
412 
418  public function getOrderCnt()
419  {
420  if ($this->_iOrderCnt === null) {
421  $this->_iOrderCnt = 0;
422  if ($oUser = $this->getUser()) {
423  $this->_iOrderCnt = $oUser->getOrderCount();
424  }
425  }
426 
427  return $this->_iOrderCnt;
428  }
429 
435  public function getBreadCrumb()
436  {
437  $aPaths = array();
438  $aPath = array();
439 
440  $aPath['title'] = oxRegistry::getLang()->translateString('MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false);
441  $aPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl($this->getViewConfig()->getSelfLink() . 'cl=account');
442  $aPaths[] = $aPath;
443 
444  $aPath['title'] = oxRegistry::getLang()->translateString('PRODUCT_COMPARISON', oxRegistry::getLang()->getBaseLanguage(), false);
445  $aPath['link'] = $this->getLink();
446  $aPaths[] = $aPath;
447 
448  return $aPaths;
449  }
450 }