Go to the documentation of this file.00001 <?php
00002
00008 class RecommList extends aList
00009 {
00014 protected $_sListType = 'recommlist';
00015
00020 protected $_sThisTemplate = 'recommlist.tpl';
00021
00026 protected $_oOtherRecommList = null;
00027
00032 protected $_aReviews = null;
00033
00038 protected $_blRate = null;
00039
00044 protected $_dRatingValue = null;
00045
00050 protected $_iRatingCnt = null;
00051
00056 protected $_oSearchRecommLists = null;
00057
00062 protected $_sSearch = null;
00063
00069 protected $_sTplLocation = null;
00070
00075 protected $_oPageNavigation = null;
00076
00082 public function render()
00083 {
00084 oxUBase::render();
00085 $myConfig = $this->getConfig();
00086
00087 $this->_iAllArtCnt = 0;
00088 $this->_aViewData['actvrecommlist'] = $this->getActiveRecommList();
00089 $this->_aViewData['itemList'] = $this->getArticleList();
00090
00091
00092 $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00093
00094
00095 $this->_aViewData['rate'] = $this->canRate();
00096 $this->_aViewData['rating'] = $this->getRatingValue();
00097 $this->_aViewData['ratingcnt'] = $this->getRatingCount();
00098 $this->_aViewData['reviews'] = $this->getReviews();
00099
00100
00101 $this->_aViewData['recommlists'] = $this->getRecommLists();
00102 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00103 if ( ( $oList = $this->getArticleList() ) && $oList->count()) {
00104 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00105 }
00106
00107 if ( $myConfig->getConfigParam( 'bl_rssRecommListArts' ) ) {
00108 $oRss = oxNew('oxrssfeed');
00109 $this->addRssFeed($oRss->getRecommListArticlesTitle($oActiveRecommList), $oRss->getRecommListArticlesUrl($this->_oActiveRecommList), 'recommlistarts');
00110 }
00111
00112 } else {
00113 if ( ( $oList = $this->getRecommLists() ) && $oList->count() ) {
00114 $oRecommList = oxNew( 'oxrecommlist' );
00115 $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount( $this->getRecommSearch() );
00116 }
00117 }
00118
00119 if ( !( $oList = $this->getArticleList() ) ) {
00120 $oList = $this->getRecommLists();
00121 }
00122
00123 if ( $oList && $oList->count() ) {
00124 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00125 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00126 $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00127 }
00128
00129 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00130 $this->_aViewData['template_location'] = $this->getTemplateLocation();
00131 $this->_aViewData['searchrecomm'] = $this->getRecommSearch();
00132 $this->_aViewData['searchrecommforhtml'] = $this->getSearchForHtml();
00133
00134 $this->_aViewData['loginformanchor'] = $this->getLoginFormAnchor();
00135
00136
00137 $this->_processListArticles();
00138
00139 return $this->_sThisTemplate;
00140 }
00141
00147 protected function _getProductLinkType()
00148 {
00149 return OXARTICLE_LINKTYPE_RECOMM;
00150 }
00151
00157 public function getAddUrlParams()
00158 {
00159 $sAddParams = parent::getAddUrlParams();
00160 $sAddParams .= ($sAddParams?'&':'') . "listtype={$this->_sListType}";
00161
00162 if ( $oRecommList = $this->getActiveRecommList() ) {
00163 $sAddParams .= "&recommid=".$oRecommList->getId();
00164 }
00165
00166 return $sAddParams;
00167 }
00168
00174 public function getAddSeoUrlParams()
00175 {
00176 $sAddParams = parent::getAddSeoUrlParams();
00177 if ( $sParam = oxConfig::getParameter( "searchrecomm", true ) ) {
00178 $sAddParams .= "&searchrecomm=" . rawurlencode( $sParam );
00179 }
00180 return $sAddParams;
00181 }
00182
00188 public function saveReview()
00189 {
00190 if ( $this->canAcceptFormData() &&
00191 ( $oRecommList = $this->getActiveRecommList() ) && ( $oUser = $this->getUser() ) ) {
00192
00193
00194 $dRating = oxConfig::getParameter( 'recommlistrating' );
00195 if ( $dRating !== null ) {
00196 $dRating = (int) $dRating;
00197 }
00198
00199 if ( $dRating !== null && $dRating >= 0 && $dRating <= 5 ) {
00200 $oRating = oxNew( 'oxrating' );
00201 if ( $oRating->allowRating( $oUser->getId(), 'oxrecommlist', $oRecommList->getId() ) ) {
00202 $oRating->oxratings__oxuserid = new oxField( $oUser->getId() );
00203 $oRating->oxratings__oxtype = new oxField( 'oxrecommlist' );
00204 $oRating->oxratings__oxobjectid = new oxField( $oRecommList->getId() );
00205 $oRating->oxratings__oxrating = new oxField( $dRating );
00206 $oRating->save();
00207 $oRecommList->addToRatingAverage( $dRating );
00208 }
00209 }
00210
00211 if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
00212 $oReview = oxNew( 'oxreview' );
00213 $oReview->oxreviews__oxobjectid = new oxField( $oRecommList->getId() );
00214 $oReview->oxreviews__oxtype = new oxField( 'oxrecommlist' );
00215 $oReview->oxreviews__oxtext = new oxField( $sReviewText, oxField::T_RAW );
00216 $oReview->oxreviews__oxlang = new oxField( oxLang::getInstance()->getBaseLanguage() );
00217 $oReview->oxreviews__oxuserid = new oxField( $oUser->getId() );
00218 $oReview->oxreviews__oxrating = new oxField( ( $dRating !== null ) ? $dRating : null );
00219 $oReview->save();
00220 }
00221 }
00222 }
00223
00231 public function showLogin()
00232 {
00233 $this->_sThisTemplate = 'account_login.tpl';
00234 $this->_sLoginFormAnchor = "review";
00235 }
00236
00242 public function getNavigationParams()
00243 {
00244 $aParams = oxUBase::getNavigationParams();
00245 $aParams['recommid'] = oxConfig::getParameter( 'recommid' );
00246
00247 return $aParams;
00248 }
00249
00257 public function getActiveRecommItems()
00258 {
00259 return $this->getArticleList();
00260 }
00261
00267 public function getArticleList()
00268 {
00269 if ( $this->_aArticleList === null ) {
00270 $this->_aArticleList = false;
00271 if ( $oActiveRecommList = $this->getActiveRecommList()) {
00272
00273 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00274 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00275
00276
00277 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00278 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00279
00280 $this->_aArticleList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00281
00282 if ( $this->_aArticleList && $this->_aArticleList->count() ) {
00283 foreach ( $this->_aArticleList as $oItem ) {
00284 $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00285 }
00286 }
00287 }
00288 }
00289 return $this->_aArticleList;
00290 }
00291
00297 public function getSimilarRecommLists()
00298 {
00299 if ( $this->_oOtherRecommList === null ) {
00300 $this->_oOtherRecommList = false;
00301 if ( ( $oActiveRecommList = $this->getActiveRecommList() ) && ( $oList = $this->getArticleList() ) ) {
00302 $oRecommLists = $oActiveRecommList->getRecommListsByIds( $oList->arrayKeys());
00303
00304 unset( $oRecommLists[$oActiveRecommList->getId()] );
00305 $this->_oOtherRecommList = $oRecommLists;
00306 }
00307 }
00308 return $this->_oOtherRecommList;
00309 }
00310
00318 public function getRecommId()
00319 {
00320 return oxConfig::getParameter( 'recommid' );
00321 }
00322
00328 public function getReviews()
00329 {
00330 if ( $this->_aReviews === null ) {
00331 $this->_aReviews = false;
00332 if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00333 $this->_aReviews = $oActiveRecommList->getReviews();
00334 }
00335 }
00336 return $this->_aReviews;
00337 }
00338
00344 public function isReviewActive()
00345 {
00346 return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
00347 }
00348
00354 public function canRate()
00355 {
00356 if ( $this->_blRate === null ) {
00357 $this->_blRate = false;
00358 if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00359 $oRating = oxNew( 'oxrating' );
00360 $this->_blRate = $oRating->allowRating( oxSession::getVar( 'usr' ), 'oxrecommlist', $oActiveRecommList->getId());
00361 }
00362 }
00363 return $this->_blRate;
00364 }
00365
00371 public function getRatingValue()
00372 {
00373 if ( $this->_dRatingValue === null ) {
00374 $this->_dRatingValue = (double)0;
00375 if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00376 $this->_dRatingValue = round( $oActiveRecommList->oxrecommlists__oxrating->value, 1);
00377 }
00378 }
00379 return (double) $this->_dRatingValue;
00380 }
00381
00387 public function getRatingCount()
00388 {
00389 if ( $this->_iRatingCnt === null ) {
00390 $this->_iRatingCnt = false;
00391 if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00392 $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
00393 }
00394 }
00395 return $this->_iRatingCnt;
00396 }
00397
00403 public function getRecommLists()
00404 {
00405 if ( $this->_oSearchRecommLists === null ) {
00406 $this->_oSearchRecommLists = array();
00407 if ( !$this->getActiveRecommList() ) {
00408
00409 $oRecommList = oxNew( 'oxrecommlist' );
00410 $oList = $oRecommList->getSearchRecommLists( $this->getRecommSearch() );
00411 if ( $oList && $oList->count() ) {
00412 $this->_oSearchRecommLists = $oList;
00413 }
00414 }
00415 }
00416 return $this->_oSearchRecommLists;
00417 }
00418
00424 public function getRecommSearch()
00425 {
00426 if ( $this->_sSearch === null ) {
00427 $this->_sSearch = false;
00428 if ( $sSearch = oxConfig::getParameter( 'searchrecomm', true ) ) {
00429 $this->_sSearch = $sSearch;
00430 }
00431 }
00432 return $this->_sSearch;
00433 }
00434
00442 public function getTemplateLocation()
00443 {
00444 if ( $this->_sTplLocation === null ) {
00445 $this->_sTplLocation = false;
00446 $oLang = oxLang::getInstance();
00447 if ( $sSearchparam = $this->getRecommSearch() ) {
00448 $sUrl = $this->getConfig()->getShopHomeURL();
00449 $sLink = "{$sUrl}cl=recommlist&searchrecomm=".rawurlencode( $sSearchparam );
00450 $sTitle = $oLang->translateString('RECOMMLIST');
00451 $sTitle .= " / ".$oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
00452 $this->_sTplLocation = "<a href='".$sLink."'>".$sTitle."</a>";
00453 } else {
00454 $this->_sTplLocation = $oLang->translateString('RECOMMLIST');
00455 }
00456 }
00457 return $this->_sTplLocation;
00458 }
00459
00465 public function getTreePath()
00466 {
00467 $oLang = oxLang::getInstance();
00468
00469 $aPath[0] = oxNew( "oxcategory" );
00470 $aPath[0]->setLink( false );
00471 $aPath[0]->oxcategories__oxtitle = new oxField( $oLang->translateString('RECOMMLIST') );
00472
00473 if ( $sSearchparam = $this->getRecommSearch() ) {
00474 $sUrl = $this->getConfig()->getShopHomeURL()."cl=recommlist&searchrecomm=".rawurlencode( $sSearchparam );
00475 $sTitle = $oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
00476
00477 $aPath[1] = oxNew( "oxcategory" );
00478 $aPath[1]->setLink( $sUrl );
00479 $aPath[1]->oxcategories__oxtitle = new oxField( $sTitle );
00480 }
00481
00482 return $aPath;
00483 }
00484
00490 public function getSearchForHtml()
00491 {
00492
00493 if ( $oActiveRecommList = $this->getActiveRecommList()) {
00494 return $oActiveRecommList->oxrecommlists__oxtitle->value;
00495 }
00496 return oxConfig::getParameter( 'searchrecomm' );
00497 }
00498
00504 public function getLoginFormAnchor()
00505 {
00506 return $this->_sLoginFormAnchor;
00507 }
00508
00514 public function generatePageNavigationUrl()
00515 {
00516 if ( ( oxUtils::getInstance()->seoIsActive() && ( $oRecomm = $this->getActiveRecommList() ) ) ) {
00517 $sUrl = $oRecomm->getLink();
00518 } else {
00519 $sUrl = oxUBase::generatePageNavigationUrl();
00520 }
00521 return $sUrl;
00522 }
00523
00533 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00534 {
00535 if ( oxUtils::getInstance()->seoIsActive() && ( $oRecomm = $this->getActiveRecommList() ) ) {
00536 if ( $iPage ) {
00537
00538 $sUrl = $oRecomm->getBaseSeoLink( $iLang, $iPage );
00539 }
00540 } else {
00541 $sUrl = oxUBase::_addPageNrParam( $sUrl, $iPage, $iLang );
00542 }
00543 return $sUrl;
00544 }
00545
00551 public function getAdditionalParams()
00552 {
00553 $sAddParams = oxUBase::getAdditionalParams();
00554
00555 if ( $oRecomm = $this->getActiveRecommList() ) {
00556 $sAddParams .= "&recommid=".$oRecomm->getId();
00557 }
00558
00559 if ( $sSearch = $this->getRecommSearch() ) {
00560 $sAddParams .= "&searchrecomm=". rawurlencode( $sSearch );
00561 }
00562
00563 return $sAddParams;
00564 }
00565
00573 public function getLink( $iLang = null )
00574 {
00575 if ( $oRecomm = $this->getActiveRecommList() ) {
00576 $sLink = $oRecomm->getLink( $iLang );
00577 } else {
00578 $sLink = oxUBase::getLink( $iLang );
00579 }
00580 $sSearch = oxConfig::getParameter( 'searchrecomm' );
00581 if ( $sSearch ) {
00582 $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&' ) . "searchrecomm={$sSearch}";
00583 }
00584
00585 return $sLink;
00586 }
00587 }