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         
00258         
00259         if ( $this->_oArtList === null ) {
00260 
00261 
00262             if ( $aItems = $this->getCompareItems()) {
00263 
00264 
00265                 $oList = oxNew( 'oxarticlelist' );
00266 
00267 
00268                 // counts how many pages
00269                 $oList->loadIds( array_keys( $aItems ) );
00270 
00271                     // cut page articles
00272                     if ( $this->_iArticlesPerPage > 0 ) {
00273                         $this->_iCntPages = round( $oList->count() / $this->_iArticlesPerPage + 0.49 );
00274                         $aItems = $this->_removeArticlesFromPage( $aItems, $oList );
00275                     }
00276 
00277                 $this->_oArtList = $this->_changeArtListOrder( $aItems, $oList );
00278 
00279             }
00280         }
00281 
00282 
00283         return $this->_oArtList;
00284     }
00285 
00291     public function getAttributeList()
00292     {
00293         if ( $this->_oAttributeList === null ) {
00294             $this->_oAttributeList = false;
00295             if ( $oArtList = $this->getCompArtList()) {
00296                 $oAttributeList = oxNew( 'oxattributelist' );
00297                 $this->_oAttributeList = $oAttributeList->loadAttributesByIds( array_keys( $oArtList ) );
00298             }
00299         }
00300         return $this->_oAttributeList;
00301     }
00302 
00308     public function getSimilarRecommLists()
00309     {
00310         if (!$this->getViewConfig()->getShowListmania()) {
00311             return false;
00312         }
00313 
00314         if ( $this->_oRecommList === null ) {
00315             $this->_oRecommList = false;
00316             if ( $oArtList = $this->getCompArtList()) {
00317                 $this->_oRecommList = oxNew('oxrecommlist');
00318                 $this->_oRecommList = $this->_oRecommList->getRecommListsByIds( array_keys( $oArtList ));
00319             }
00320         }
00321         return $this->_oRecommList;
00322     }
00323 
00329     public function getPageNavigation()
00330     {
00331         if ( $this->_oPageNavigation === null ) {
00332             $this->_oPageNavigation = false;
00333             $this->_oPageNavigation = $this->generatePageNavigation();
00334         }
00335         return $this->_oPageNavigation;
00336     }
00337 
00346     protected function _removeArticlesFromPage( $aItems, $oList )
00347     {
00348         //#1106S $aItems changed to $oList.
00349         //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
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         return $aNewItems;
00362     }
00363 
00372     protected function _changeArtListOrder( $aItems, $oList )
00373     {
00374         // #777C changing order of list elements, according to $aItems
00375         $oNewList = array();
00376         $iCnt = 0;
00377         $iActPage = $this->getActPage();
00378         foreach ( $aItems as $sOxid => $sVal ) {
00379             $iCnt++;
00380             $oNewList[$sOxid] = $oList[$sOxid];
00381 
00382             // hide arrow if article is first in the list
00383             $oNewList[$sOxid]->hidePrev = false;
00384             if ( $iActPage == 0 && $iCnt==1 ) {
00385                 $oNewList[$sOxid]->hidePrev = true;
00386             }
00387 
00388             // hide arrow if article is last in the list
00389             $oNewList[$sOxid]->hideNext = false;
00390             if ( ( $iActPage + 1 ) == $this->_iCntPages && $iCnt == count( $aItems ) ) {
00391                 $oNewList[$sOxid]->hideNext = true;
00392             }
00393         }
00394         return $oNewList;
00395     }
00396 
00402     public function getOrderCnt()
00403     {
00404         if ( $this->_iOrderCnt === null ) {
00405             $this->_iOrderCnt = 0;
00406             if ( $oUser = $this->getUser() ) {
00407                 $this->_iOrderCnt = $oUser->getOrderCount();
00408             }
00409         }
00410         return $this->_iOrderCnt;
00411     }
00412 
00418     public function getBreadCrumb()
00419     {
00420         $aPaths = array();
00421         $aPath = array();
00422 
00423         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_ACCOUNT_MY_ACCOUNT', oxLang::getInstance()->getBaseLanguage(), false );
00424         $aPath['link']  = oxSeoEncoder::getInstance()->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00425         $aPaths[] = $aPath;
00426 
00427         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_PRODUCT_COMPARE_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
00428         $aPath['link']  = $this->getLink();
00429         $aPaths[] = $aPath;
00430 
00431         return $aPaths;
00432     }
00433 
00434 }