Go to the documentation of this file.00001 <?php
00002
00007 class Compare extends oxUBase
00008 {
00009
00015 protected $_iCntPages = 1;
00016
00022 protected $_iOrderCnt = null;
00023
00029 protected $_iArticlesPerPage = 3;
00030
00036 protected $_iCompItemsCnt = null;
00037
00043 protected $_aCompItems = null;
00044
00050 protected $_oArtList = null;
00051
00057 protected $_oAttributeList = null;
00058
00064 protected $_oRecommList = null;
00065
00071 protected $_oPageNavigation = null;
00072
00078 protected $_blBargainAction = true;
00079
00085 protected $_blShowTagCloud = false;
00086
00087
00093 protected $_sThisTemplate = 'page/compare/compare.tpl';
00094
00100 protected $_aSimilarRecommListIds = null;
00101
00102
00106 public function moveLeft()
00107 {
00108 $sArticleId = oxRegistry::getConfig()->getRequestParameter('aid');
00109 if ($sArticleId && ($aItems = $this->getCompareItems())) {
00110 $sPrevArticleId = null;
00111
00112 $blFound = false;
00113 foreach ($aItems as $sOxid => $sVal) {
00114 if ($sOxid == $sArticleId) {
00115 $blFound = true;
00116 }
00117 if (!$blFound) {
00118 $sPrevArticleId = $sOxid;
00119 }
00120 }
00121
00122 if ($sPrevArticleId) {
00123
00124 $aNewItems = array();
00125 foreach ($aItems as $sOxid => $sVal) {
00126 if ($sOxid == $sPrevArticleId) {
00127 $aNewItems[$sArticleId] = true;
00128 } elseif ($sOxid == $sArticleId) {
00129 $aNewItems[$sPrevArticleId] = true;
00130 } else {
00131 $aNewItems[$sOxid] = true;
00132 }
00133 }
00134
00135 $this->setCompareItems($aNewItems);
00136 }
00137 }
00138 }
00139
00143 public function moveRight()
00144 {
00145 $sArticleId = oxRegistry::getConfig()->getRequestParameter('aid');
00146 if ($sArticleId && ($aItems = $this->getCompareItems())) {
00147 $sNextArticleId = 0;
00148
00149 $blFound = false;
00150 foreach ($aItems as $sOxid => $sVal) {
00151 if ($blFound) {
00152 $sNextArticleId = $sOxid;
00153 $blFound = false;
00154 }
00155 if ($sOxid == $sArticleId) {
00156 $blFound = true;
00157 }
00158 }
00159
00160 if ($sNextArticleId) {
00161
00162 $aNewItems = array();
00163 foreach ($aItems as $sOxid => $sVal) {
00164 if ($sOxid == $sArticleId) {
00165 $aNewItems[$sNextArticleId] = true;
00166 } elseif ($sOxid == $sNextArticleId) {
00167 $aNewItems[$sArticleId] = true;
00168 } else {
00169 $aNewItems[$sOxid] = true;
00170 }
00171 }
00172 $this->setCompareItems($aNewItems);
00173 }
00174 }
00175 }
00176
00180 public function inPopup()
00181 {
00182 $this->_sThisTemplate = 'compare_popup.tpl';
00183 $this->_iArticlesPerPage = -1;
00184 }
00185
00191 public function setCompareItemsCnt($iCount)
00192 {
00193 $this->_iCompItemsCnt = $iCount;
00194 }
00195
00201 public function getCompareItemsCnt()
00202 {
00203 if ($this->_iCompItemsCnt === null) {
00204 $this->_iCompItemsCnt = 0;
00205 if ($aItems = $this->getCompareItems()) {
00206 $this->_iCompItemsCnt = count($aItems);
00207 }
00208 }
00209
00210 return $this->_iCompItemsCnt;
00211 }
00212
00218 public function getCompareItems()
00219 {
00220 if ($this->_aCompItems === null) {
00221 $aItems = oxRegistry::getSession()->getVariable('aFiltcompproducts');
00222 if (is_array($aItems) && count($aItems)) {
00223 $this->_aCompItems = $aItems;
00224 }
00225 }
00226
00227 return $this->_aCompItems;
00228 }
00229
00235 public function setCompareItems($aItems)
00236 {
00237 $this->_aCompItems = $aItems;
00238 oxRegistry::getSession()->setVariable('aFiltcompproducts', $aItems);
00239 }
00240
00246 protected function _setArticlesPerPage($iNumber)
00247 {
00248 $this->_iArticlesPerPage = $iNumber;
00249 }
00250
00254 public function setNoPaging()
00255 {
00256 $this->_setArticlesPerPage(0);
00257 }
00258
00259
00266 public function getCompArtList()
00267 {
00268 if ($this->_oArtList === null) {
00269 if (($aItems = $this->getCompareItems())) {
00270
00271 $oList = oxNew('oxarticlelist');
00272 $oList->loadIds(array_keys($aItems));
00273
00274
00275 if ($this->_iArticlesPerPage > 0) {
00276 $this->_iCntPages = round($oList->count() / $this->_iArticlesPerPage + 0.49);
00277 $aItems = $this->_removeArticlesFromPage($aItems, $oList);
00278 }
00279
00280 $this->_oArtList = $this->_changeArtListOrder($aItems, $oList);
00281 }
00282 }
00283
00284 return $this->_oArtList;
00285 }
00286
00292 public function getAttributeList()
00293 {
00294 if ($this->_oAttributeList === null) {
00295 $this->_oAttributeList = false;
00296 if ($oArtList = $this->getCompArtList()) {
00297 $oAttributeList = oxNew('oxattributelist');
00298 $this->_oAttributeList = $oAttributeList->loadAttributesByIds(array_keys($oArtList));
00299 }
00300 }
00301
00302 return $this->_oAttributeList;
00303 }
00304
00310 public function getSimilarRecommListIds()
00311 {
00312 if ($this->_aSimilarRecommListIds === null) {
00313 $this->_aSimilarRecommListIds = false;
00314
00315 if ($oArtList = $this->getCompArtList()) {
00316 $this->_aSimilarRecommListIds = array_keys($oArtList);
00317 }
00318 }
00319
00320 return $this->_aSimilarRecommListIds;
00321 }
00322
00328 public function getPageNavigation()
00329 {
00330 if ($this->_oPageNavigation === null) {
00331 $this->_oPageNavigation = false;
00332 $this->_oPageNavigation = $this->generatePageNavigation();
00333 }
00334
00335 return $this->_oPageNavigation;
00336 }
00337
00346 protected function _removeArticlesFromPage($aItems, $oList)
00347 {
00348
00349
00350 $aListKeys = $oList->arrayKeys();
00351 $aItemKeys = array_keys($aItems);
00352 $aKeys = array_intersect($aItemKeys, $aListKeys);
00353 $aNewItems = array();
00354 $iActPage = $this->getActPage();
00355 for ($i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++) {
00356 if (!isset($aKeys[$i])) {
00357 break;
00358 }
00359 $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
00360 }
00361
00362 return $aNewItems;
00363 }
00364
00373 protected function _changeArtListOrder($aItems, $oList)
00374 {
00375
00376 $oNewList = array();
00377 $iCnt = 0;
00378 $iActPage = $this->getActPage();
00379 foreach ($aItems as $sOxid => $sVal) {
00380
00381
00382 if (!isset ($oList[$sOxid])) {
00383 continue;
00384 }
00385
00386 $iCnt++;
00387 $oNewList[$sOxid] = $oList[$sOxid];
00388
00389
00390 $oNewList[$sOxid]->hidePrev = false;
00391 if ($iActPage == 0 && $iCnt == 1) {
00392 $oNewList[$sOxid]->hidePrev = true;
00393 }
00394
00395
00396 $oNewList[$sOxid]->hideNext = false;
00397 if (($iActPage + 1) == $this->_iCntPages && $iCnt == count($aItems)) {
00398 $oNewList[$sOxid]->hideNext = true;
00399 }
00400 }
00401
00402 return $oNewList;
00403 }
00404
00410 public function getOrderCnt()
00411 {
00412 if ($this->_iOrderCnt === null) {
00413 $this->_iOrderCnt = 0;
00414 if ($oUser = $this->getUser()) {
00415 $this->_iOrderCnt = $oUser->getOrderCount();
00416 }
00417 }
00418
00419 return $this->_iOrderCnt;
00420 }
00421
00427 public function getBreadCrumb()
00428 {
00429 $aPaths = array();
00430 $aPath = array();
00431
00432 $aPath['title'] = oxRegistry::getLang()->translateString('MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false);
00433 $aPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl($this->getViewConfig()->getSelfLink() . 'cl=account');
00434 $aPaths[] = $aPath;
00435
00436 $aPath['title'] = oxRegistry::getLang()->translateString('PRODUCT_COMPARISON', oxRegistry::getLang()->getBaseLanguage(), false);
00437 $aPath['link'] = $this->getLink();
00438 $aPaths[] = $aPath;
00439
00440 return $aPaths;
00441 }
00442 }