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->_oRecommList === null ) {
00306             $this->_oRecommList = false;
00307             if ( $oArtList = $this->getCompArtList()) {
00308                 $this->_oRecommList = oxNew('oxrecommlist');
00309                 $this->_oRecommList = $this->_oRecommList->getRecommListsByIds( array_keys( $oArtList ));
00310             }
00311         }
00312         return $this->_oRecommList;
00313     }
00314 
00320     public function getPageNavigation()
00321     {
00322         if ( $this->_oPageNavigation === null ) {
00323             $this->_oPageNavigation = false;
00324             $this->_oPageNavigation = $this->generatePageNavigation();
00325         }
00326         return $this->_oPageNavigation;
00327     }
00328 
00337     protected function _removeArticlesFromPage( $aItems, $oList )
00338     {
00339         //#1106S $aItems changed to $oList.
00340         //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
00341         $aListKeys = $oList->arrayKeys();
00342         $aItemKeys = array_keys($aItems);
00343         $aKeys = array_intersect( $aItemKeys, $aListKeys );
00344         $aNewItems = array();
00345         $iActPage = $this->getActPage();
00346         for ( $i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++ ) {
00347             if ( !isset($aKeys[$i])) {
00348                 break;
00349             }
00350             $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
00351         }
00352         return $aNewItems;
00353     }
00354 
00363     protected function _changeArtListOrder( $aItems, $oList )
00364     {
00365         // #777C changing order of list elements, according to $aItems
00366         $oNewList = array();
00367         $iCnt = 0;
00368         $iActPage = $this->getActPage();
00369         foreach ( $aItems as $sOxid => $sVal ) {
00370             $iCnt++;
00371             $oNewList[$sOxid] = $oList[$sOxid];
00372 
00373             // hide arrow if article is first in the list
00374             if ( $iActPage == 0 && $iCnt==1 ) {
00375                 $oNewList[$sOxid]->hidePrev = true;
00376             } else {
00377                 $oNewList[$sOxid]->hidePrev = false;
00378             }
00379 
00380             // hide arrow if article is last in the list
00381             if ( ( $iActPage + 1 ) == $this->_iCntPages && $iCnt == count( $aItems ) ) {
00382                 $oNewList[$sOxid]->hideNext = true;
00383             } else {
00384                 $oNewList[$sOxid]->hideNext = false;
00385             }
00386         }
00387         return $oNewList;
00388     }
00389 
00395     public function getOrderCnt()
00396     {
00397         if ( $this->_iOrderCnt === null ) {
00398             $this->_iOrderCnt = 0;
00399             if ( $oUser = $this->getUser() ) {
00400                 $this->_iOrderCnt = $oUser->getOrderCount();
00401             }
00402         }
00403         return $this->_iOrderCnt;
00404     }
00405 
00406 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5