Go to the documentation of this file.00001 <?php
00002
00008 class RecommList extends aList
00009 {
00010
00016 protected $_sListType = 'recommlist';
00017
00023 protected $_sThisTemplate = 'page/recommendations/recommlist.tpl';
00024
00030 protected $_oOtherRecommList = null;
00031
00037 protected $_aReviews = null;
00038
00044 protected $_blRate = null;
00045
00051 protected $_dRatingValue = null;
00052
00058 protected $_iRatingCnt = null;
00059
00065 protected $_oSearchRecommLists = null;
00066
00072 protected $_sSearch = null;
00073
00079 protected $_sTplLocation = null;
00080
00086 protected $_oPageNavigation = null;
00087
00088
00094 public function render()
00095 {
00096 oxUBase::render();
00097 $myConfig = $this->getConfig();
00098
00099 $this->_iAllArtCnt = 0;
00100
00101 if ($oActiveRecommList = $this->getActiveRecommList()) {
00102 if (($oList = $this->getArticleList()) && $oList->count()) {
00103 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00104 }
00105
00106 if ($myConfig->getConfigParam('bl_rssRecommListArts')) {
00108 $oRss = oxNew('oxrssfeed');
00109 $this->addRssFeed(
00110 $oRss->getRecommListArticlesTitle($oActiveRecommList),
00111 $oRss->getRecommListArticlesUrl($this->_oActiveRecommList),
00112 'recommlistarts'
00113 );
00114 }
00115
00116 } else {
00117 if (($oList = $this->getRecommLists()) && $oList->count()) {
00118 $oRecommList = oxNew('oxrecommlist');
00119 $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount($this->getRecommSearch());
00120 }
00121 }
00122
00123 if (!($oList = $this->getArticleList())) {
00124 $oList = $this->getRecommLists();
00125 }
00126
00127 if ($oList && $oList->count()) {
00128 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
00129 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00130 $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
00131 }
00132
00133 $this->_processListArticles();
00134
00135 return $this->_sThisTemplate;
00136 }
00137
00143 protected function _getProductLinkType()
00144 {
00145 return OXARTICLE_LINKTYPE_RECOMM;
00146 }
00147
00153 public function getAddUrlParams()
00154 {
00155 $sAddParams = parent::getAddUrlParams();
00156 $sAddParams .= ($sAddParams ? '&' : '') . "listtype={$this->_sListType}";
00157
00158 if ($oRecommList = $this->getActiveRecommList()) {
00159 $sAddParams .= "&recommid=" . $oRecommList->getId();
00160 }
00161
00162 return $sAddParams;
00163 }
00164
00170 public function getAddSeoUrlParams()
00171 {
00172 $sAddParams = parent::getAddSeoUrlParams();
00173 if ($sParam = oxRegistry::getConfig()->getRequestParameter("searchrecomm", true)) {
00174 $sAddParams .= "&searchrecomm=" . rawurlencode($sParam);
00175 }
00176
00177 return $sAddParams;
00178 }
00179
00185 public function saveReview()
00186 {
00187 if (!oxRegistry::getSession()->checkSessionChallenge()) {
00188 return;
00189 }
00190
00191 if ($this->canAcceptFormData() &&
00192 ($oRecommList = $this->getActiveRecommList()) && ($oUser = $this->getUser())
00193 ) {
00194
00195
00196 $dRating = oxRegistry::getConfig()->getRequestParameter('recommlistrating');
00197 if ($dRating !== null) {
00198 $dRating = (int) $dRating;
00199 }
00200
00201 if ($dRating !== null && $dRating >= 1 && $dRating <= 5) {
00202 $oRating = oxNew('oxrating');
00203 if ($oRating->allowRating($oUser->getId(), 'oxrecommlist', $oRecommList->getId())) {
00204 $oRating->oxratings__oxuserid = new oxField($oUser->getId());
00205 $oRating->oxratings__oxtype = new oxField('oxrecommlist');
00206 $oRating->oxratings__oxobjectid = new oxField($oRecommList->getId());
00207 $oRating->oxratings__oxrating = new oxField($dRating);
00208 $oRating->save();
00209 $oRecommList->addToRatingAverage($dRating);
00210 }
00211 }
00212
00213 if (($sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true)))) {
00214 $oReview = oxNew('oxreview');
00215 $oReview->oxreviews__oxobjectid = new oxField($oRecommList->getId());
00216 $oReview->oxreviews__oxtype = new oxField('oxrecommlist');
00217 $oReview->oxreviews__oxtext = new oxField($sReviewText, oxField::T_RAW);
00218 $oReview->oxreviews__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
00219 $oReview->oxreviews__oxuserid = new oxField($oUser->getId());
00220 $oReview->oxreviews__oxrating = new oxField(($dRating !== null) ? $dRating : null);
00221 $oReview->save();
00222 }
00223 }
00224 }
00225
00231 public function getNavigationParams()
00232 {
00233 $aParams = oxUBase::getNavigationParams();
00234 $aParams['recommid'] = oxRegistry::getConfig()->getRequestParameter('recommid');
00235
00236 return $aParams;
00237 }
00238
00244 public function getArticleList()
00245 {
00246 if ($this->_aArticleList === null) {
00247 $this->_aArticleList = false;
00248 if ($oActiveRecommList = $this->getActiveRecommList()) {
00249
00250 $iActPage = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
00251 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00252
00253
00254 $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
00255 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00256
00257 $this->_aArticleList = $oActiveRecommList->getArticles(
00258 $iNrofCatArticles * $iActPage,
00259 $iNrofCatArticles
00260 );
00261
00262 if ($this->_aArticleList && $this->_aArticleList->count()) {
00263 foreach ($this->_aArticleList as $oItem) {
00264 $oItem->text = $oActiveRecommList->getArtDescription($oItem->getId());
00265 }
00266 }
00267 }
00268 }
00269
00270 return $this->_aArticleList;
00271 }
00272
00278 public function getSimilarRecommLists()
00279 {
00280 if ($this->_oOtherRecommList === null) {
00281 $this->_oOtherRecommList = false;
00282 if (($oActiveRecommList = $this->getActiveRecommList()) && ($oList = $this->getArticleList())) {
00283 $oRecommLists = $oActiveRecommList->getRecommListsByIds($oList->arrayKeys());
00284
00285 unset($oRecommLists[$oActiveRecommList->getId()]);
00286 $this->_oOtherRecommList = $oRecommLists;
00287 }
00288 }
00289
00290 return $this->_oOtherRecommList;
00291 }
00292
00298 public function getReviews()
00299 {
00300 if ($this->_aReviews === null) {
00301 $this->_aReviews = false;
00302 if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
00303 $this->_aReviews = $oActiveRecommList->getReviews();
00304 }
00305 }
00306
00307 return $this->_aReviews;
00308 }
00309
00315 public function isReviewActive()
00316 {
00317 return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
00318 }
00319
00325 public function canRate()
00326 {
00327 if ($this->_blRate === null) {
00328 $this->_blRate = false;
00329 if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
00330 $oRating = oxNew('oxrating');
00331 $sUserVariable = oxRegistry::getSession()->getVariable('usr');
00332 $this->_blRate = $oRating->allowRating($sUserVariable, 'oxrecommlist', $oActiveRecommList->getId());
00333 }
00334 }
00335
00336 return $this->_blRate;
00337 }
00338
00344 public function getRatingValue()
00345 {
00346 if ($this->_dRatingValue === null) {
00347 $this->_dRatingValue = (double) 0;
00348 if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
00349 $this->_dRatingValue = round($oActiveRecommList->oxrecommlists__oxrating->value, 1);
00350 }
00351 }
00352
00353 return (double) $this->_dRatingValue;
00354 }
00355
00361 public function getRatingCount()
00362 {
00363 if ($this->_iRatingCnt === null) {
00364 $this->_iRatingCnt = false;
00365 if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
00366 $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
00367 }
00368 }
00369
00370 return $this->_iRatingCnt;
00371 }
00372
00378 public function getRecommLists()
00379 {
00380 if ($this->_oSearchRecommLists === null) {
00381 $this->_oSearchRecommLists = array();
00382 if (!$this->getActiveRecommList()) {
00383
00384 $oRecommList = oxNew('oxrecommlist');
00385 $oList = $oRecommList->getSearchRecommLists($this->getRecommSearch());
00386 if ($oList && $oList->count()) {
00387 $this->_oSearchRecommLists = $oList;
00388 }
00389 }
00390 }
00391
00392 return $this->_oSearchRecommLists;
00393 }
00394
00400 public function getRecommSearch()
00401 {
00402 if ($this->_sSearch === null) {
00403 $this->_sSearch = false;
00404 if ($sSearch = oxRegistry::getConfig()->getRequestParameter('searchrecomm', false)) {
00405 $this->_sSearch = $sSearch;
00406 }
00407 }
00408
00409 return $this->_sSearch;
00410 }
00411
00417 public function getTreePath()
00418 {
00419 $oLang = oxRegistry::getLang();
00420
00421 $aPath[0] = oxNew("oxcategory");
00422 $aPath[0]->setLink(false);
00423 $aPath[0]->oxcategories__oxtitle = new oxField($oLang->translateString('RECOMMLIST'));
00424
00425 if ($sSearchParam = $this->getRecommSearch()) {
00426 $shopHomeURL = $this->getConfig()->getShopHomeURL();
00427 $sUrl = $shopHomeURL . "cl=recommlist&searchrecomm=" . rawurlencode($sSearchParam);
00428 $sTitle = $oLang->translateString('RECOMMLIST_SEARCH') . ' "' . $sSearchParam . '"';
00429
00430 $aPath[1] = oxNew("oxcategory");
00431 $aPath[1]->setLink($sUrl);
00432 $aPath[1]->oxcategories__oxtitle = new oxField($sTitle);
00433 }
00434
00435 return $aPath;
00436 }
00437
00443 public function getSearchForHtml()
00444 {
00445
00446 if ($oActiveRecommList = $this->getActiveRecommList()) {
00447 return $oActiveRecommList->oxrecommlists__oxtitle->value;
00448 }
00449
00450 return oxRegistry::getConfig()->getRequestParameter('searchrecomm');
00451 }
00452
00458 public function generatePageNavigationUrl()
00459 {
00460 if ((oxRegistry::getUtils()->seoIsActive() && ($oRecomm = $this->getActiveRecommList()))) {
00461 $sUrl = $oRecomm->getLink();
00462 } else {
00463 $sUrl = oxUBase::generatePageNavigationUrl();
00464 }
00465
00466 return $sUrl;
00467 }
00468
00478 protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
00479 {
00480 if (oxRegistry::getUtils()->seoIsActive() && ($oRecomm = $this->getActiveRecommList())) {
00481 if ($iPage) {
00482
00483 $sUrl = $oRecomm->getBaseSeoLink($iLang, $iPage);
00484 }
00485 } else {
00486 $sUrl = oxUBase::_addPageNrParam($sUrl, $iPage, $iLang);
00487 }
00488
00489 return $sUrl;
00490 }
00491
00497 public function getAdditionalParams()
00498 {
00499 $sAddParams = oxUBase::getAdditionalParams();
00500
00501 if ($oRecomm = $this->getActiveRecommList()) {
00502 $sAddParams .= "&recommid=" . $oRecomm->getId();
00503 }
00504
00505 if ($sSearch = $this->getRecommSearch()) {
00506 $sAddParams .= "&searchrecomm=" . rawurlencode($sSearch);
00507 }
00508
00509 return $sAddParams;
00510 }
00511
00519 public function getLink($iLang = null)
00520 {
00521 if ($oRecomm = $this->getActiveRecommList()) {
00522 $sLink = $oRecomm->getLink($iLang);
00523 } else {
00524 $sLink = oxUBase::getLink($iLang);
00525 }
00526 $sSearch = oxRegistry::getConfig()->getRequestParameter('searchrecomm');
00527 if ($sSearch) {
00528 $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&') . "searchrecomm={$sSearch}";
00529 }
00530
00531 return $sLink;
00532 }
00533
00539 public function getBreadCrumb()
00540 {
00541 $aPaths = array();
00542 $aPath = array();
00543
00544 $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00545 $aPath['title'] = oxRegistry::getLang()->translateString('LISTMANIA', $iBaseLanguage, false);
00546 $aPath['link'] = $this->getLink();
00547 $aPaths[] = $aPath;
00548
00549 return $aPaths;
00550 }
00551
00557 public function getTitle()
00558 {
00559 $oLang = oxRegistry::getLang();
00560 if ($aActiveList = $this->getActiveRecommList()) {
00561 $sTranslatedString = $oLang->translateString('LIST_BY', $oLang->getBaseLanguage(), false);
00562 $sTitleField = 'oxrecommlists__oxtitle';
00563 $sAuthorField = 'oxrecommlists__oxauthor';
00564 $sTitle = $aActiveList->$sTitleField->value . ' (' . $sTranslatedString . ' ' .
00565 $aActiveList->$sAuthorField->value . ')';
00566 } else {
00567 $sTranslatedString = $oLang->translateString('HITS_FOR', $oLang->getBaseLanguage(), false);
00568 $sTitle = $this->getArticleCount() . ' ' . $sTranslatedString . ' "' . $this->getSearchForHtml() . '"';
00569 }
00570
00571 return $sTitle;
00572 }
00573 }