compare.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Compare extends oxUBase
00008 {
00013     protected $_iCntPages = 1;
00014 
00019     protected $_iOrderCnt = null;
00020 
00025     protected $_iArticlesPerPage = 3;
00026 
00031     protected $_iCompItemsCnt = null;
00032 
00037     protected $_aCompItems = null;
00038 
00043     protected $_oArtList = null;
00044 
00049     protected $_oAttributeList = null;
00050 
00055     protected $_oRecommList = null;
00056 
00061     protected $_oPageNavigation = null;
00062 
00067     protected $_blTop5Action = false;
00068 
00073     protected $_blBargainAction = true;
00074 
00079     protected $_blShowTagCloud = false;
00080 
00081 
00086     protected $_sThisTemplate = 'page/compare/compare.tpl';
00087 
00093     protected $_aSimilarRecommListIds = null;
00094 
00095 
00101     public function moveLeft() //#777C
00102     {
00103         $sArticleId = oxConfig::getParameter( 'aid' );
00104         if ( $sArticleId && ( $aItems = $this->getCompareItems() ) ) {
00105             $sPrevArticleId = null;
00106 
00107             $blFound = false;
00108             foreach ( $aItems as $sOxid => $sVal ) {
00109                 if ( $sOxid == $sArticleId ) {
00110                     $blFound = true;
00111                 }
00112                 if ( !$blFound ) {
00113                     $sPrevArticleId = $sOxid;
00114                 }
00115             }
00116 
00117             if ( $sPrevArticleId ) {
00118 
00119                 $aNewItems = array();
00120                 foreach ( $aItems as $sOxid => $sVal ) {
00121                     if ( $sOxid == $sPrevArticleId ) {
00122                         $aNewItems[$sArticleId] = true;
00123                     } elseif ( $sOxid == $sArticleId ) {
00124                         $aNewItems[$sPrevArticleId] = true;
00125                     } else {
00126                         $aNewItems[$sOxid] = true;
00127                     }
00128                 }
00129 
00130                 $this->setCompareItems($aNewItems);
00131             }
00132         }
00133     }
00134 
00140     public function moveRight()  //#777C
00141     {
00142         $sArticleId = oxConfig::getParameter( 'aid' );
00143         if ( $sArticleId && ( $aItems = $this->getCompareItems() ) ) {
00144             $sNextArticleId = 0;
00145 
00146             $blFound = false;
00147             foreach ( $aItems as $sOxid => $sVal ) {
00148                 if ( $blFound ) {
00149                     $sNextArticleId = $sOxid;
00150                     $blFound = false;
00151                 }
00152                 if ( $sOxid == $sArticleId ) {
00153                     $blFound = true;
00154                 }
00155             }
00156 
00157             if ( $sNextArticleId ) {
00158 
00159                 $aNewItems = array();
00160                 foreach ( $aItems as $sOxid => $sVal ) {
00161                     if ( $sOxid == $sArticleId ) {
00162                         $aNewItems[$sNextArticleId] = true;
00163                     } elseif ( $sOxid == $sNextArticleId ) {
00164                         $aNewItems[$sArticleId] = true;
00165                     } else {
00166                         $aNewItems[$sOxid] = true;
00167                     }
00168                 }
00169                 $this->setCompareItems($aNewItems);
00170             }
00171         }
00172     }
00173 
00179     public function inPopup() // #777C
00180     {
00181         $this->_sThisTemplate = 'compare_popup.tpl';
00182         $this->_iArticlesPerPage = -1;
00183     }
00184 
00192     public function setCompareItemsCnt( $iCount )
00193     {
00194         $this->_iCompItemsCnt = $iCount;
00195     }
00196 
00202     public function getCompareItemsCnt()
00203     {
00204         if ( $this->_iCompItemsCnt === null ) {
00205             $this->_iCompItemsCnt = 0;
00206             if ( $aItems = $this->getCompareItems() ) {
00207                 $this->_iCompItemsCnt = count( $aItems );
00208             }
00209         }
00210         return $this->_iCompItemsCnt;
00211     }
00212 
00218     public function getCompareItems()
00219     {
00220         if ( $this->_aCompItems === null ) {
00221             $aItems = oxSession::getVar( 'aFiltcompproducts' );
00222             if ( is_array($aItems) && count($aItems) ) {
00223                 $this->_aCompItems = $aItems;
00224             }
00225         }
00226         return $this->_aCompItems;
00227     }
00228 
00236     public function setCompareItems( $aItems)
00237     {
00238         $this->_aCompItems = $aItems;
00239         oxSession::setVar( 'aFiltcompproducts', $aItems );
00240     }
00241 
00249     protected function _setArticlesPerPage( $iNumber)
00250     {
00251         $this->_iArticlesPerPage = $iNumber;
00252     }
00253 
00259     public function setNoPaging()
00260     {
00261         $this->_setArticlesPerPage(0);
00262     }
00263 
00264 
00271     public function getCompArtList()
00272     {
00273         if ( $this->_oArtList === null ) {
00274             if ( ( $aItems = $this->getCompareItems() ) ) {
00275                 // counts how many pages
00276                 $oList = oxNew( 'oxarticlelist' );
00277                 $oList->loadIds( array_keys( $aItems ) );
00278 
00279                 // cut page articles
00280                 if ( $this->_iArticlesPerPage > 0 ) {
00281                     $this->_iCntPages = round( $oList->count() / $this->_iArticlesPerPage + 0.49 );
00282                     $aItems = $this->_removeArticlesFromPage( $aItems, $oList );
00283                 }
00284 
00285                 $this->_oArtList = $this->_changeArtListOrder( $aItems, $oList );
00286             }
00287         }
00288 
00289         return $this->_oArtList;
00290     }
00291 
00297     public function getAttributeList()
00298     {
00299         if ( $this->_oAttributeList === null ) {
00300             $this->_oAttributeList = false;
00301             if ( $oArtList = $this->getCompArtList()) {
00302                 $oAttributeList = oxNew( 'oxattributelist' );
00303                 $this->_oAttributeList = $oAttributeList->loadAttributesByIds( array_keys( $oArtList ) );
00304             }
00305         }
00306         return $this->_oAttributeList;
00307     }
00308 
00314     public function getSimilarRecommListIds()
00315     {
00316         if ( $this->_aSimilarRecommListIds === null ) {
00317             $this->_aSimilarRecommListIds = false;
00318 
00319             if ( $oArtList = $this->getCompArtList() ) {
00320                 $this->_aSimilarRecommListIds = array_keys( $oArtList );
00321             }
00322         }
00323         return $this->_aSimilarRecommListIds;
00324     }
00325 
00331     public function getPageNavigation()
00332     {
00333         if ( $this->_oPageNavigation === null ) {
00334             $this->_oPageNavigation = false;
00335             $this->_oPageNavigation = $this->generatePageNavigation();
00336         }
00337         return $this->_oPageNavigation;
00338     }
00339 
00348     protected function _removeArticlesFromPage( $aItems, $oList )
00349     {
00350         //#1106S $aItems changed to $oList.
00351         //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
00352         $aListKeys = $oList->arrayKeys();
00353         $aItemKeys = array_keys($aItems);
00354         $aKeys = array_intersect( $aItemKeys, $aListKeys );
00355         $aNewItems = array();
00356         $iActPage = $this->getActPage();
00357         for ( $i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++ ) {
00358             if ( !isset($aKeys[$i])) {
00359                 break;
00360             }
00361             $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
00362         }
00363         return $aNewItems;
00364     }
00365 
00374     protected function _changeArtListOrder( $aItems, $oList )
00375     {
00376         // #777C changing order of list elements, according to $aItems
00377         $oNewList = array();
00378         $iCnt = 0;
00379         $iActPage = $this->getActPage();
00380         foreach ( $aItems as $sOxid => $sVal ) {
00381 
00382             //#4391T, skipping non loaded products
00383             if (!isset ($oList[$sOxid]) ) {
00384                 continue;
00385             }
00386 
00387             $iCnt++;
00388             $oNewList[$sOxid] = $oList[$sOxid];
00389 
00390             // hide arrow if article is first in the list
00391             $oNewList[$sOxid]->hidePrev = false;
00392             if ( $iActPage == 0 && $iCnt==1 ) {
00393                 $oNewList[$sOxid]->hidePrev = true;
00394             }
00395 
00396             // hide arrow if article is last in the list
00397             $oNewList[$sOxid]->hideNext = false;
00398             if ( ( $iActPage + 1 ) == $this->_iCntPages && $iCnt == count( $aItems ) ) {
00399                 $oNewList[$sOxid]->hideNext = true;
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         return $this->_iOrderCnt;
00419     }
00420 
00426     public function getBreadCrumb()
00427     {
00428         $aPaths = array();
00429         $aPath = array();
00430 
00431         $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_ACCOUNT_MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false );
00432         $aPath['link']  = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00433         $aPaths[] = $aPath;
00434 
00435         $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_PRODUCT_COMPARE_TITLE', oxRegistry::getLang()->getBaseLanguage(), false );
00436         $aPath['link']  = $this->getLink();
00437         $aPaths[] = $aPath;
00438 
00439         return $aPaths;
00440     }
00441 }