00001 <?php
00002
00008 class RecommList extends oxUBase
00009 {
00014 protected $_sListType = 'recommlist';
00015
00020 protected $_sThisTemplate = 'recommlist.tpl';
00021
00026 protected $_sRecommId = null;
00027
00032 protected $_oActiveRecommList = null;
00033
00038 protected $_oActiveRecommItems = null;
00039
00044 protected $_oOtherRecommList = null;
00045
00050 protected $_aReviews = null;
00051
00056 protected $_blReviewActive = null;
00057
00062 protected $_blRate = null;
00063
00068 protected $_dRatingValue = null;
00069
00074 protected $_iRatingCnt = null;
00075
00080 protected $_oSearchRecommLists = null;
00081
00086 protected $_sSearch = null;
00087
00093 protected $_sTplLocation = null;
00094
00099 protected $_oPageNavigation = null;
00100
00106 public function render()
00107 {
00108 parent::render();
00109 $myConfig = $this->getConfig();
00110
00111 $this->_iAllArtCnt = 0;
00112 $this->_aViewData['actvrecommlist'] = $this->getActiveRecommList();
00113 $this->_aViewData['itemList'] = $this->getActiveRecommItems();
00114
00115
00116 $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00117
00118
00119 $this->_aViewData['rate'] = $this->canRate();
00120 $this->_aViewData['rating'] = $this->getRatingValue();
00121 $this->_aViewData['ratingcnt'] = $this->getRatingCount();
00122 $this->_aViewData['reviews'] = $this->getReviews();
00123
00124
00125 $this->_aViewData['recommlists'] = $this->getRecommLists();
00126 if ( $sOxid = $this->getRecommId()) {
00127 $oActiveRecommList = $this->getActiveRecommList();
00128 $oList = $this->getActiveRecommItems();
00129 if ( $oList && $oList->count()) {
00130 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00131 }
00132
00133 if (in_array('oxrss_recommlistarts', $myConfig->getConfigParam( 'aRssSelected' ))) {
00134 $oRss = oxNew('oxrssfeed');
00135 $this->addRssFeed($oRss->getRecommListArticlesTitle($oActiveRecommList), $oRss->getRecommListArticlesUrl($this->_oActiveRecommList), 'recommlistarts');
00136 }
00137
00138 } else {
00139 if ( ($oList = $this->getRecommLists()) && $oList->count() ) {
00140 $oRecommList = oxNew( 'oxrecommlist' );
00141 $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount( $this->getRecommSearch() );
00142 }
00143 }
00144
00145 if ( !$oList = $this->getActiveRecommItems() ) {
00146 $oList = $this->getRecommLists();
00147 }
00148
00149 if ( $oList && $oList->count() ) {
00150 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00151 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00152 $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00153 }
00154
00155 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00156 $this->_aViewData['template_location'] = $this->getTemplateLocation();
00157 $this->_aViewData['searchrecomm'] = $this->getRecommSearch();
00158 $this->_aViewData['searchrecommforhtml'] = $this->getSearchForHtml();
00159
00160 $this->_aViewData['loginformanchor'] = $this->getLoginFormAnchor();
00161
00162
00163 $this->_processListArticles();
00164
00165 return $this->_sThisTemplate;
00166 }
00167
00173 protected function _processListArticles()
00174 {
00175 $sAddParams = $this->getAddUrlParams();
00176 if ( $sAddParams && $this->_oActiveRecommItems ) {
00177 foreach ( $this->_oActiveRecommItems as $oArticle ) {
00178 $oArticle->appendLink( $sAddParams );
00179 }
00180 }
00181 }
00182
00188 public function getAddUrlParams()
00189 {
00190 $sAddParams = parent::getAddUrlParams();
00191 $sAddParams .= ($sAddParams?'&':'') . "listtype={$this->_sListType}";
00192
00193 if ( $sParam = rawurlencode( oxConfig::getParameter( 'searchrecomm', true ) ) ) {
00194 $sAddParams .= "&searchrecomm={$sParam}";
00195 }
00196
00197 if ( $oRecommList = $this->getActRecommList() ) {
00198 $sAddParams .= '&recommid='.$oRecommList->getId();
00199 }
00200
00201 return $sAddParams;
00202 }
00203
00209 public function saveReview()
00210 {
00211 $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) );
00212 $dRating = oxConfig::getParameter( 'recommlistrating' );
00213 if ( $dRating < 0 || $dRating > 5 ) {
00214 $dRating = null;
00215 }
00216
00217 $sRLId = oxConfig::getParameter( 'recommid' );
00218 $sUserId = oxSession::getVar( 'usr' );
00219
00220 $oRecommList = oxNew('oxrecommlist');
00221 if (!$oRecommList->load($sRLId)) {
00222 return;
00223 }
00224
00225
00226 if ( $dRating && $sUserId ) {
00227 $oRating = oxNew( 'oxrating' );
00228 $blRate = $oRating->allowRating( $sUserId, 'oxrecommlist', $oRecommList->getId());
00229 if ( $blRate) {
00230 $oRating->oxratings__oxuserid = new oxField($sUserId);
00231 $oRating->oxratings__oxtype = new oxField('oxrecommlist', oxField::T_RAW);
00232 $oRating->oxratings__oxobjectid = new oxField($sRLId);
00233 $oRating->oxratings__oxrating = new oxField($dRating);
00234 $oRating->save();
00235 $oRecommList->addToRatingAverage( $dRating);
00236 } else {
00237 $dRating = null;
00238 }
00239 }
00240
00241 if ( $sReviewText && $sUserId ) {
00242 $oReview = oxNew( 'oxreview' );
00243 $oReview->oxreviews__oxobjectid = new oxField($sRLId);
00244 $oReview->oxreviews__oxtype = new oxField('oxrecommlist', oxField::T_RAW);
00245 $oReview->oxreviews__oxtext = new oxField($sReviewText, oxField::T_RAW);
00246 $oReview->oxreviews__oxlang = new oxField(oxLang::getInstance()->getBaseLanguage());
00247 $oReview->oxreviews__oxuserid = new oxField($sUserId);
00248 $oReview->oxreviews__oxrating = new oxField(( $dRating) ? $dRating : null);
00249 $oReview->save();
00250 }
00251 }
00252
00260 public function showLogin()
00261 {
00262 $this->_sThisTemplate = 'account_login.tpl';
00263 $this->_sLoginFormAnchor = "review";
00264 }
00265
00271 public function getNavigationParams()
00272 {
00273 $aParams = parent::getNavigationParams();
00274 $aParams['recommid'] = oxConfig::getParameter( 'recommid' );
00275
00276 return $aParams;
00277 }
00278
00284 public function getActiveRecommList()
00285 {
00286 if ( $this->_oActiveRecommList === null ) {
00287 $this->_oActiveRecommList = false;
00288 if ( $sOxid = $this->getRecommId()) {
00289 $this->_oActiveRecommList = oxNew( 'oxrecommlist' );
00290 $this->_oActiveRecommList->load( $sOxid);
00291 }
00292 }
00293 return $this->_oActiveRecommList;
00294 }
00295
00301 public function getActiveRecommItems()
00302 {
00303 if ( $this->_oActiveRecommItems === null ) {
00304 $this->_oActiveRecommItems = false;
00305 if ( $oActiveRecommList = $this->getActiveRecommList()) {
00306
00307 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00308 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00309
00310
00311 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00312 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00313
00314 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00315
00316 if ( $oList && $oList->count() ) {
00317 foreach ( $oList as $oItem) {
00318 $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00319 }
00320 $this->_oActiveRecommItems = $oList;
00321 }
00322 }
00323 }
00324 return $this->_oActiveRecommItems;
00325 }
00326
00332 public function getSimilarRecommLists()
00333 {
00334 if ( $this->_oOtherRecommList === null ) {
00335 $this->_oOtherRecommList = false;
00336 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00337 if ( $oList = $this->getActiveRecommItems() ) {
00338 $oRecommLists = $oActiveRecommList->getRecommListsByIds( $oList->arrayKeys());
00339
00340 unset($oRecommLists[$this->getRecommId()]);
00341 $this->_oOtherRecommList = $oRecommLists;
00342 }
00343 }
00344 }
00345 return $this->_oOtherRecommList;
00346 }
00347
00353 public function getRecommId()
00354 {
00355 if ( $this->_sRecommId === null ) {
00356 $this->_sRecommId = false;
00357 if ( $sOxid = oxConfig::getParameter( 'recommid' )) {
00358 $this->_sRecommId = $sOxid;
00359 }
00360 }
00361 return $this->_sRecommId;
00362 }
00363
00369 public function getReviews()
00370 {
00371 if ( $this->_aReviews === null ) {
00372 $this->_aReviews = false;
00373 if ( $this->isReviewActive() ) {
00374 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00375 $this->_aReviews = $oActiveRecommList->getReviews();
00376 }
00377 }
00378 }
00379 return $this->_aReviews;
00380 }
00381
00387 public function isReviewActive()
00388 {
00389 $myConfig = $this->getConfig();
00390 if ( $this->_blReviewActive === null ) {
00391 $this->_blReviewActive = false;
00392 if ( $myConfig->getConfigParam( 'bl_perfLoadReviews' ) ) {
00393 $this->_blReviewActive = true;
00394 }
00395 }
00396 return $this->_blReviewActive;
00397 }
00398
00404 public function canRate()
00405 {
00406 if ( $this->_blRate === null ) {
00407 $this->_blRate = false;
00408 if ( $this->isReviewActive() ) {
00409 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00410 $oRating = oxNew( 'oxrating' );
00411 $this->_blRate = $oRating->allowRating( oxSession::getVar( 'usr' ), 'oxrecommlist', $oActiveRecommList->getId());
00412 }
00413 }
00414 }
00415 return $this->_blRate;
00416 }
00417
00423 public function getRatingValue()
00424 {
00425 if ( $this->_dRatingValue === null ) {
00426 $this->_dRatingValue = false;
00427 if ( $this->isReviewActive() ) {
00428 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00429 $this->_dRatingValue = round( $oActiveRecommList->oxrecommlists__oxrating->value, 1);
00430 }
00431 }
00432 }
00433 return $this->_dRatingValue;
00434 }
00435
00441 public function getRatingCount()
00442 {
00443 if ( $this->_iRatingCnt === null ) {
00444 $this->_iRatingCnt = false;
00445 if ( $this->isReviewActive() ) {
00446 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00447 $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
00448 }
00449 }
00450 }
00451 return $this->_iRatingCnt;
00452 }
00453
00459 public function getRecommLists()
00460 {
00461 if ( $this->_oSearchRecommLists === null ) {
00462 $this->_oSearchRecommLists = array();
00463 if ( !$this->getRecommId()) {
00464 $sSearch = $this->getRecommSearch();
00465
00466 $oRecommList = oxNew( 'oxrecommlist' );
00467 $oList = $oRecommList->getSearchRecommLists( $sSearch );
00468 if ( $oList && $oList->count() ) {
00469 $this->_oSearchRecommLists = $oList;
00470 }
00471 }
00472 }
00473 return $this->_oSearchRecommLists;
00474 }
00475
00481 public function getRecommSearch()
00482 {
00483 if ( $this->_sSearch === null ) {
00484 $this->_sSearch = false;
00485 if ( $sSearch = oxConfig::getParameter( 'searchrecomm', true ) ) {
00486 $this->_sSearch = $sSearch;
00487 }
00488 }
00489 return $this->_sSearch;
00490 }
00491
00499 public function getTemplateLocation()
00500 {
00501 if ( $this->_sTplLocation === null ) {
00502 $this->_sTplLocation = false;
00503 $oLang = oxLang::getInstance();
00504 if ( $sSearchparam = $this->getRecommSearch() ) {
00505 $sUrl = $this->getConfig()->getShopHomeURL();
00506 $sLink = "{$sUrl}cl=recommlist&searchrecomm=".rawurlencode( $sSearchparam );
00507 $sTitle = $oLang->translateString('RECOMMLIST');
00508 $sTitle .= " / ".$oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
00509 $this->_sTplLocation = "<a href='".$sLink."'>".$sTitle."</a>";
00510 } else {
00511 $this->_sTplLocation = $oLang->translateString('RECOMMLIST');
00512 }
00513 }
00514 return $this->_sTplLocation;
00515 }
00516
00522 public function getTreePath()
00523 {
00524 $oLang = oxLang::getInstance();
00525
00526 $aPath[0] = oxNew( "oxcategory" );
00527 $aPath[0]->setLink( false );
00528 $aPath[0]->oxcategories__oxtitle = new oxField( $oLang->translateString('RECOMMLIST') );
00529
00530 if ( $sSearchparam = $this->getRecommSearch() ) {
00531 $sUrl = $this->getConfig()->getShopHomeURL()."cl=recommlist&searchrecomm=".rawurlencode( $sSearchparam );
00532 $sTitle = $oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
00533
00534 $aPath[1] = oxNew( "oxcategory" );
00535 $aPath[1]->setLink( $sUrl );
00536 $aPath[1]->oxcategories__oxtitle = new oxField( $sTitle );
00537 }
00538
00539 return $aPath;
00540 }
00541
00547 public function getSearchForHtml()
00548 {
00549 return oxConfig::getParameter( 'searchrecomm' );
00550 }
00551
00557 public function getLoginFormAnchor()
00558 {
00559 return $this->_sLoginFormAnchor;
00560 }
00561
00567 public function getPageNavigation()
00568 {
00569 if ( $this->_oPageNavigation === null ) {
00570 $this->_oPageNavigation = false;
00571 $this->_oPageNavigation = $this->generatePageNavigation();
00572 }
00573 return $this->_oPageNavigation;
00574 }
00575
00581 public function getAdditionalParams()
00582 {
00583 $sAddParams = parent::getAdditionalParams();
00584
00585 if ( $sOxid = $this->getRecommId() ) {
00586 $sAddParams .= "&recommid={$sOxid}";
00587 }
00588
00589 if ( $sSearch = $this->getRecommSearch() ) {
00590 $sAddParams .= "&searchrecomm=". rawurlencode( $sSearch );
00591 }
00592
00593 return $sAddParams;
00594 }
00595
00603 public function getLink( $iLang = null )
00604 {
00605 $sLink = parent::getLink( $iLang );
00606
00607 if ( oxUtils::getInstance()->seoIsActive() ) {
00608 if ( $sRecommId = $this->getRecommId() ) {
00609 $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&' ) . "recommid={$sRecommId}";
00610 }
00611
00612 if ( $sSearch = $this->getSearchForHtml() ) {
00613 $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&' ) . "searchrecomm={$sSearch}";
00614 }
00615 }
00616
00617 return $sLink;
00618 }
00619 }