compare.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Compare extends oxUBase
00008 {
00013     protected $_iCntPages = null;
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 = true;
00068 
00073     protected $_blBargainAction = true;
00074 
00079     protected $_sThisTemplate = 'compare.tpl';
00080 
00091     public function render()
00092     {
00093         parent::render();
00094 
00095         //add amount of compared items to view data
00096         $this->_aViewData['oxcmp_compare'] = $this->getCompareItemsCnt();
00097 
00098         $this->getCompArtList();
00099         // load article list in comparison
00100         $this->_aViewData['articlelist'] = $this->getCompArtList();
00101 
00102         // load all attributes for articles
00103         $this->_aViewData['allartattr'] = $this->getAttributeList();
00104 
00105         // page navigation object
00106         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00107 
00108         $this->_aViewData['pgNr'] = $this->getActPage();
00109 
00110         // recomm products list
00111         $this->_aViewData['similarrecommlist']  = $this->getSimilarRecommLists();
00112 
00113         // calculating amount of orders made by user
00114         $this->_aViewData['iordersmade'] = $this->getOrderCnt();
00115 
00116         // loading actions
00117         $this->_loadActions();
00118 
00119         return $this->_sThisTemplate;
00120     }
00121 
00127     public function moveLeft() //#777C
00128     {
00129         if ( $aItems = $this->getCompareItems() ) {
00130             $sArticleId = oxConfig::getParameter( 'aid' );
00131             $sPrevArticleId = null;
00132 
00133             $blFound = false;
00134             foreach ( $aItems as $sOxid => $sVal ) {
00135                 if ( $sOxid == $sArticleId ) {
00136                     $blFound = true;
00137                 }
00138                 if ( !$blFound ) {
00139                     $sPrevArticleId = $sOxid;
00140                 }
00141             }
00142 
00143             if ( $sPrevArticleId ) {
00144 
00145                 $aNewItems = array();
00146                 foreach ( $aItems as $sOxid => $sVal ) {
00147                     if ( $sOxid == $sPrevArticleId ) {
00148                         $aNewItems[$sArticleId] = true;
00149                     } elseif ( $sOxid == $sArticleId ) {
00150                         $aNewItems[$sPrevArticleId] = true;
00151                     } else {
00152                         $aNewItems[$sOxid] = true;
00153                     }
00154                 }
00155 
00156                 $this->setCompareItems($aNewItems);
00157             }
00158         }
00159     }
00160 
00166     public function moveRight()  //#777C
00167     {
00168         if ( $aItems = $this->getCompareItems() ) {
00169             $sArticleId = oxConfig::getParameter( 'aid' );
00170             $sNextArticleId = 0;
00171 
00172             $blFound = false;
00173             foreach ( $aItems as $sOxid => $sVal ) {
00174                 if ( $blFound ) {
00175                     $sNextArticleId = $sOxid;
00176                     $blFound = false;
00177                 }
00178                 if ( $sOxid == $sArticleId ) {
00179                     $blFound = true;
00180                 }
00181             }
00182 
00183             if ( $sNextArticleId ) {
00184 
00185                 $aNewItems = array();
00186                 foreach ( $aItems as $sOxid => $sVal ) {
00187                     if ( $sOxid == $sArticleId ) {
00188                         $aNewItems[$sNextArticleId] = true;
00189                     } elseif ( $sOxid == $sNextArticleId ) {
00190                         $aNewItems[$sArticleId] = true;
00191                     } else {
00192                         $aNewItems[$sOxid] = true;
00193                     }
00194                 }
00195                 $this->setCompareItems($aNewItems);
00196             }
00197         }
00198     }
00199 
00205     public function inPopup() // #777C
00206     {
00207         $this->_sThisTemplate = 'compare_popup.tpl';
00208         $this->_iArticlesPerPage = -1;
00209     }
00210 
00216     public function getCompareItemsCnt()
00217     {
00218         if ( $this->_iCompItemsCnt === null ) {
00219             $this->_iCompItemsCnt = 0;
00220             if ( $aItems = $this->getCompareItems() ) {
00221                 $this->_iCompItemsCnt = count( $aItems );
00222             }
00223         }
00224         return $this->_iCompItemsCnt;
00225     }
00226 
00232     public function getCompareItems()
00233     {
00234         if ( $this->_aCompItems === null ) {
00235             $aItems = oxConfig::getParameter( 'aFiltcompproducts' );
00236             if ( is_array( $aItems ) && count( $aItems ) ) {
00237                 $this->_aCompItems = $aItems;
00238             }
00239         }
00240         return $this->_aCompItems;
00241     }
00242 
00250     public function setCompareItems( $aItems)
00251     {
00252         $this->_aCompItems = $aItems;
00253         oxSession::setVar( 'aFiltcompproducts', $aItems );
00254     }
00255 
00262     public function getCompArtList()
00263     {
00264         if ( $this->_oArtList === null ) {
00265             if ( $aItems = $this->getCompareItems()) {
00266                 // counts how many pages
00267                 $oList = oxNew( 'oxarticlelist' );
00268                 $oList->loadIds( array_keys( $aItems ) );
00269                 $this->_iCntPages = round( $oList->count() / $this->_iArticlesPerPage + 0.49 );
00270 
00271                 // cut page articles
00272                 if ( $this->_iArticlesPerPage > 0 ) {
00273                     $aItems = $this->_removeArticlesFromPage( $aItems, $oList );
00274                 }
00275                 $this->_oArtList = $this->_changeArtListOrder( $aItems, $oList );
00276             }
00277         }
00278         return $this->_oArtList;
00279     }
00280 
00286     public function getAttributeList()
00287     {
00288         if ( $this->_oAttributeList === null ) {
00289             $this->_oAttributeList = false;
00290             if ( $oArtList = $this->getCompArtList()) {
00291                 $oAttributeList = oxNew( 'oxattributelist' );
00292                 $this->_oAttributeList = $oAttributeList->loadAttributesByIds( array_keys( $oArtList ) );
00293             }
00294         }
00295         return $this->_oAttributeList;
00296     }
00297 
00303     public function getSimilarRecommLists()
00304     {
00305         if (!$this->getViewConfig()->getShowListmania()) {
00306             return false;
00307         }
00308 
00309         if ( $this->_oRecommList === null ) {
00310             $this->_oRecommList = false;
00311             if ( $oArtList = $this->getCompArtList()) {
00312                 $this->_oRecommList = oxNew('oxrecommlist');
00313                 $this->_oRecommList = $this->_oRecommList->getRecommListsByIds( array_keys( $oArtList ));
00314             }
00315         }
00316         return $this->_oRecommList;
00317     }
00318 
00324     public function getPageNavigation()
00325     {
00326         if ( $this->_oPageNavigation === null ) {
00327             $this->_oPageNavigation = false;
00328             $this->_oPageNavigation = $this->generatePageNavigation();
00329         }
00330         return $this->_oPageNavigation;
00331     }
00332 
00341     protected function _removeArticlesFromPage( $aItems, $oList )
00342     {
00343         //#1106S $aItems changed to $oList.
00344         //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
00345         $aListKeys = $oList->arrayKeys();
00346         $aItemKeys = array_keys($aItems);
00347         $aKeys = array_intersect( $aItemKeys, $aListKeys );
00348         $aNewItems = array();
00349         $iActPage = $this->getActPage();
00350         for ( $i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++ ) {
00351             if ( !isset($aKeys[$i])) {
00352                 break;
00353             }
00354             $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
00355         }
00356         return $aNewItems;
00357     }
00358 
00367     protected function _changeArtListOrder( $aItems, $oList )
00368     {
00369         // #777C changing order of list elements, according to $aItems
00370         $oNewList = array();
00371         $iCnt = 0;
00372         $iActPage = $this->getActPage();
00373         foreach ( $aItems as $sOxid => $sVal ) {
00374             $iCnt++;
00375             $oNewList[$sOxid] = $oList[$sOxid];
00376 
00377             // hide arrow if article is first in the list
00378             $oNewList[$sOxid]->hidePrev = false;
00379             if ( $iActPage == 0 && $iCnt==1 ) {
00380                 $oNewList[$sOxid]->hidePrev = true;
00381             }
00382 
00383             // hide arrow if article is last in the list
00384             $oNewList[$sOxid]->hideNext = false;
00385             if ( ( $iActPage + 1 ) == $this->_iCntPages && $iCnt == count( $aItems ) ) {
00386                 $oNewList[$sOxid]->hideNext = true;
00387             }
00388         }
00389         return $oNewList;
00390     }
00391 
00397     public function getOrderCnt()
00398     {
00399         if ( $this->_iOrderCnt === null ) {
00400             $this->_iOrderCnt = 0;
00401             if ( $oUser = $this->getUser() ) {
00402                 $this->_iOrderCnt = $oUser->getOrderCount();
00403             }
00404         }
00405         return $this->_iOrderCnt;
00406     }
00407 
00408 }

Generated by  doxygen 1.6.2