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     public function moveLeft() //#777C
00094     {
00095         $sArticleId = oxConfig::getParameter( 'aid' );
00096         if ( $sArticleId && ( $aItems = $this->getCompareItems() ) ) {
00097             $sPrevArticleId = null;
00098 
00099             $blFound = false;
00100             foreach ( $aItems as $sOxid => $sVal ) {
00101                 if ( $sOxid == $sArticleId ) {
00102                     $blFound = true;
00103                 }
00104                 if ( !$blFound ) {
00105                     $sPrevArticleId = $sOxid;
00106                 }
00107             }
00108 
00109             if ( $sPrevArticleId ) {
00110 
00111                 $aNewItems = array();
00112                 foreach ( $aItems as $sOxid => $sVal ) {
00113                     if ( $sOxid == $sPrevArticleId ) {
00114                         $aNewItems[$sArticleId] = true;
00115                     } elseif ( $sOxid == $sArticleId ) {
00116                         $aNewItems[$sPrevArticleId] = true;
00117                     } else {
00118                         $aNewItems[$sOxid] = true;
00119                     }
00120                 }
00121 
00122                 $this->setCompareItems($aNewItems);
00123             }
00124         }
00125     }
00126 
00132     public function moveRight()  //#777C
00133     {
00134         $sArticleId = oxConfig::getParameter( 'aid' );
00135         if ( $sArticleId && ( $aItems = $this->getCompareItems() ) ) {
00136             $sNextArticleId = 0;
00137 
00138             $blFound = false;
00139             foreach ( $aItems as $sOxid => $sVal ) {
00140                 if ( $blFound ) {
00141                     $sNextArticleId = $sOxid;
00142                     $blFound = false;
00143                 }
00144                 if ( $sOxid == $sArticleId ) {
00145                     $blFound = true;
00146                 }
00147             }
00148 
00149             if ( $sNextArticleId ) {
00150 
00151                 $aNewItems = array();
00152                 foreach ( $aItems as $sOxid => $sVal ) {
00153                     if ( $sOxid == $sArticleId ) {
00154                         $aNewItems[$sNextArticleId] = true;
00155                     } elseif ( $sOxid == $sNextArticleId ) {
00156                         $aNewItems[$sArticleId] = true;
00157                     } else {
00158                         $aNewItems[$sOxid] = true;
00159                     }
00160                 }
00161                 $this->setCompareItems($aNewItems);
00162             }
00163         }
00164     }
00165 
00171     public function inPopup() // #777C
00172     {
00173         $this->_sThisTemplate = 'compare_popup.tpl';
00174         $this->_iArticlesPerPage = -1;
00175     }
00176 
00182     public function getCompareItemsCnt()
00183     {
00184         if ( $this->_iCompItemsCnt === null ) {
00185             $this->_iCompItemsCnt = 0;
00186             if ( $aItems = $this->getCompareItems() ) {
00187                 $this->_iCompItemsCnt = count( $aItems );
00188             }
00189         }
00190         return $this->_iCompItemsCnt;
00191     }
00192 
00198     public function getCompareItems()
00199     {
00200 
00201         if ( $this->_aCompItems === null ) {
00202 
00203             $aItems = oxSession::getVar( 'aFiltcompproducts' );
00204 
00205             if ( is_array( $aItems ) && count( $aItems ) ) {
00206 
00207                 $this->_aCompItems = $aItems;
00208             }
00209         }
00210         return $this->_aCompItems;
00211     }
00212 
00220     public function setCompareItems( $aItems)
00221     {
00222         $this->_aCompItems = $aItems;
00223         oxSession::setVar( 'aFiltcompproducts', $aItems );
00224     }
00225 
00233     protected function _setArticlesPerPage( $iNumber)
00234     {
00235         $this->_iArticlesPerPage = $iNumber;
00236     }
00237 
00243     public function setNoPaging()
00244     {
00245         $this->_setArticlesPerPage(0);
00246     }
00247 
00248 
00255     public function getCompArtList()
00256     {
00257         if ( $this->_oArtList === null ) {
00258             if ( ( $aItems = $this->getCompareItems() ) ) {
00259                 // counts how many pages
00260                 $oList = oxNew( 'oxarticlelist' );
00261                 $oList->loadIds( array_keys( $aItems ) );
00262 
00263                 // cut page articles
00264                 if ( $this->_iArticlesPerPage > 0 ) {
00265                     $this->_iCntPages = round( $oList->count() / $this->_iArticlesPerPage + 0.49 );
00266                     $aItems = $this->_removeArticlesFromPage( $aItems, $oList );
00267                 }
00268 
00269                 $this->_oArtList = $this->_changeArtListOrder( $aItems, $oList );
00270             }
00271         }
00272 
00273         return $this->_oArtList;
00274     }
00275 
00281     public function getAttributeList()
00282     {
00283         if ( $this->_oAttributeList === null ) {
00284             $this->_oAttributeList = false;
00285             if ( $oArtList = $this->getCompArtList()) {
00286                 $oAttributeList = oxNew( 'oxattributelist' );
00287                 $this->_oAttributeList = $oAttributeList->loadAttributesByIds( array_keys( $oArtList ) );
00288             }
00289         }
00290         return $this->_oAttributeList;
00291     }
00292 
00298     public function getSimilarRecommLists()
00299     {
00300         if (!$this->getViewConfig()->getShowListmania()) {
00301             return false;
00302         }
00303 
00304         if ( $this->_oRecommList === null ) {
00305             $this->_oRecommList = false;
00306             if ( $oArtList = $this->getCompArtList()) {
00307                 $this->_oRecommList = oxNew('oxrecommlist');
00308                 $this->_oRecommList = $this->_oRecommList->getRecommListsByIds( array_keys( $oArtList ));
00309             }
00310         }
00311         return $this->_oRecommList;
00312     }
00313 
00319     public function getPageNavigation()
00320     {
00321         if ( $this->_oPageNavigation === null ) {
00322             $this->_oPageNavigation = false;
00323             $this->_oPageNavigation = $this->generatePageNavigation();
00324         }
00325         return $this->_oPageNavigation;
00326     }
00327 
00336     protected function _removeArticlesFromPage( $aItems, $oList )
00337     {
00338         //#1106S $aItems changed to $oList.
00339         //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
00340         $aListKeys = $oList->arrayKeys();
00341         $aItemKeys = array_keys($aItems);
00342         $aKeys = array_intersect( $aItemKeys, $aListKeys );
00343         $aNewItems = array();
00344         $iActPage = $this->getActPage();
00345         for ( $i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++ ) {
00346             if ( !isset($aKeys[$i])) {
00347                 break;
00348             }
00349             $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
00350         }
00351         return $aNewItems;
00352     }
00353 
00362     protected function _changeArtListOrder( $aItems, $oList )
00363     {
00364         // #777C changing order of list elements, according to $aItems
00365         $oNewList = array();
00366         $iCnt = 0;
00367         $iActPage = $this->getActPage();
00368         foreach ( $aItems as $sOxid => $sVal ) {
00369             $iCnt++;
00370             $oNewList[$sOxid] = $oList[$sOxid];
00371 
00372             // hide arrow if article is first in the list
00373             $oNewList[$sOxid]->hidePrev = false;
00374             if ( $iActPage == 0 && $iCnt==1 ) {
00375                 $oNewList[$sOxid]->hidePrev = true;
00376             }
00377 
00378             // hide arrow if article is last in the list
00379             $oNewList[$sOxid]->hideNext = false;
00380             if ( ( $iActPage + 1 ) == $this->_iCntPages && $iCnt == count( $aItems ) ) {
00381                 $oNewList[$sOxid]->hideNext = true;
00382             }
00383         }
00384         return $oNewList;
00385     }
00386 
00392     public function getOrderCnt()
00393     {
00394         if ( $this->_iOrderCnt === null ) {
00395             $this->_iOrderCnt = 0;
00396             if ( $oUser = $this->getUser() ) {
00397                 $this->_iOrderCnt = $oUser->getOrderCount();
00398             }
00399         }
00400         return $this->_iOrderCnt;
00401     }
00402 
00408     public function getBreadCrumb()
00409     {
00410         $aPaths = array();
00411         $aPath = array();
00412 
00413         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_ACCOUNT_MY_ACCOUNT', oxLang::getInstance()->getBaseLanguage(), false );
00414         $aPath['link']  = oxSeoEncoder::getInstance()->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00415         $aPaths[] = $aPath;
00416 
00417         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_COMPARE_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
00418         $aPath['link']  = $this->getLink();
00419         $aPaths[] = $aPath;
00420 
00421         return $aPaths;
00422     }
00423 
00424 }