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 $_blBargainAction = true;
00068 
00073     protected $_blShowTagCloud = false;
00074 
00075 
00080     protected $_sThisTemplate = 'page/compare/compare.tpl';
00081 
00087     protected $_aSimilarRecommListIds = null;
00088 
00089 
00095     public function moveLeft() //#777C
00096     {
00097         $sArticleId = oxConfig::getParameter( 'aid' );
00098         if ( $sArticleId && ( $aItems = $this->getCompareItems() ) ) {
00099             $sPrevArticleId = null;
00100 
00101             $blFound = false;
00102             foreach ( $aItems as $sOxid => $sVal ) {
00103                 if ( $sOxid == $sArticleId ) {
00104                     $blFound = true;
00105                 }
00106                 if ( !$blFound ) {
00107                     $sPrevArticleId = $sOxid;
00108                 }
00109             }
00110 
00111             if ( $sPrevArticleId ) {
00112 
00113                 $aNewItems = array();
00114                 foreach ( $aItems as $sOxid => $sVal ) {
00115                     if ( $sOxid == $sPrevArticleId ) {
00116                         $aNewItems[$sArticleId] = true;
00117                     } elseif ( $sOxid == $sArticleId ) {
00118                         $aNewItems[$sPrevArticleId] = true;
00119                     } else {
00120                         $aNewItems[$sOxid] = true;
00121                     }
00122                 }
00123 
00124                 $this->setCompareItems($aNewItems);
00125             }
00126         }
00127     }
00128 
00134     public function moveRight()  //#777C
00135     {
00136         $sArticleId = oxConfig::getParameter( 'aid' );
00137         if ( $sArticleId && ( $aItems = $this->getCompareItems() ) ) {
00138             $sNextArticleId = 0;
00139 
00140             $blFound = false;
00141             foreach ( $aItems as $sOxid => $sVal ) {
00142                 if ( $blFound ) {
00143                     $sNextArticleId = $sOxid;
00144                     $blFound = false;
00145                 }
00146                 if ( $sOxid == $sArticleId ) {
00147                     $blFound = true;
00148                 }
00149             }
00150 
00151             if ( $sNextArticleId ) {
00152 
00153                 $aNewItems = array();
00154                 foreach ( $aItems as $sOxid => $sVal ) {
00155                     if ( $sOxid == $sArticleId ) {
00156                         $aNewItems[$sNextArticleId] = true;
00157                     } elseif ( $sOxid == $sNextArticleId ) {
00158                         $aNewItems[$sArticleId] = true;
00159                     } else {
00160                         $aNewItems[$sOxid] = true;
00161                     }
00162                 }
00163                 $this->setCompareItems($aNewItems);
00164             }
00165         }
00166     }
00167 
00173     public function inPopup() // #777C
00174     {
00175         $this->_sThisTemplate = 'compare_popup.tpl';
00176         $this->_iArticlesPerPage = -1;
00177     }
00178 
00186     public function setCompareItemsCnt( $iCount )
00187     {
00188         $this->_iCompItemsCnt = $iCount;
00189     }
00190 
00196     public function getCompareItemsCnt()
00197     {
00198         if ( $this->_iCompItemsCnt === null ) {
00199             $this->_iCompItemsCnt = 0;
00200             if ( $aItems = $this->getCompareItems() ) {
00201                 $this->_iCompItemsCnt = count( $aItems );
00202             }
00203         }
00204         return $this->_iCompItemsCnt;
00205     }
00206 
00212     public function getCompareItems()
00213     {
00214         if ( $this->_aCompItems === null ) {
00215             $aItems = oxSession::getVar( 'aFiltcompproducts' );
00216             if ( is_array($aItems) && count($aItems) ) {
00217                 $this->_aCompItems = $aItems;
00218             }
00219         }
00220         return $this->_aCompItems;
00221     }
00222 
00230     public function setCompareItems( $aItems)
00231     {
00232         $this->_aCompItems = $aItems;
00233         oxSession::setVar( 'aFiltcompproducts', $aItems );
00234     }
00235 
00243     protected function _setArticlesPerPage( $iNumber)
00244     {
00245         $this->_iArticlesPerPage = $iNumber;
00246     }
00247 
00253     public function setNoPaging()
00254     {
00255         $this->_setArticlesPerPage(0);
00256     }
00257 
00258 
00265     public function getCompArtList()
00266     {
00267         if ( $this->_oArtList === null ) {
00268             if ( ( $aItems = $this->getCompareItems() ) ) {
00269                 // counts how many pages
00270                 $oList = oxNew( 'oxarticlelist' );
00271                 $oList->loadIds( array_keys( $aItems ) );
00272 
00273                 // cut page articles
00274                 if ( $this->_iArticlesPerPage > 0 ) {
00275                     $this->_iCntPages = round( $oList->count() / $this->_iArticlesPerPage + 0.49 );
00276                     $aItems = $this->_removeArticlesFromPage( $aItems, $oList );
00277                 }
00278 
00279                 $this->_oArtList = $this->_changeArtListOrder( $aItems, $oList );
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 getSimilarRecommListIds()
00309     {
00310         if ( $this->_aSimilarRecommListIds === null ) {
00311             $this->_aSimilarRecommListIds = false;
00312 
00313             if ( $oArtList = $this->getCompArtList() ) {
00314                 $this->_aSimilarRecommListIds = array_keys( $oArtList );
00315             }
00316         }
00317         return $this->_aSimilarRecommListIds;
00318     }
00319 
00325     public function getPageNavigation()
00326     {
00327         if ( $this->_oPageNavigation === null ) {
00328             $this->_oPageNavigation = false;
00329             $this->_oPageNavigation = $this->generatePageNavigation();
00330         }
00331         return $this->_oPageNavigation;
00332     }
00333 
00342     protected function _removeArticlesFromPage( $aItems, $oList )
00343     {
00344         //#1106S $aItems changed to $oList.
00345         //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
00346         $aListKeys = $oList->arrayKeys();
00347         $aItemKeys = array_keys($aItems);
00348         $aKeys = array_intersect( $aItemKeys, $aListKeys );
00349         $aNewItems = array();
00350         $iActPage = $this->getActPage();
00351         for ( $i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++ ) {
00352             if ( !isset($aKeys[$i])) {
00353                 break;
00354             }
00355             $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
00356         }
00357         return $aNewItems;
00358     }
00359 
00368     protected function _changeArtListOrder( $aItems, $oList )
00369     {
00370         // #777C changing order of list elements, according to $aItems
00371         $oNewList = array();
00372         $iCnt = 0;
00373         $iActPage = $this->getActPage();
00374         foreach ( $aItems as $sOxid => $sVal ) {
00375 
00376             //#4391T, skipping non loaded products
00377             if (!isset ($oList[$sOxid]) ) {
00378                 continue;
00379             }
00380 
00381             $iCnt++;
00382             $oNewList[$sOxid] = $oList[$sOxid];
00383 
00384             // hide arrow if article is first in the list
00385             $oNewList[$sOxid]->hidePrev = false;
00386             if ( $iActPage == 0 && $iCnt==1 ) {
00387                 $oNewList[$sOxid]->hidePrev = true;
00388             }
00389 
00390             // hide arrow if article is last in the list
00391             $oNewList[$sOxid]->hideNext = false;
00392             if ( ( $iActPage + 1 ) == $this->_iCntPages && $iCnt == count( $aItems ) ) {
00393                 $oNewList[$sOxid]->hideNext = true;
00394             }
00395         }
00396         return $oNewList;
00397     }
00398 
00404     public function getOrderCnt()
00405     {
00406         if ( $this->_iOrderCnt === null ) {
00407             $this->_iOrderCnt = 0;
00408             if ( $oUser = $this->getUser() ) {
00409                 $this->_iOrderCnt = $oUser->getOrderCount();
00410             }
00411         }
00412         return $this->_iOrderCnt;
00413     }
00414 
00420     public function getBreadCrumb()
00421     {
00422         $aPaths = array();
00423         $aPath = array();
00424 
00425         $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_ACCOUNT_MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false );
00426         $aPath['link']  = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00427         $aPaths[] = $aPath;
00428 
00429         $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_PRODUCT_COMPARE_TITLE', oxRegistry::getLang()->getBaseLanguage(), false );
00430         $aPath['link']  = $this->getLink();
00431         $aPaths[] = $aPath;
00432 
00433         return $aPaths;
00434     }
00435 }