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 $_sThisTemplate = 'compare.tpl';
00068
00079 public function render()
00080 {
00081 parent::render();
00082
00083
00084 $this->_aViewData['oxcmp_compare'] = $this->getCompareItemsCnt();
00085
00086 $this->getCompArtList();
00087
00088 $this->_aViewData['articlelist'] = $this->getCompArtList();
00089
00090
00091 $this->_aViewData['allartattr'] = $this->getAttributeList();
00092
00093
00094 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00095
00096 $this->_aViewData['pgNr'] = $this->getActPage();
00097
00098
00099 $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00100
00101
00102 $this->_aViewData['iordersmade'] = $this->getOrderCnt();
00103
00104
00105 $this->_loadActions();
00106
00107 return $this->_sThisTemplate;
00108 }
00109
00115 public function moveLeft()
00116 {
00117 if ( $aItems = $this->getCompareItems() ) {
00118 $sArticleId = oxConfig::getParameter( 'aid' );
00119 $sPrevArticleId = null;
00120
00121 $blFound = false;
00122 foreach ( $aItems as $sOxid => $sVal ) {
00123 if ( $sOxid == $sArticleId ) {
00124 $blFound = true;
00125 }
00126 if ( !$blFound ) {
00127 $sPrevArticleId = $sOxid;
00128 }
00129 }
00130
00131 if ( $sPrevArticleId ) {
00132
00133 $aNewItems = array();
00134 foreach ( $aItems as $sOxid => $sVal ) {
00135 if ( $sOxid == $sPrevArticleId ) {
00136 $aNewItems[$sArticleId] = true;
00137 } elseif ( $sOxid == $sArticleId ) {
00138 $aNewItems[$sPrevArticleId] = true;
00139 } else {
00140 $aNewItems[$sOxid] = true;
00141 }
00142 }
00143
00144 $this->setCompareItems($aNewItems);
00145 }
00146 }
00147 }
00148
00154 public function moveRight()
00155 {
00156 if ( $aItems = $this->getCompareItems() ) {
00157 $sArticleId = oxConfig::getParameter( 'aid' );
00158 $sNextArticleId = 0;
00159
00160 $blFound = false;
00161 foreach ( $aItems as $sOxid => $sVal ) {
00162 if ( $blFound ) {
00163 $sNextArticleId = $sOxid;
00164 $blFound = false;
00165 }
00166 if ( $sOxid == $sArticleId ) {
00167 $blFound = true;
00168 }
00169 }
00170
00171 if ( $sNextArticleId ) {
00172
00173 $aNewItems = array();
00174 foreach ( $aItems as $sOxid => $sVal ) {
00175 if ( $sOxid == $sArticleId ) {
00176 $aNewItems[$sNextArticleId] = true;
00177 } elseif ( $sOxid == $sNextArticleId ) {
00178 $aNewItems[$sArticleId] = true;
00179 } else {
00180 $aNewItems[$sOxid] = true;
00181 }
00182 }
00183 $this->setCompareItems($aNewItems);
00184 }
00185 }
00186 }
00187
00193 public function inPopup()
00194 {
00195 $this->_sThisTemplate = 'compare_popup.tpl';
00196 $this->_iArticlesPerPage = -1;
00197 }
00198
00204 public function getCompareItemsCnt()
00205 {
00206 if ( $this->_iCompItemsCnt === null ) {
00207 $this->_iCompItemsCnt = 0;
00208 if ( $aItems = $this->getCompareItems() ) {
00209 $this->_iCompItemsCnt = count( $aItems );
00210 }
00211 }
00212 return $this->_iCompItemsCnt;
00213 }
00214
00220 public function getCompareItems()
00221 {
00222 if ( $this->_aCompItems === null ) {
00223 $aItems = oxConfig::getParameter( 'aFiltcompproducts' );
00224 if ( is_array( $aItems ) && count( $aItems ) ) {
00225 $this->_aCompItems = $aItems;
00226 }
00227 }
00228 return $this->_aCompItems;
00229 }
00230
00238 public function setCompareItems( $aItems)
00239 {
00240 $this->_aCompItems = $aItems;
00241 oxSession::setVar( 'aFiltcompproducts', $aItems );
00242 }
00243
00250 public function getCompArtList()
00251 {
00252 if ( $this->_oArtList === null ) {
00253 if ( $aItems = $this->getCompareItems()) {
00254
00255 $oList = oxNew( 'oxarticlelist' );
00256 $oList->loadIds( array_keys( $aItems ) );
00257 $this->_iCntPages = round( $oList->count() / $this->_iArticlesPerPage + 0.49 );
00258
00259
00260 if ( $this->_iArticlesPerPage > 0 ) {
00261 $aItems = $this->_removeArticlesFromPage( $aItems, $oList );
00262 }
00263 $this->_oArtList = $this->_changeArtListOrder( $aItems, $oList );
00264 }
00265 }
00266 return $this->_oArtList;
00267 }
00268
00274 public function getAttributeList()
00275 {
00276 if ( $this->_oAttributeList === null ) {
00277 $this->_oAttributeList = false;
00278 if ( $oArtList = $this->getCompArtList()) {
00279 $oAttributeList = oxNew( 'oxattributelist' );
00280 $this->_oAttributeList = $oAttributeList->loadAttributesByIds( array_keys( $oArtList ) );
00281 }
00282 }
00283 return $this->_oAttributeList;
00284 }
00285
00291 public function getSimilarRecommLists()
00292 {
00293 if ( $this->_oRecommList === null ) {
00294 $this->_oRecommList = false;
00295 if ( $oArtList = $this->getCompArtList()) {
00296 $this->_oRecommList = oxNew('oxrecommlist');
00297 $this->_oRecommList = $this->_oRecommList->getRecommListsByIds( array_keys( $oArtList ));
00298 }
00299 }
00300 return $this->_oRecommList;
00301 }
00302
00308 public function getPageNavigation()
00309 {
00310 if ( $this->_oPageNavigation === null ) {
00311 $this->_oPageNavigation = false;
00312 $this->_oPageNavigation = $this->generatePageNavigation();
00313 }
00314 return $this->_oPageNavigation;
00315 }
00316
00325 protected function _removeArticlesFromPage( $aItems, $oList )
00326 {
00327
00328
00329 $aListKeys = $oList->arrayKeys();
00330 $aItemKeys = array_keys($aItems);
00331 $aKeys = array_intersect( $aItemKeys, $aListKeys );
00332 $aNewItems = array();
00333 $iActPage = $this->getActPage();
00334 for ( $i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++ ) {
00335 if ( !isset($aKeys[$i])) {
00336 break;
00337 }
00338 $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
00339 }
00340 return $aNewItems;
00341 }
00342
00351 protected function _changeArtListOrder( $aItems, $oList )
00352 {
00353
00354 $oNewList = array();
00355 $iCnt = 0;
00356 $iActPage = $this->getActPage();
00357 foreach ( $aItems as $sOxid => $sVal ) {
00358 $iCnt++;
00359 $oNewList[$sOxid] = $oList[$sOxid];
00360
00361
00362 if ( $iActPage == 0 && $iCnt==1 ) {
00363 $oNewList[$sOxid]->hidePrev = true;
00364 } else {
00365 $oNewList[$sOxid]->hidePrev = false;
00366 }
00367
00368
00369 if ( ( $iActPage + 1 ) == $this->_iCntPages && $iCnt == count( $aItems ) ) {
00370 $oNewList[$sOxid]->hideNext = true;
00371 } else {
00372 $oNewList[$sOxid]->hideNext = false;
00373 }
00374 }
00375 return $oNewList;
00376 }
00377
00383 public function getOrderCnt()
00384 {
00385 if ( $this->_iOrderCnt === null ) {
00386 $this->_iOrderCnt = 0;
00387 if ( $oUser = $this->getUser() ) {
00388 $this->_iOrderCnt = $oUser->getOrderCount();
00389 }
00390 }
00391 return $this->_iOrderCnt;
00392 }
00393
00394 }