OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
review.php
Go to the documentation of this file.
1 <?php
2 
7 class Review extends Details
8 {
9 
15  protected $_oRevUser = null;
16 
22  protected $_oActObject = null;
23 
29  protected $_oActiveRecommList = null;
30 
36  protected $_oActiveRecommItems = null;
37 
43  protected $_blRate = null;
44 
50  protected $_aReviews = null;
51 
57  protected $_oCrossSelling = null;
58 
64  protected $_oSimilarProducts = null;
65 
71  protected $_oRecommList = null;
72 
78  protected $_blReviewSendStatus = null;
79 
85  protected $_oPageNavigation = null;
86 
92  protected $_sThisTemplate = 'page/review/review.tpl';
93 
99  protected $_sThisLoginTemplate = 'page/review/review_login.tpl';
100 
107 
113  public function getViewId()
114  {
115  return oxUBase::getViewId();
116  }
117 
121  public function init()
122  {
123  if (oxRegistry::getConfig()->getRequestParameter('recommid') && !$this->getActiveRecommList()) {
124  oxRegistry::getUtils()->redirect($this->getConfig()->getShopHomeURL(), true, 302);
125  }
126 
127  oxUBase::init();
128  }
129 
138  public function render()
139  {
140  $oConfig = $this->getConfig();
141 
142  if (!$oConfig->getConfigParam("bl_perfLoadReviews")) {
143  oxRegistry::getUtils()->redirect($oConfig->getShopHomeURL());
144  }
145 
146  oxUBase::render();
147  if (!($this->getReviewUser())) {
148  $this->_sThisTemplate = $this->_sThisLoginTemplate;
149  } else {
150 
151  $oActiveRecommList = $this->getActiveRecommList();
152  $oList = $this->getActiveRecommItems();
153 
154  if ($oActiveRecommList) {
155  if ($oList && $oList->count()) {
156  $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
157  }
158  // load only lists which we show on screen
159  $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
160  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
161  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
162  }
163  }
164 
165  return $this->_sThisTemplate;
166  }
167 
173  public function saveReview()
174  {
175  if (!oxRegistry::getSession()->checkSessionChallenge()) {
176  return;
177  }
178 
179  if (($oRevUser = $this->getReviewUser()) && $this->canAcceptFormData()) {
180 
181  if (($oActObject = $this->_getActiveObject()) && ($sType = $this->_getActiveType())) {
182 
183  if (($dRating = oxRegistry::getConfig()->getRequestParameter('rating')) === null) {
184  $dRating = oxRegistry::getConfig()->getRequestParameter('artrating');
185  }
186 
187  if ($dRating !== null) {
188  $dRating = (int) $dRating;
189  }
190 
191  //save rating
192  if ($dRating !== null && $dRating >= 1 && $dRating <= 5) {
193  $oRating = oxNew('oxrating');
194  if ($oRating->allowRating($oRevUser->getId(), $sType, $oActObject->getId())) {
195  $oRating->oxratings__oxuserid = new oxField($oRevUser->getId());
196  $oRating->oxratings__oxtype = new oxField($sType);
197  $oRating->oxratings__oxobjectid = new oxField($oActObject->getId());
198  $oRating->oxratings__oxrating = new oxField($dRating);
199  $oRating->save();
200 
201  $oActObject->addToRatingAverage($dRating);
202 
203  $this->_blReviewSendStatus = true;
204  }
205  }
206 
207  if (($sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true)))) {
208  $oReview = oxNew('oxreview');
209  $oReview->oxreviews__oxobjectid = new oxField($oActObject->getId());
210  $oReview->oxreviews__oxtype = new oxField($sType);
211  $oReview->oxreviews__oxtext = new oxField($sReviewText, oxField::T_RAW);
212  $oReview->oxreviews__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
213  $oReview->oxreviews__oxuserid = new oxField($oRevUser->getId());
214  $oReview->oxreviews__oxrating = new oxField(($dRating !== null) ? $dRating : null);
215  $oReview->save();
216 
217  $this->_blReviewSendStatus = true;
218  }
219  }
220  }
221  }
222 
228  public function getReviewUser()
229  {
230  if ($this->_oRevUser === null) {
231  $this->_oRevUser = false;
232  $oUser = oxNew("oxuser");
233 
234  if ($sUserId = $oUser->getReviewUserId($this->getReviewUserHash())) {
235  // review user, by link or other source?
236  if ($oUser->load($sUserId)) {
237  $this->_oRevUser = $oUser;
238  }
239  } elseif ($oUser = $this->getUser()) {
240  // session user?
241  $this->_oRevUser = $oUser;
242  }
243 
244  }
245 
246  return $this->_oRevUser;
247  }
248 
254  public function getReviewUserHash()
255  {
256  return oxRegistry::getConfig()->getRequestParameter('reviewuserhash');
257  }
258 
264  protected function _getActiveObject()
265  {
266  if ($this->_oActObject === null) {
267  $this->_oActObject = false;
268 
269  if (($oProduct = $this->getProduct())) {
270  $this->_oActObject = $oProduct;
271  } elseif (($oRecommList = $this->getActiveRecommList())) {
272  $this->_oActObject = $oRecommList;
273  }
274  }
275 
276  return $this->_oActObject;
277  }
278 
284  protected function _getActiveType()
285  {
286  $sType = null;
287  if ($this->getProduct()) {
288  $sType = 'oxarticle';
289  } elseif ($this->getActiveRecommList()) {
290  $sType = 'oxrecommlist';
291  }
292 
293  return $sType;
294  }
295 
301  public function getActiveRecommList()
302  {
303  if (!$this->getViewConfig()->getShowListmania()) {
304  return false;
305  }
306 
307  if ($this->_oActiveRecommList === null) {
308  $this->_oActiveRecommList = false;
309 
310  if ($sRecommId = oxRegistry::getConfig()->getRequestParameter('recommid')) {
311  $oActiveRecommList = oxNew('oxrecommlist');
312  if ($oActiveRecommList->load($sRecommId)) {
313  $this->_oActiveRecommList = $oActiveRecommList;
314  }
315  }
316  }
317 
319  }
320 
326  public function canRate()
327  {
328  if ($this->_blRate === null) {
329  $this->_blRate = false;
330  if (($oActObject = $this->_getActiveObject()) && ($oRevUser = $this->getReviewUser())) {
331  $oRating = oxNew('oxrating');
332  $this->_blRate = $oRating->allowRating(
333  $oRevUser->getId(),
334  $this->_getActiveType(),
335  $oActObject->getId()
336  );
337  }
338  }
339 
340  return $this->_blRate;
341  }
342 
348  public function getReviews()
349  {
350  if ($this->_aReviews === null) {
351  $this->_aReviews = false;
352  if ($oObject = $this->_getActiveObject()) {
353  $this->_aReviews = $oObject->getReviews();
354  }
355  }
356 
357  return $this->_aReviews;
358  }
359 
365  public function getRecommList()
366  {
367  if ($this->_oRecommList === null) {
368  $this->_oRecommList = false;
369  if ($oProduct = $this->getProduct()) {
370  $oRecommList = oxNew('oxrecommlist');
371  $this->_oRecommList = $oRecommList->getRecommListsByIds(array($oProduct->getId()));
372  }
373  }
374 
375  return $this->_oRecommList;
376  }
377 
383  public function getActiveRecommItems()
384  {
385  if ($this->_oActiveRecommItems === null) {
386  $this->_oActiveRecommItems = false;
387  if ($oActiveRecommList = $this->getActiveRecommList()) {
388  // sets active page
389  $iActPage = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
390  $iActPage = ($iActPage < 0) ? 0 : $iActPage;
391 
392  // load only lists which we show on screen
393  $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
394  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
395 
396  $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
397 
398  if ($oList && $oList->count()) {
399  foreach ($oList as $oItem) {
400  $oItem->text = $oActiveRecommList->getArtDescription($oItem->getId());
401  }
402  $this->_oActiveRecommItems = $oList;
403  }
404  }
405  }
406 
408  }
409 
415  public function getReviewSendStatus()
416  {
418  }
419 
425  public function getPageNavigation()
426  {
427  if ($this->_oPageNavigation === null) {
428  $this->_oPageNavigation = false;
429  if ($this->getActiveRecommList()) {
430  $this->_oPageNavigation = $this->generatePageNavigation();
431  }
432  }
433 
435  }
436 
442  public function getAdditionalParams()
443  {
444  $sAddParams = oxUBase::getAdditionalParams();
445  if ($oActRecommList = $this->getActiveRecommList()) {
446  $sAddParams .= '&amp;recommid=' . $oActRecommList->getId();
447  }
448 
449  return $sAddParams;
450  }
451 
457  public function getDynUrlParams()
458  {
459  $sParams = parent::getDynUrlParams();
460 
461  if ($sCnId = oxRegistry::getConfig()->getRequestParameter('cnid')) {
462  $sParams .= "&amp;cnid={$sCnId}";
463  }
464  if ($sAnId = oxRegistry::getConfig()->getRequestParameter('anid')) {
465  $sParams .= "&amp;anid={$sAnId}";
466  }
467  if ($sListType = oxRegistry::getConfig()->getRequestParameter('listtype')) {
468  $sParams .= "&amp;listtype={$sListType}";
469  }
470  if ($sRecommId = oxRegistry::getConfig()->getRequestParameter('recommid')) {
471  $sParams .= "&amp;recommid={$sRecommId}";
472  }
473 
474  return $sParams;
475  }
476 }