OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
recommlist.php
Go to the documentation of this file.
1 <?php
2 
10 class RecommList extends aList
11 {
12 
18  protected $_sListType = 'recommlist';
19 
25  protected $_sThisTemplate = 'page/recommendations/recommlist.tpl';
26 
32  protected $_oOtherRecommList = null;
33 
39  protected $_aReviews = null;
40 
46  protected $_blRate = null;
47 
53  protected $_dRatingValue = null;
54 
60  protected $_iRatingCnt = null;
61 
67  protected $_oSearchRecommLists = null;
68 
74  protected $_sSearch = null;
75 
81  protected $_sTplLocation = null;
82 
88  protected $_oPageNavigation = null;
89 
90 
96  public function render()
97  {
99  $myConfig = $this->getConfig();
100 
101  $this->_iAllArtCnt = 0;
102 
103  if ($oActiveRecommList = $this->getActiveRecommList()) {
104  if (($oList = $this->getArticleList()) && $oList->count()) {
105  $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
106  }
107 
108  if ($myConfig->getConfigParam('bl_rssRecommListArts')) {
110  $oRss = oxNew('oxrssfeed');
111  $this->addRssFeed(
112  $oRss->getRecommListArticlesTitle($oActiveRecommList),
113  $oRss->getRecommListArticlesUrl($this->_oActiveRecommList),
114  'recommlistarts'
115  );
116  }
117 
118  } else {
119  if (($oList = $this->getRecommLists()) && $oList->count()) {
120  $oRecommList = oxNew('oxrecommlist');
121  $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount($this->getRecommSearch());
122  }
123  }
124 
125  if (!($oList = $this->getArticleList())) {
126  $oList = $this->getRecommLists();
127  }
128 
129  if ($oList && $oList->count()) {
130  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
131  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
132  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
133  }
134  // processing list articles
135  $this->_processListArticles();
136 
137  return $this->_sThisTemplate;
138  }
139 
145  protected function _getProductLinkType()
146  {
148  }
149 
155  public function getAddUrlParams()
156  {
157  $sAddParams = parent::getAddUrlParams();
158  $sAddParams .= ($sAddParams ? '&amp;' : '') . "listtype={$this->_sListType}";
159 
160  if ($oRecommList = $this->getActiveRecommList()) {
161  $sAddParams .= "&amp;recommid=" . $oRecommList->getId();
162  }
163 
164  return $sAddParams;
165  }
166 
172  public function getAddSeoUrlParams()
173  {
174  $sAddParams = parent::getAddSeoUrlParams();
175  if ($sParam = oxRegistry::getConfig()->getRequestParameter("searchrecomm", true)) {
176  $sAddParams .= "&amp;searchrecomm=" . rawurlencode($sParam);
177  }
178 
179  return $sAddParams;
180  }
181 
187  public function saveReview()
188  {
189  if (!oxRegistry::getSession()->checkSessionChallenge()) {
190  return;
191  }
192 
193  if ($this->canAcceptFormData() &&
194  ($oRecommList = $this->getActiveRecommList()) && ($oUser = $this->getUser())
195  ) {
196 
197  //save rating
198  $dRating = oxRegistry::getConfig()->getRequestParameter('recommlistrating');
199  if ($dRating !== null) {
200  $dRating = (int) $dRating;
201  }
202 
203  if ($dRating !== null && $dRating >= 1 && $dRating <= 5) {
204  $oRating = oxNew('oxrating');
205  if ($oRating->allowRating($oUser->getId(), 'oxrecommlist', $oRecommList->getId())) {
206  $oRating->oxratings__oxuserid = new oxField($oUser->getId());
207  $oRating->oxratings__oxtype = new oxField('oxrecommlist');
208  $oRating->oxratings__oxobjectid = new oxField($oRecommList->getId());
209  $oRating->oxratings__oxrating = new oxField($dRating);
210  $oRating->save();
211  $oRecommList->addToRatingAverage($dRating);
212  }
213  }
214 
215  if (($sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true)))) {
216  $oReview = oxNew('oxreview');
217  $oReview->oxreviews__oxobjectid = new oxField($oRecommList->getId());
218  $oReview->oxreviews__oxtype = new oxField('oxrecommlist');
219  $oReview->oxreviews__oxtext = new oxField($sReviewText, oxField::T_RAW);
220  $oReview->oxreviews__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
221  $oReview->oxreviews__oxuserid = new oxField($oUser->getId());
222  $oReview->oxreviews__oxrating = new oxField(($dRating !== null) ? $dRating : null);
223  $oReview->save();
224  }
225  }
226  }
227 
233  public function getNavigationParams()
234  {
235  $aParams = oxUBase::getNavigationParams();
236  $aParams['recommid'] = oxRegistry::getConfig()->getRequestParameter('recommid');
237 
238  return $aParams;
239  }
240 
246  public function getArticleList()
247  {
248  if ($this->_aArticleList === null) {
249  $this->_aArticleList = false;
250  if ($oActiveRecommList = $this->getActiveRecommList()) {
251  // sets active page
252  $iActPage = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
253  $iActPage = ($iActPage < 0) ? 0 : $iActPage;
254 
255  // load only lists which we show on screen
256  $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
257  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
258 
259  $this->_aArticleList = $oActiveRecommList->getArticles(
260  $iNrofCatArticles * $iActPage,
261  $iNrofCatArticles
262  );
263 
264  if ($this->_aArticleList && $this->_aArticleList->count()) {
265  foreach ($this->_aArticleList as $oItem) {
266  $oItem->text = $oActiveRecommList->getArtDescription($oItem->getId());
267  }
268  }
269  }
270  }
271 
272  return $this->_aArticleList;
273  }
274 
280  public function getSimilarRecommLists()
281  {
282  if ($this->_oOtherRecommList === null) {
283  $this->_oOtherRecommList = false;
284  if (($oActiveRecommList = $this->getActiveRecommList()) && ($oList = $this->getArticleList())) {
285  $oRecommLists = $oActiveRecommList->getRecommListsByIds($oList->arrayKeys());
286  //do not show the same list
287  unset($oRecommLists[$oActiveRecommList->getId()]);
288  $this->_oOtherRecommList = $oRecommLists;
289  }
290  }
291 
293  }
294 
300  public function getReviews()
301  {
302  if ($this->_aReviews === null) {
303  $this->_aReviews = false;
304  if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
305  $this->_aReviews = $oActiveRecommList->getReviews();
306  }
307  }
308 
309  return $this->_aReviews;
310  }
311 
317  public function isReviewActive()
318  {
319  return $this->getConfig()->getConfigParam('bl_perfLoadReviews');
320  }
321 
327  public function canRate()
328  {
329  if ($this->_blRate === null) {
330  $this->_blRate = false;
331  if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
332  $oRating = oxNew('oxrating');
333  $sUserVariable = oxRegistry::getSession()->getVariable('usr');
334  $this->_blRate = $oRating->allowRating($sUserVariable, 'oxrecommlist', $oActiveRecommList->getId());
335  }
336  }
337 
338  return $this->_blRate;
339  }
340 
346  public function getRatingValue()
347  {
348  if ($this->_dRatingValue === null) {
349  $this->_dRatingValue = (double) 0;
350  if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
351  $this->_dRatingValue = round($oActiveRecommList->oxrecommlists__oxrating->value, 1);
352  }
353  }
354 
355  return (double) $this->_dRatingValue;
356  }
357 
363  public function getRatingCount()
364  {
365  if ($this->_iRatingCnt === null) {
366  $this->_iRatingCnt = false;
367  if ($this->isReviewActive() && ($oActiveRecommList = $this->getActiveRecommList())) {
368  $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
369  }
370  }
371 
372  return $this->_iRatingCnt;
373  }
374 
380  public function getRecommLists()
381  {
382  if ($this->_oSearchRecommLists === null) {
383  $this->_oSearchRecommLists = array();
384  if (!$this->getActiveRecommList()) {
385  // list of found oxrecommlists
386  $oRecommList = oxNew('oxrecommlist');
387  $oList = $oRecommList->getSearchRecommLists($this->getRecommSearch());
388  if ($oList && $oList->count()) {
389  $this->_oSearchRecommLists = $oList;
390  }
391  }
392  }
393 
395  }
396 
402  public function getRecommSearch()
403  {
404  if ($this->_sSearch === null) {
405  $this->_sSearch = false;
406  if ($sSearch = oxRegistry::getConfig()->getRequestParameter('searchrecomm', false)) {
407  $this->_sSearch = $sSearch;
408  }
409  }
410 
411  return $this->_sSearch;
412  }
413 
419  public function getTreePath()
420  {
421  $oLang = oxRegistry::getLang();
422 
423  $aPath[0] = oxNew("oxcategory");
424  $aPath[0]->setLink(false);
425  $aPath[0]->oxcategories__oxtitle = new oxField($oLang->translateString('RECOMMLIST'));
426 
427  if ($sSearchParam = $this->getRecommSearch()) {
428  $shopHomeURL = $this->getConfig()->getShopHomeURL();
429  $sUrl = $shopHomeURL . "cl=recommlist&amp;searchrecomm=" . rawurlencode($sSearchParam);
430  $sTitle = $oLang->translateString('RECOMMLIST_SEARCH') . ' "' . $sSearchParam . '"';
431 
432  $aPath[1] = oxNew("oxcategory");
433  $aPath[1]->setLink($sUrl);
434  $aPath[1]->oxcategories__oxtitle = new oxField($sTitle);
435  }
436 
437  return $aPath;
438  }
439 
445  public function getSearchForHtml()
446  {
447  // #M1450 if active recommlist is loaded return it's title
448  if ($oActiveRecommList = $this->getActiveRecommList()) {
449  return $oActiveRecommList->oxrecommlists__oxtitle->value;
450  }
451 
452  return oxRegistry::getConfig()->getRequestParameter('searchrecomm');
453  }
454 
460  public function generatePageNavigationUrl()
461  {
462  if ((oxRegistry::getUtils()->seoIsActive() && ($oRecomm = $this->getActiveRecommList()))) {
463  $sUrl = $oRecomm->getLink();
464  } else {
466  }
467 
468  return $sUrl;
469  }
470 
480  protected function _addPageNrParam($sUrl, $iPage, $iLang = null)
481  {
482  if (oxRegistry::getUtils()->seoIsActive() && ($oRecomm = $this->getActiveRecommList())) {
483  if ($iPage) {
484  // only if page number > 0
485  $sUrl = $oRecomm->getBaseSeoLink($iLang, $iPage);
486  }
487  } else {
488  $sUrl = oxUBase::_addPageNrParam($sUrl, $iPage, $iLang);
489  }
490 
491  return $sUrl;
492  }
493 
499  public function getAdditionalParams()
500  {
501  $sAddParams = oxUBase::getAdditionalParams();
502 
503  if ($oRecomm = $this->getActiveRecommList()) {
504  $sAddParams .= "&amp;recommid=" . $oRecomm->getId();
505  }
506 
507  if ($sSearch = $this->getRecommSearch()) {
508  $sAddParams .= "&amp;searchrecomm=" . rawurlencode($sSearch);
509  }
510 
511  return $sAddParams;
512  }
513 
521  public function getLink($iLang = null)
522  {
523  if ($oRecomm = $this->getActiveRecommList()) {
524  $sLink = $oRecomm->getLink($iLang);
525  } else {
526  $sLink = oxUBase::getLink($iLang);
527  }
528  $sSearch = oxRegistry::getConfig()->getRequestParameter('searchrecomm');
529  if ($sSearch) {
530  $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&amp;') . "searchrecomm={$sSearch}";
531  }
532 
533  return $sLink;
534  }
535 
541  public function getBreadCrumb()
542  {
543  $aPaths = array();
544  $aPath = array();
545 
546  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
547  $aPath['title'] = oxRegistry::getLang()->translateString('LISTMANIA', $iBaseLanguage, false);
548  $aPath['link'] = $this->getLink();
549  $aPaths[] = $aPath;
550 
551  return $aPaths;
552  }
553 
559  public function getTitle()
560  {
561  $oLang = oxRegistry::getLang();
562  if ($aActiveList = $this->getActiveRecommList()) {
563  $sTranslatedString = $oLang->translateString('LIST_BY', $oLang->getBaseLanguage(), false);
564  $sTitleField = 'oxrecommlists__oxtitle';
565  $sAuthorField = 'oxrecommlists__oxauthor';
566  $sTitle = $aActiveList->$sTitleField->value . ' (' . $sTranslatedString . ' ' .
567  $aActiveList->$sAuthorField->value . ')';
568  } else {
569  $sTranslatedString = $oLang->translateString('HITS_FOR', $oLang->getBaseLanguage(), false);
570  $sTitle = $this->getArticleCount() . ' ' . $sTranslatedString . ' "' . $this->getSearchForHtml() . '"';
571  }
572 
573  return $sTitle;
574  }
575 }