OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
recommlist.php
Go to the documentation of this file.
1 <?php
2 
8 class RecommList extends aList
9 {
14  protected $_sListType = 'recommlist';
15 
20  protected $_sThisTemplate = 'page/recommendations/recommlist.tpl';
21 
26  protected $_oOtherRecommList = null;
27 
32  protected $_aReviews = null;
33 
38  protected $_blRate = null;
39 
44  protected $_dRatingValue = null;
45 
50  protected $_iRatingCnt = null;
51 
56  protected $_oSearchRecommLists = null;
57 
62  protected $_sSearch = null;
63 
69  protected $_sTplLocation = null;
70 
75  protected $_oPageNavigation = null;
76 
77 
83  public function render()
84  {
86  $myConfig = $this->getConfig();
87 
88  $this->_iAllArtCnt = 0;
89 
90  if ( $oActiveRecommList = $this->getActiveRecommList() ) {
91  if ( ( $oList = $this->getArticleList() ) && $oList->count()) {
92  $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
93  }
94 
95  if ( $myConfig->getConfigParam( 'bl_rssRecommListArts' ) ) {
96  $oRss = oxNew('oxrssfeed');
97  $this->addRssFeed($oRss->getRecommListArticlesTitle($oActiveRecommList), $oRss->getRecommListArticlesUrl($this->_oActiveRecommList), 'recommlistarts');
98  }
99 
100  } else {
101  if ( ( $oList = $this->getRecommLists() ) && $oList->count() ) {
102  $oRecommList = oxNew( 'oxrecommlist' );
103  $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount( $this->getRecommSearch() );
104  }
105  }
106 
107  if ( !( $oList = $this->getArticleList() ) ) {
108  $oList = $this->getRecommLists();
109  }
110 
111  if ( $oList && $oList->count() ) {
112  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
113  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
114  $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
115  }
116  // processing list articles
117  $this->_processListArticles();
118 
119  return $this->_sThisTemplate;
120  }
121 
127  protected function _getProductLinkType()
128  {
130  }
131 
137  public function getAddUrlParams()
138  {
139  $sAddParams = parent::getAddUrlParams();
140  $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
141 
142  if ( $oRecommList = $this->getActiveRecommList() ) {
143  $sAddParams .= "&amp;recommid=".$oRecommList->getId();
144  }
145 
146  return $sAddParams;
147  }
148 
154  public function getAddSeoUrlParams()
155  {
156  $sAddParams = parent::getAddSeoUrlParams();
157  if ( $sParam = oxConfig::getParameter( "searchrecomm", true) ) {
158  $sAddParams .= "&amp;searchrecomm=" . rawurlencode( $sParam );
159  }
160  return $sAddParams;
161  }
162 
168  public function saveReview()
169  {
170  if (!oxRegistry::getSession()->checkSessionChallenge()) {
171  return;
172  }
173 
174  if ( $this->canAcceptFormData() &&
175  ( $oRecommList = $this->getActiveRecommList() ) && ( $oUser = $this->getUser() ) ) {
176 
177  //save rating
178  $dRating = oxConfig::getParameter( 'recommlistrating' );
179  if ( $dRating !== null ) {
180  $dRating = (int) $dRating;
181  }
182 
183  if ( $dRating !== null && $dRating >= 1 && $dRating <= 5 ) {
184  $oRating = oxNew( 'oxrating' );
185  if ( $oRating->allowRating( $oUser->getId(), 'oxrecommlist', $oRecommList->getId() ) ) {
186  $oRating->oxratings__oxuserid = new oxField( $oUser->getId() );
187  $oRating->oxratings__oxtype = new oxField( 'oxrecommlist' );
188  $oRating->oxratings__oxobjectid = new oxField( $oRecommList->getId() );
189  $oRating->oxratings__oxrating = new oxField( $dRating );
190  $oRating->save();
191  $oRecommList->addToRatingAverage( $dRating );
192  }
193  }
194 
195  if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
196  $oReview = oxNew( 'oxreview' );
197  $oReview->oxreviews__oxobjectid = new oxField( $oRecommList->getId() );
198  $oReview->oxreviews__oxtype = new oxField( 'oxrecommlist' );
199  $oReview->oxreviews__oxtext = new oxField( $sReviewText, oxField::T_RAW );
200  $oReview->oxreviews__oxlang = new oxField( oxRegistry::getLang()->getBaseLanguage() );
201  $oReview->oxreviews__oxuserid = new oxField( $oUser->getId() );
202  $oReview->oxreviews__oxrating = new oxField( ( $dRating !== null ) ? $dRating : null );
203  $oReview->save();
204  }
205  }
206  }
207 
213  public function getNavigationParams()
214  {
215  $aParams = oxUBase::getNavigationParams();
216  $aParams['recommid'] = oxConfig::getParameter( 'recommid' );
217 
218  return $aParams;
219  }
220 
226  public function getArticleList()
227  {
228  if ( $this->_aArticleList === null ) {
229  $this->_aArticleList = false;
230  if ( $oActiveRecommList = $this->getActiveRecommList()) {
231  // sets active page
232  $iActPage = (int) oxConfig::getParameter( 'pgNr' );
233  $iActPage = ($iActPage < 0) ? 0 : $iActPage;
234 
235  // load only lists which we show on screen
236  $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
237  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
238 
239  $this->_aArticleList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
240 
241  if ( $this->_aArticleList && $this->_aArticleList->count() ) {
242  foreach ( $this->_aArticleList as $oItem ) {
243  $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
244  }
245  }
246  }
247  }
248  return $this->_aArticleList;
249  }
250 
256  public function getSimilarRecommLists()
257  {
258  if ( $this->_oOtherRecommList === null ) {
259  $this->_oOtherRecommList = false;
260  if ( ( $oActiveRecommList = $this->getActiveRecommList() ) && ( $oList = $this->getArticleList() ) ) {
261  $oRecommLists = $oActiveRecommList->getRecommListsByIds( $oList->arrayKeys() );
262  //do not show the same list
263  unset( $oRecommLists[$oActiveRecommList->getId()] );
264  $this->_oOtherRecommList = $oRecommLists;
265  }
266  }
268  }
269 
275  public function getReviews()
276  {
277  if ( $this->_aReviews === null ) {
278  $this->_aReviews = false;
279  if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
280  $this->_aReviews = $oActiveRecommList->getReviews();
281  }
282  }
283  return $this->_aReviews;
284  }
285 
291  public function isReviewActive()
292  {
293  return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
294  }
295 
301  public function canRate()
302  {
303  if ( $this->_blRate === null ) {
304  $this->_blRate = false;
305  if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
306  $oRating = oxNew( 'oxrating' );
307  $this->_blRate = $oRating->allowRating( oxSession::getVar( 'usr' ), 'oxrecommlist', $oActiveRecommList->getId());
308  }
309  }
310  return $this->_blRate;
311  }
312 
318  public function getRatingValue()
319  {
320  if ( $this->_dRatingValue === null ) {
321  $this->_dRatingValue = (double)0;
322  if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
323  $this->_dRatingValue = round( $oActiveRecommList->oxrecommlists__oxrating->value, 1);
324  }
325  }
326  return (double) $this->_dRatingValue;
327  }
328 
334  public function getRatingCount()
335  {
336  if ( $this->_iRatingCnt === null ) {
337  $this->_iRatingCnt = false;
338  if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
339  $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
340  }
341  }
342  return $this->_iRatingCnt;
343  }
344 
350  public function getRecommLists()
351  {
352  if ( $this->_oSearchRecommLists === null ) {
353  $this->_oSearchRecommLists = array();
354  if ( !$this->getActiveRecommList() ) {
355  // list of found oxrecommlists
356  $oRecommList = oxNew( 'oxrecommlist' );
357  $oList = $oRecommList->getSearchRecommLists( $this->getRecommSearch() );
358  if ( $oList && $oList->count() ) {
359  $this->_oSearchRecommLists = $oList;
360  }
361  }
362  }
364  }
365 
371  public function getRecommSearch()
372  {
373  if ( $this->_sSearch === null ) {
374  $this->_sSearch = false;
375  if ( $sSearch = oxConfig::getParameter( 'searchrecomm', false ) ) {
376  $this->_sSearch = $sSearch;
377  }
378  }
379  return $this->_sSearch;
380  }
381 
387  public function getTreePath()
388  {
389  $oLang = oxRegistry::getLang();
390 
391  $aPath[0] = oxNew( "oxcategory" );
392  $aPath[0]->setLink( false );
393  $aPath[0]->oxcategories__oxtitle = new oxField( $oLang->translateString('RECOMMLIST') );
394 
395  if ( $sSearchparam = $this->getRecommSearch() ) {
396  $sUrl = $this->getConfig()->getShopHomeURL()."cl=recommlist&amp;searchrecomm=".rawurlencode( $sSearchparam );
397  $sTitle = $oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
398 
399  $aPath[1] = oxNew( "oxcategory" );
400  $aPath[1]->setLink( $sUrl );
401  $aPath[1]->oxcategories__oxtitle = new oxField( $sTitle );
402  }
403 
404  return $aPath;
405  }
406 
412  public function getSearchForHtml()
413  {
414  // #M1450 if active recommlist is loaded return it's title
415  if ( $oActiveRecommList = $this->getActiveRecommList()) {
416  return $oActiveRecommList->oxrecommlists__oxtitle->value;
417  }
418  return oxConfig::getParameter( 'searchrecomm' );
419  }
420 
426  public function generatePageNavigationUrl()
427  {
428  if ( ( oxRegistry::getUtils()->seoIsActive() && ( $oRecomm = $this->getActiveRecommList() ) ) ) {
429  $sUrl = $oRecomm->getLink();
430  } else {
432  }
433  return $sUrl;
434  }
435 
445  protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
446  {
447  if ( oxRegistry::getUtils()->seoIsActive() && ( $oRecomm = $this->getActiveRecommList() ) ) {
448  if ( $iPage ) {
449  // only if page number > 0
450  $sUrl = $oRecomm->getBaseSeoLink( $iLang, $iPage );
451  }
452  } else {
453  $sUrl = oxUBase::_addPageNrParam( $sUrl, $iPage, $iLang );
454  }
455  return $sUrl;
456  }
457 
463  public function getAdditionalParams()
464  {
465  $sAddParams = oxUBase::getAdditionalParams();
466 
467  if ( $oRecomm = $this->getActiveRecommList() ) {
468  $sAddParams .= "&amp;recommid=".$oRecomm->getId();
469  }
470 
471  if ( $sSearch = $this->getRecommSearch() ) {
472  $sAddParams .= "&amp;searchrecomm=". rawurlencode( $sSearch );
473  }
474 
475  return $sAddParams;
476  }
477 
485  public function getLink( $iLang = null )
486  {
487  if ( $oRecomm = $this->getActiveRecommList() ) {
488  $sLink = $oRecomm->getLink( $iLang );
489  } else {
490  $sLink = oxUBase::getLink( $iLang );
491  }
492  $sSearch = oxConfig::getParameter( 'searchrecomm' );
493  if ( $sSearch ) {
494  $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "searchrecomm={$sSearch}";
495  }
496 
497  return $sLink;
498  }
499 
505  public function getBreadCrumb()
506  {
507  $aPaths = array();
508  $aPath = array();
509 
510  $aPath['title'] = oxRegistry::getLang()->translateString( 'LISTMANIA', oxRegistry::getLang()->getBaseLanguage(), false );
511  $aPath['link'] = $this->getLink();
512  $aPaths[] = $aPath;
513 
514  return $aPaths;
515  }
516 }