OXID eShop CE  4.9.7
 All Classes Files Functions Variables Pages
recommlist.php
Go to the documentation of this file.
1 <?php
2 
8 class RecommList extends aList
9 {
10 
16  protected $_sListType = 'recommlist';
17 
23  protected $_sThisTemplate = 'page/recommendations/recommlist.tpl';
24 
30  protected $_oOtherRecommList = null;
31 
37  protected $_aReviews = null;
38 
44  protected $_blRate = null;
45 
51  protected $_dRatingValue = null;
52 
58  protected $_iRatingCnt = null;
59 
65  protected $_oSearchRecommLists = null;
66 
72  protected $_sSearch = null;
73 
79  protected $_sTplLocation = null;
80 
86  protected $_oPageNavigation = null;
87 
88 
94  public function render()
95  {
97  $myConfig = $this->getConfig();
98 
99  $this->_iAllArtCnt = 0;
100 
101  if ($oActiveRecommList = $this->getActiveRecommList()) {
102  if (($oList = $this->getArticleList()) && $oList->count()) {
103  $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
104  }
105 
106  if ($myConfig->getConfigParam('bl_rssRecommListArts')) {
108  $oRss = oxNew('oxrssfeed');
109  $this->addRssFeed(
110  $oRss->getRecommListArticlesTitle($oActiveRecommList),
111  $oRss->getRecommListArticlesUrl($this->_oActiveRecommList),
112  'recommlistarts'
113  );
114  }
115 
116  } else {
117  if (($oList = $this->getRecommLists()) && $oList->count()) {
118  $oRecommList = oxNew('oxrecommlist');
119  $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount($this->getRecommSearch());
120  }
121  }
122 
123  if (!($oList = $this->getArticleList())) {
124  $oList = $this->getRecommLists();
125  }
126 
127  if ($oList && $oList->count()) {
128  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
129  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
130  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
131  }
132  // processing list articles
133  $this->_processListArticles();
134 
135  return $this->_sThisTemplate;
136  }
137 
143  protected function _getProductLinkType()
144  {
146  }
147 
153  public function getAddUrlParams()
154  {
155  $sAddParams = parent::getAddUrlParams();
156  $sAddParams .= ($sAddParams ? '&amp;' : '') . "listtype={$this->_sListType}";
157 
158  if ($oRecommList = $this->getActiveRecommList()) {
159  $sAddParams .= "&amp;recommid=" . $oRecommList->getId();
160  }
161 
162  return $sAddParams;
163  }
164 
170  public function getAddSeoUrlParams()
171  {
172  $sAddParams = parent::getAddSeoUrlParams();
173  if ($sParam = oxRegistry::getConfig()->getRequestParameter("searchrecomm", true)) {
174  $sAddParams .= "&amp;searchrecomm=" . rawurlencode($sParam);
175  }
176 
177  return $sAddParams;
178  }
179 
185  public function saveReview()
186  {
187  if (!oxRegistry::getSession()->checkSessionChallenge()) {
188  return;
189  }
190 
191  if ($this->canAcceptFormData() &&
192  ($oRecommList = $this->getActiveRecommList()) && ($oUser = $this->getUser())
193  ) {
194 
195  //save rating
196  $dRating = oxRegistry::getConfig()->getRequestParameter('recommlistrating');
197  if ($dRating !== null) {
198  $dRating = (int) $dRating;
199  }
200 
201  if ($dRating !== null && $dRating >= 1 && $dRating <= 5) {
202  $oRating = oxNew('oxrating');
203  if ($oRating->allowRating($oUser->getId(), 'oxrecommlist', $oRecommList->getId())) {
204  $oRating->oxratings__oxuserid = new oxField($oUser->getId());
205  $oRating->oxratings__oxtype = new oxField('oxrecommlist');
206  $oRating->oxratings__oxobjectid = new oxField($oRecommList->getId());
207  $oRating->oxratings__oxrating = new oxField($dRating);
208  $oRating->save();
209  $oRecommList->addToRatingAverage($dRating);
210  }
211  }
212 
213  if (($sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true)))) {
214  $oReview = oxNew('oxreview');
215  $oReview->oxreviews__oxobjectid = new oxField($oRecommList->getId());
216  $oReview->oxreviews__oxtype = new oxField('oxrecommlist');
217  $oReview->oxreviews__oxtext = new oxField($sReviewText, oxField::T_RAW);
218  $oReview->oxreviews__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
219  $oReview->oxreviews__oxuserid = new oxField($oUser->getId());
220  $oReview->oxreviews__oxrating = new oxField(($dRating !== null) ? $dRating : null);
221  $oReview->save();
222  }
223  }
224  }
225 
231  public function getNavigationParams()
232  {
233  $aParams = oxUBase::getNavigationParams();
234  $aParams['recommid'] = oxRegistry::getConfig()->getRequestParameter('recommid');
235 
236  return $aParams;
237  }
238 
244  public function getArticleList()
245  {
246  if ($this->_aArticleList === null) {
247  $this->_aArticleList = false;
248  if ($oActiveRecommList = $this->getActiveRecommList()) {
249  // sets active page
250  $iActPage = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
251  $iActPage = ($iActPage < 0) ? 0 : $iActPage;
252 
253  // load only lists which we show on screen
254  $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
255  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
256 
257  $this->_aArticleList = $oActiveRecommList->getArticles(
258  $iNrofCatArticles * $iActPage,
259  $iNrofCatArticles
260  );
261 
262  if ($this->_aArticleList && $this->_aArticleList->count()) {
263  foreach ($this->_aArticleList as $oItem) {
264  $oItem->text = $oActiveRecommList->getArtDescription($oItem->getId());
265  }
266  }
267  }
268  }
269 
270  return $this->_aArticleList;
271  }
272 
278  public function getSimilarRecommLists()
279  {
280  if ($this->_oOtherRecommList === null) {
281  $this->_oOtherRecommList = false;
282  if (($oActiveRecommList = $this->getActiveRecommList()) && ($oList = $this->getArticleList())) {
283  $oRecommLists = $oActiveRecommList->getRecommListsByIds($oList->arrayKeys());
284  //do not show the same list
285  unset($oRecommLists[$oActiveRecommList->getId()]);
286  $this->_oOtherRecommList = $oRecommLists;
287  }
288  }
289 
291  }
292 
298  public function getReviews()
299  {
300  if ($this->_aReviews === null) {
301  $this->_aReviews = false;
302  if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
303  $this->_aReviews = $oActiveRecommList->getReviews();
304  }
305  }
306 
307  return $this->_aReviews;
308  }
309 
315  public function isReviewActive()
316  {
317  return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
318  }
319 
325  public function canRate()
326  {
327  if ($this->_blRate === null) {
328  $this->_blRate = false;
329  if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
330  $oRating = oxNew('oxrating');
331  $sUserVariable = oxRegistry::getSession()->getVariable('usr');
332  $this->_blRate = $oRating->allowRating($sUserVariable, 'oxrecommlist', $oActiveRecommList->getId());
333  }
334  }
335 
336  return $this->_blRate;
337  }
338 
344  public function getRatingValue()
345  {
346  if ($this->_dRatingValue === null) {
347  $this->_dRatingValue = (double) 0;
348  if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
349  $this->_dRatingValue = round($oActiveRecommList->oxrecommlists__oxrating->value, 1);
350  }
351  }
352 
353  return (double) $this->_dRatingValue;
354  }
355 
361  public function getRatingCount()
362  {
363  if ($this->_iRatingCnt === null) {
364  $this->_iRatingCnt = false;
365  if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
366  $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
367  }
368  }
369 
370  return $this->_iRatingCnt;
371  }
372 
378  public function getRecommLists()
379  {
380  if ($this->_oSearchRecommLists === null) {
381  $this->_oSearchRecommLists = array();
382  if (!$this->getActiveRecommList()) {
383  // list of found oxrecommlists
384  $oRecommList = oxNew('oxrecommlist');
385  $oList = $oRecommList->getSearchRecommLists($this->getRecommSearch());
386  if ($oList && $oList->count()) {
387  $this->_oSearchRecommLists = $oList;
388  }
389  }
390  }
391 
393  }
394 
400  public function getRecommSearch()
401  {
402  if ($this->_sSearch === null) {
403  $this->_sSearch = false;
404  if ($sSearch = oxRegistry::getConfig()->getRequestParameter('searchrecomm', false)) {
405  $this->_sSearch = $sSearch;
406  }
407  }
408 
409  return $this->_sSearch;
410  }
411 
417  public function getTreePath()
418  {
419  $oLang = oxRegistry::getLang();
420 
421  $aPath[0] = oxNew("oxcategory");
422  $aPath[0]->setLink(false);
423  $aPath[0]->oxcategories__oxtitle = new oxField($oLang->translateString('RECOMMLIST'));
424 
425  if ($sSearchParam = $this->getRecommSearch()) {
426  $shopHomeURL = $this->getConfig()->getShopHomeURL();
427  $sUrl = $shopHomeURL . "cl=recommlist&amp;searchrecomm=" . rawurlencode($sSearchParam);
428  $sTitle = $oLang->translateString('RECOMMLIST_SEARCH') . ' "' . $sSearchParam . '"';
429 
430  $aPath[1] = oxNew("oxcategory");
431  $aPath[1]->setLink($sUrl);
432  $aPath[1]->oxcategories__oxtitle = new oxField($sTitle);
433  }
434 
435  return $aPath;
436  }
437 
443  public function getSearchForHtml()
444  {
445  // #M1450 if active recommlist is loaded return it's title
446  if ($oActiveRecommList = $this->getActiveRecommList()) {
447  return $oActiveRecommList->oxrecommlists__oxtitle->value;
448  }
449 
450  return oxRegistry::getConfig()->getRequestParameter('searchrecomm');
451  }
452 
458  public function generatePageNavigationUrl()
459  {
460  if ((oxRegistry::getUtils()->seoIsActive() && ($oRecomm = $this->getActiveRecommList()))) {
461  $sUrl = $oRecomm->getLink();
462  } else {
464  }
465 
466  return $sUrl;
467  }
468 
478  protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
479  {
480  if (oxRegistry::getUtils()->seoIsActive() && ($oRecomm = $this->getActiveRecommList())) {
481  if ($iPage) {
482  // only if page number > 0
483  $sUrl = $oRecomm->getBaseSeoLink($iLang, $iPage);
484  }
485  } else {
486  $sUrl = oxUBase::_addPageNrParam($sUrl, $iPage, $iLang);
487  }
488 
489  return $sUrl;
490  }
491 
497  public function getAdditionalParams()
498  {
499  $sAddParams = oxUBase::getAdditionalParams();
500 
501  if ($oRecomm = $this->getActiveRecommList()) {
502  $sAddParams .= "&amp;recommid=" . $oRecomm->getId();
503  }
504 
505  if ($sSearch = $this->getRecommSearch()) {
506  $sAddParams .= "&amp;searchrecomm=" . rawurlencode($sSearch);
507  }
508 
509  return $sAddParams;
510  }
511 
519  public function getLink($iLang = null)
520  {
521  if ($oRecomm = $this->getActiveRecommList()) {
522  $sLink = $oRecomm->getLink($iLang);
523  } else {
524  $sLink = oxUBase::getLink($iLang);
525  }
526  $sSearch = oxRegistry::getConfig()->getRequestParameter('searchrecomm');
527  if ($sSearch) {
528  $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&amp;') . "searchrecomm={$sSearch}";
529  }
530 
531  return $sLink;
532  }
533 
539  public function getBreadCrumb()
540  {
541  $aPaths = array();
542  $aPath = array();
543 
544  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
545  $aPath['title'] = oxRegistry::getLang()->translateString('LISTMANIA', $iBaseLanguage, false);
546  $aPath['link'] = $this->getLink();
547  $aPaths[] = $aPath;
548 
549  return $aPaths;
550  }
551 
557  public function getTitle()
558  {
559  $oLang = oxRegistry::getLang();
560  if ($aActiveList = $this->getActiveRecommList()) {
561  $sTranslatedString = $oLang->translateString('LIST_BY', $oLang->getBaseLanguage(), false);
562  $sTitleField = 'oxrecommlists__oxtitle';
563  $sAuthorField = 'oxrecommlists__oxauthor';
564  $sTitle = $aActiveList->$sTitleField->value . ' (' . $sTranslatedString . ' ' .
565  $aActiveList->$sAuthorField->value . ')';
566  } else {
567  $sTranslatedString = $oLang->translateString('HITS_FOR', $oLang->getBaseLanguage(), false);
568  $sTitle = $this->getArticleCount() . ' ' . $sTranslatedString . ' "' . $this->getSearchForHtml() . '"';
569  }
570 
571  return $sTitle;
572  }
573 }