Go to the documentation of this file.00001 <?php
00002
00008 class RecommList extends aList
00009 {
00014 protected $_sListType = 'recommlist';
00015
00020 protected $_sThisTemplate = 'page/recommendations/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
00077
00083 public function render()
00084 {
00085 oxUBase::render();
00086 $myConfig = $this->getConfig();
00087
00088 $this->_iAllArtCnt = 0;
00089
00090 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00091 if ( ( $oList = $this->getArticleList() ) && $oList->count()) {
00092 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00093 }
00094
00095 if ( $myConfig->getConfigParam( 'bl_rssRecommListArts' ) ) {
00096 $oRss = oxNew('oxrssfeed');
00097 $this->addRssFeed($oRss->getRecommListArticlesTitle($oActiveRecommList), $oRss->getRecommListArticlesUrl($this->_oActiveRecommList), 'recommlistarts');
00098 }
00099
00100 } else {
00101 if ( ( $oList = $this->getRecommLists() ) && $oList->count() ) {
00102 $oRecommList = oxNew( 'oxrecommlist' );
00103 $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount( $this->getRecommSearch() );
00104 }
00105 }
00106
00107 if ( !( $oList = $this->getArticleList() ) ) {
00108 $oList = $this->getRecommLists();
00109 }
00110
00111 if ( $oList && $oList->count() ) {
00112 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00113 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00114 $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00115 }
00116
00117 $this->_processListArticles();
00118
00119 return $this->_sThisTemplate;
00120 }
00121
00127 protected function _getProductLinkType()
00128 {
00129 return OXARTICLE_LINKTYPE_RECOMM;
00130 }
00131
00137 public function getAddUrlParams()
00138 {
00139 $sAddParams = parent::getAddUrlParams();
00140 $sAddParams .= ($sAddParams?'&':'') . "listtype={$this->_sListType}";
00141
00142 if ( $oRecommList = $this->getActiveRecommList() ) {
00143 $sAddParams .= "&recommid=".$oRecommList->getId();
00144 }
00145
00146 return $sAddParams;
00147 }
00148
00154 public function getAddSeoUrlParams()
00155 {
00156 $sAddParams = parent::getAddSeoUrlParams();
00157 if ( $sParam = oxConfig::getParameter( "searchrecomm", true) ) {
00158 $sAddParams .= "&searchrecomm=" . rawurlencode( $sParam );
00159 }
00160 return $sAddParams;
00161 }
00162
00168 public function saveReview()
00169 {
00170 if (!oxRegistry::getSession()->checkSessionChallenge()) {
00171 return;
00172 }
00173
00174 if ( $this->canAcceptFormData() &&
00175 ( $oRecommList = $this->getActiveRecommList() ) && ( $oUser = $this->getUser() ) ) {
00176
00177
00178 $dRating = oxConfig::getParameter( 'recommlistrating' );
00179 if ( $dRating !== null ) {
00180 $dRating = (int) $dRating;
00181 }
00182
00183 if ( $dRating !== null && $dRating >= 1 && $dRating <= 5 ) {
00184 $oRating = oxNew( 'oxrating' );
00185 if ( $oRating->allowRating( $oUser->getId(), 'oxrecommlist', $oRecommList->getId() ) ) {
00186 $oRating->oxratings__oxuserid = new oxField( $oUser->getId() );
00187 $oRating->oxratings__oxtype = new oxField( 'oxrecommlist' );
00188 $oRating->oxratings__oxobjectid = new oxField( $oRecommList->getId() );
00189 $oRating->oxratings__oxrating = new oxField( $dRating );
00190 $oRating->save();
00191 $oRecommList->addToRatingAverage( $dRating );
00192 }
00193 }
00194
00195 if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
00196 $oReview = oxNew( 'oxreview' );
00197 $oReview->oxreviews__oxobjectid = new oxField( $oRecommList->getId() );
00198 $oReview->oxreviews__oxtype = new oxField( 'oxrecommlist' );
00199 $oReview->oxreviews__oxtext = new oxField( $sReviewText, oxField::T_RAW );
00200 $oReview->oxreviews__oxlang = new oxField( oxRegistry::getLang()->getBaseLanguage() );
00201 $oReview->oxreviews__oxuserid = new oxField( $oUser->getId() );
00202 $oReview->oxreviews__oxrating = new oxField( ( $dRating !== null ) ? $dRating : null );
00203 $oReview->save();
00204 }
00205 }
00206 }
00207
00213 public function getNavigationParams()
00214 {
00215 $aParams = oxUBase::getNavigationParams();
00216 $aParams['recommid'] = oxConfig::getParameter( 'recommid' );
00217
00218 return $aParams;
00219 }
00220
00226 public function getArticleList()
00227 {
00228 if ( $this->_aArticleList === null ) {
00229 $this->_aArticleList = false;
00230 if ( $oActiveRecommList = $this->getActiveRecommList()) {
00231
00232 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00233 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00234
00235
00236 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00237 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00238
00239 $this->_aArticleList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00240
00241 if ( $this->_aArticleList && $this->_aArticleList->count() ) {
00242 foreach ( $this->_aArticleList as $oItem ) {
00243 $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00244 }
00245 }
00246 }
00247 }
00248 return $this->_aArticleList;
00249 }
00250
00256 public function getSimilarRecommLists()
00257 {
00258 if ( $this->_oOtherRecommList === null ) {
00259 $this->_oOtherRecommList = false;
00260 if ( ( $oActiveRecommList = $this->getActiveRecommList() ) && ( $oList = $this->getArticleList() ) ) {
00261 $oRecommLists = $oActiveRecommList->getRecommListsByIds( $oList->arrayKeys() );
00262
00263 unset( $oRecommLists[$oActiveRecommList->getId()] );
00264 $this->_oOtherRecommList = $oRecommLists;
00265 }
00266 }
00267 return $this->_oOtherRecommList;
00268 }
00269
00275 public function getReviews()
00276 {
00277 if ( $this->_aReviews === null ) {
00278 $this->_aReviews = false;
00279 if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00280 $this->_aReviews = $oActiveRecommList->getReviews();
00281 }
00282 }
00283 return $this->_aReviews;
00284 }
00285
00291 public function isReviewActive()
00292 {
00293 return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
00294 }
00295
00301 public function canRate()
00302 {
00303 if ( $this->_blRate === null ) {
00304 $this->_blRate = false;
00305 if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00306 $oRating = oxNew( 'oxrating' );
00307 $this->_blRate = $oRating->allowRating( oxSession::getVar( 'usr' ), 'oxrecommlist', $oActiveRecommList->getId());
00308 }
00309 }
00310 return $this->_blRate;
00311 }
00312
00318 public function getRatingValue()
00319 {
00320 if ( $this->_dRatingValue === null ) {
00321 $this->_dRatingValue = (double)0;
00322 if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00323 $this->_dRatingValue = round( $oActiveRecommList->oxrecommlists__oxrating->value, 1);
00324 }
00325 }
00326 return (double) $this->_dRatingValue;
00327 }
00328
00334 public function getRatingCount()
00335 {
00336 if ( $this->_iRatingCnt === null ) {
00337 $this->_iRatingCnt = false;
00338 if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00339 $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
00340 }
00341 }
00342 return $this->_iRatingCnt;
00343 }
00344
00350 public function getRecommLists()
00351 {
00352 if ( $this->_oSearchRecommLists === null ) {
00353 $this->_oSearchRecommLists = array();
00354 if ( !$this->getActiveRecommList() ) {
00355
00356 $oRecommList = oxNew( 'oxrecommlist' );
00357 $oList = $oRecommList->getSearchRecommLists( $this->getRecommSearch() );
00358 if ( $oList && $oList->count() ) {
00359 $this->_oSearchRecommLists = $oList;
00360 }
00361 }
00362 }
00363 return $this->_oSearchRecommLists;
00364 }
00365
00371 public function getRecommSearch()
00372 {
00373 if ( $this->_sSearch === null ) {
00374 $this->_sSearch = false;
00375 if ( $sSearch = oxConfig::getParameter( 'searchrecomm', false ) ) {
00376 $this->_sSearch = $sSearch;
00377 }
00378 }
00379 return $this->_sSearch;
00380 }
00381
00387 public function getTreePath()
00388 {
00389 $oLang = oxRegistry::getLang();
00390
00391 $aPath[0] = oxNew( "oxcategory" );
00392 $aPath[0]->setLink( false );
00393 $aPath[0]->oxcategories__oxtitle = new oxField( $oLang->translateString('RECOMMLIST') );
00394
00395 if ( $sSearchparam = $this->getRecommSearch() ) {
00396 $sUrl = $this->getConfig()->getShopHomeURL()."cl=recommlist&searchrecomm=".rawurlencode( $sSearchparam );
00397 $sTitle = $oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
00398
00399 $aPath[1] = oxNew( "oxcategory" );
00400 $aPath[1]->setLink( $sUrl );
00401 $aPath[1]->oxcategories__oxtitle = new oxField( $sTitle );
00402 }
00403
00404 return $aPath;
00405 }
00406
00412 public function getSearchForHtml()
00413 {
00414
00415 if ( $oActiveRecommList = $this->getActiveRecommList()) {
00416 return $oActiveRecommList->oxrecommlists__oxtitle->value;
00417 }
00418 return oxConfig::getParameter( 'searchrecomm' );
00419 }
00420
00426 public function generatePageNavigationUrl()
00427 {
00428 if ( ( oxRegistry::getUtils()->seoIsActive() && ( $oRecomm = $this->getActiveRecommList() ) ) ) {
00429 $sUrl = $oRecomm->getLink();
00430 } else {
00431 $sUrl = oxUBase::generatePageNavigationUrl();
00432 }
00433 return $sUrl;
00434 }
00435
00445 protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00446 {
00447 if ( oxRegistry::getUtils()->seoIsActive() && ( $oRecomm = $this->getActiveRecommList() ) ) {
00448 if ( $iPage ) {
00449
00450 $sUrl = $oRecomm->getBaseSeoLink( $iLang, $iPage );
00451 }
00452 } else {
00453 $sUrl = oxUBase::_addPageNrParam( $sUrl, $iPage, $iLang );
00454 }
00455 return $sUrl;
00456 }
00457
00463 public function getAdditionalParams()
00464 {
00465 $sAddParams = oxUBase::getAdditionalParams();
00466
00467 if ( $oRecomm = $this->getActiveRecommList() ) {
00468 $sAddParams .= "&recommid=".$oRecomm->getId();
00469 }
00470
00471 if ( $sSearch = $this->getRecommSearch() ) {
00472 $sAddParams .= "&searchrecomm=". rawurlencode( $sSearch );
00473 }
00474
00475 return $sAddParams;
00476 }
00477
00485 public function getLink( $iLang = null )
00486 {
00487 if ( $oRecomm = $this->getActiveRecommList() ) {
00488 $sLink = $oRecomm->getLink( $iLang );
00489 } else {
00490 $sLink = oxUBase::getLink( $iLang );
00491 }
00492 $sSearch = oxConfig::getParameter( 'searchrecomm' );
00493 if ( $sSearch ) {
00494 $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&' ) . "searchrecomm={$sSearch}";
00495 }
00496
00497 return $sLink;
00498 }
00499
00505 public function getBreadCrumb()
00506 {
00507 $aPaths = array();
00508 $aPath = array();
00509
00510 $aPath['title'] = oxRegistry::getLang()->translateString( 'LISTMANIA', oxRegistry::getLang()->getBaseLanguage(), false );
00511 $aPath['link'] = $this->getLink();
00512 $aPaths[] = $aPath;
00513
00514 return $aPaths;
00515 }
00516 }