OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
review.php
Go to the documentation of this file.
1 <?php
2 
7 class Review extends Details
8 {
13  protected $_oRevUser = null;
14 
19  protected $_oActObject = null;
20 
25  protected $_oActiveRecommList = null;
26 
31  protected $_oActiveRecommItems = null;
32 
37  protected $_blRate = null;
38 
43  protected $_aReviews = null;
44 
49  protected $_oCrossSelling = null;
50 
55  protected $_oSimilarProducts = null;
56 
61  protected $_oRecommList = null;
62 
67  protected $_blReviewSendStatus = null;
68 
73  protected $_oPageNavigation = null;
74 
79  protected $_sThisTemplate = 'page/review/review.tpl';
80 
85  protected $_sThisLoginTemplate = 'page/review/review_login.tpl';
86 
93 
99  public function getViewId()
100  {
101  return oxUBase::getViewId();
102  }
103 
109  public function init()
110  {
111  if ( oxConfig::getParameter( 'recommid' ) && !$this->getActiveRecommList() ) {
112  oxRegistry::getUtils()->redirect( $this->getConfig()->getShopHomeURL(), true, 302 );
113  }
114 
115  oxUBase::init();
116  }
117 
126  public function render()
127  {
128  $oConfig = $this->getConfig();
129 
130  if ( !$oConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
131  oxRegistry::getUtils()->redirect( $oConfig->getShopHomeURL() );
132  }
133 
134  oxUBase::render();
135  if ( ! ( $this->getReviewUser() ) ) {
136  $this->_sThisTemplate = $this->_sThisLoginTemplate;
137  } else {
138 
139  $oActiveRecommList = $this->getActiveRecommList();
140  $oList = $this->getActiveRecommItems();
141 
142  if ( $oActiveRecommList ) {
143  if ( $oList && $oList->count()) {
144  $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
145  }
146  // load only lists which we show on screen
147  $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
148  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
149  $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
150  }
151  }
152 
153  return $this->_sThisTemplate;
154  }
155 
161  public function saveReview()
162  {
163  if (!oxRegistry::getSession()->checkSessionChallenge()) {
164  return;
165  }
166 
167  if ( ( $oRevUser = $this->getReviewUser() ) && $this->canAcceptFormData() ) {
168 
169  if ( ( $oActObject = $this->_getActiveObject() ) && ( $sType = $this->_getActiveType() ) ) {
170 
171  if ( ( $dRating = oxConfig::getParameter( 'rating' ) ) === null ) {
172  $dRating = oxConfig::getParameter( 'artrating' );
173  }
174 
175  if ( $dRating !== null ) {
176  $dRating = (int) $dRating;
177  }
178 
179  //save rating
180  if ( $dRating !== null && $dRating >= 1 && $dRating <= 5 ) {
181  $oRating = oxNew( 'oxrating' );
182  if ( $oRating->allowRating( $oRevUser->getId(), $sType, $oActObject->getId() ) ) {
183  $oRating->oxratings__oxuserid = new oxField( $oRevUser->getId() );
184  $oRating->oxratings__oxtype = new oxField( $sType );
185  $oRating->oxratings__oxobjectid = new oxField( $oActObject->getId() );
186  $oRating->oxratings__oxrating = new oxField( $dRating );
187  $oRating->save();
188 
189  $oActObject->addToRatingAverage( $dRating);
190 
191  $this->_blReviewSendStatus = true;
192  }
193  }
194 
195  if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
196  $oReview = oxNew( 'oxreview' );
197  $oReview->oxreviews__oxobjectid = new oxField( $oActObject->getId() );
198  $oReview->oxreviews__oxtype = new oxField( $sType );
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( $oRevUser->getId() );
202  $oReview->oxreviews__oxrating = new oxField( ( $dRating !== null ) ? $dRating : null );
203  $oReview->save();
204 
205  $this->_blReviewSendStatus = true;
206  }
207  }
208  }
209  }
210 
216  public function getReviewUser()
217  {
218  if ( $this->_oRevUser === null ) {
219  $this->_oRevUser = false;
220  $oUser = oxNew( "oxuser" );
221 
222  if ( $sUserId = $oUser->getReviewUserId( $this->getReviewUserHash() ) ) {
223  // review user, by link or other source?
224  if ( $oUser->load( $sUserId ) ) {
225  $this->_oRevUser = $oUser;
226  }
227  } elseif ( $oUser = $this->getUser() ) {
228  // session user?
229  $this->_oRevUser = $oUser;
230  }
231 
232  }
233  return $this->_oRevUser;
234  }
235 
241  public function getReviewUserHash()
242  {
243  return oxConfig::getParameter( 'reviewuserhash' );
244  }
245 
251  protected function _getActiveObject()
252  {
253  if ( $this->_oActObject === null ) {
254  $this->_oActObject = false;
255 
256  if ( ( $oProduct = $this->getProduct() ) ) {
257  $this->_oActObject = $oProduct;
258  } elseif ( ( $oRecommList = $this->getActiveRecommList() ) ) {
259  $this->_oActObject = $oRecommList;
260  }
261  }
262  return $this->_oActObject;
263  }
264 
270  protected function _getActiveType()
271  {
272  $sType = null;
273  if ( $this->getProduct() ) {
274  $sType = 'oxarticle';
275  } elseif ( $this->getActiveRecommList() ) {
276  $sType = 'oxrecommlist';
277  }
278  return $sType;
279  }
280 
286  public function getActiveRecommList()
287  {
288  if (!$this->getViewConfig()->getShowListmania()) {
289  return false;
290  }
291 
292  if ( $this->_oActiveRecommList === null ) {
293  $this->_oActiveRecommList = false;
294 
295  if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
296  $oActiveRecommList = oxNew('oxrecommlist');
297  if ( $oActiveRecommList->load( $sRecommId ) ) {
298  $this->_oActiveRecommList = $oActiveRecommList;
299  }
300  }
301  }
303  }
304 
310  public function canRate()
311  {
312  if ( $this->_blRate === null ) {
313  $this->_blRate = false;
314  if ( ( $oActObject = $this->_getActiveObject() ) && ( $oRevUser = $this->getReviewUser() ) ) {
315  $oRating = oxNew( 'oxrating' );
316  $this->_blRate = $oRating->allowRating( $oRevUser->getId(), $this->_getActiveType(), $oActObject->getId() );
317  }
318  }
319  return $this->_blRate;
320  }
321 
327  public function getReviews()
328  {
329  if ( $this->_aReviews === null ) {
330  $this->_aReviews = false;
331  if ( $oObject = $this->_getActiveObject() ) {
332  $this->_aReviews = $oObject->getReviews();
333  }
334  }
335  return $this->_aReviews;
336  }
337 
343  public function getRecommList()
344  {
345  if ( $this->_oRecommList === null ) {
346  $this->_oRecommList = false;
347  if ( $oProduct = $this->getProduct() ) {
348  $oRecommList = oxNew('oxrecommlist');
349  $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
350  }
351  }
352  return $this->_oRecommList;
353  }
354 
360  public function getActiveRecommItems()
361  {
362  if ( $this->_oActiveRecommItems === null ) {
363  $this->_oActiveRecommItems = false;
364  if ( $oActiveRecommList = $this->getActiveRecommList()) {
365  // sets active page
366  $iActPage = (int) oxConfig::getParameter( 'pgNr' );
367  $iActPage = ($iActPage < 0) ? 0 : $iActPage;
368 
369  // load only lists which we show on screen
370  $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
371  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
372 
373  $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
374 
375  if ( $oList && $oList->count() ) {
376  foreach ( $oList as $oItem) {
377  $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
378  }
379  $this->_oActiveRecommItems = $oList;
380  }
381  }
382  }
384  }
385 
391  public function getReviewSendStatus()
392  {
394  }
395 
401  public function getPageNavigation()
402  {
403  if ( $this->_oPageNavigation === null ) {
404  $this->_oPageNavigation = false;
405  if ( $this->getActiveRecommList() ) {
406  $this->_oPageNavigation = $this->generatePageNavigation();
407  }
408  }
410  }
411 
417  public function getAdditionalParams()
418  {
419  $sAddParams = oxUBase::getAdditionalParams();
420  if ( $oActRecommList = $this->getActiveRecommList() ) {
421  $sAddParams .= '&amp;recommid='.$oActRecommList->getId();
422  }
423  return $sAddParams;
424  }
425 
431  public function getDynUrlParams()
432  {
433  $sParams = parent::getDynUrlParams();
434 
435  if ( $sCnId = oxConfig::getParameter( 'cnid' ) ) {
436  $sParams .= "&amp;cnid={$sCnId}";
437  }
438  if ( $sAnId = oxConfig::getParameter( 'anid' ) ) {
439  $sParams .= "&amp;anid={$sAnId}";
440  }
441  if ( $sListType = oxConfig::getParameter( 'listtype' ) ) {
442  $sParams .= "&amp;listtype={$sListType}";
443  }
444  if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
445  $sParams .= "&amp;recommid={$sRecommId}";
446  }
447 
448  return $sParams;
449  }
450 }