OXID eShop CE  4.10.2
 All Classes Namespaces 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 
24  protected $_oActObject = null;
25 
33  protected $_oActiveRecommList = null;
34 
42  protected $_oActiveRecommItems = null;
43 
49  protected $_blRate = null;
50 
56  protected $_aReviews = null;
57 
63  protected $_oCrossSelling = null;
64 
70  protected $_oSimilarProducts = null;
71 
79  protected $_oRecommList = null;
80 
86  protected $_blReviewSendStatus = null;
87 
93  protected $_oPageNavigation = null;
94 
100  protected $_sThisTemplate = 'page/review/review.tpl';
101 
107  protected $_sThisLoginTemplate = 'page/review/review_login.tpl';
108 
115 
121  public function getViewId()
122  {
123  return oxUBase::getViewId();
124  }
125 
129  public function init()
130  {
131  // @deprecated since v5.3 (2016-06-17); Listmania will be moved to an own module.
132  if (oxRegistry::getConfig()->getRequestParameter('recommid') && !$this->getActiveRecommList()) {
133  oxRegistry::getUtils()->redirect($this->getConfig()->getShopHomeURL(), true, 302);
134  }
135  // END deprecated
136 
137  oxUBase::init();
138  }
139 
148  public function render()
149  {
150  $oConfig = $this->getConfig();
151 
152  if (!$oConfig->getConfigParam("bl_perfLoadReviews")) {
153  oxRegistry::getUtils()->redirect($oConfig->getShopHomeURL());
154  }
155 
156  oxUBase::render();
157  if (!($this->getReviewUser())) {
158  $this->_sThisTemplate = $this->_sThisLoginTemplate;
159  } else {
160 
161  // @deprecated since v5.3 (2016-06-17); Listmania will be moved to an own module.
162  $oActiveRecommList = $this->getActiveRecommList();
163  $oList = $this->getActiveRecommItems();
164 
165  if ($oActiveRecommList) {
166  if ($oList && $oList->count()) {
167  $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
168  }
169  // load only lists which we show on screen
170  $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
171  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
172  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
173  }
174  // END deprecated
175  }
176 
177  return $this->_sThisTemplate;
178  }
179 
185  public function saveReview()
186  {
187  if (!oxRegistry::getSession()->checkSessionChallenge()) {
188  return;
189  }
190 
191  if (($oRevUser = $this->getReviewUser()) && $this->canAcceptFormData()) {
192 
193  if (($oActObject = $this->_getActiveObject()) && ($sType = $this->_getActiveType())) {
194 
195  if (($dRating = oxRegistry::getConfig()->getRequestParameter('rating')) === null) {
196  $dRating = oxRegistry::getConfig()->getRequestParameter('artrating');
197  }
198 
199  if ($dRating !== null) {
200  $dRating = (int) $dRating;
201  }
202 
203  //save rating
204  if ($dRating !== null && $dRating >= 1 && $dRating <= 5) {
205  $oRating = oxNew('oxrating');
206  if ($oRating->allowRating($oRevUser->getId(), $sType, $oActObject->getId())) {
207  $oRating->oxratings__oxuserid = new oxField($oRevUser->getId());
208  $oRating->oxratings__oxtype = new oxField($sType);
209  $oRating->oxratings__oxobjectid = new oxField($oActObject->getId());
210  $oRating->oxratings__oxrating = new oxField($dRating);
211  $oRating->save();
212 
213  $oActObject->addToRatingAverage($dRating);
214 
215  $this->_blReviewSendStatus = true;
216  }
217  }
218 
219  if (($sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true)))) {
220  $oReview = oxNew('oxreview');
221  $oReview->oxreviews__oxobjectid = new oxField($oActObject->getId());
222  $oReview->oxreviews__oxtype = new oxField($sType);
223  $oReview->oxreviews__oxtext = new oxField($sReviewText, oxField::T_RAW);
224  $oReview->oxreviews__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
225  $oReview->oxreviews__oxuserid = new oxField($oRevUser->getId());
226  $oReview->oxreviews__oxrating = new oxField(($dRating !== null) ? $dRating : null);
227  $oReview->save();
228 
229  $this->_blReviewSendStatus = true;
230  }
231  }
232  }
233  }
234 
240  public function getReviewUser()
241  {
242  if ($this->_oRevUser === null) {
243  $this->_oRevUser = false;
244  $oUser = oxNew("oxuser");
245 
246  if ($sUserId = $oUser->getReviewUserId($this->getReviewUserHash())) {
247  // review user, by link or other source?
248  if ($oUser->load($sUserId)) {
249  $this->_oRevUser = $oUser;
250  }
251  } elseif ($oUser = $this->getUser()) {
252  // session user?
253  $this->_oRevUser = $oUser;
254  }
255 
256  }
257 
258  return $this->_oRevUser;
259  }
260 
266  public function getReviewUserHash()
267  {
268  return oxRegistry::getConfig()->getRequestParameter('reviewuserhash');
269  }
270 
276  protected function _getActiveObject()
277  {
278  if ($this->_oActObject === null) {
279  $this->_oActObject = false;
280 
281  if (($oProduct = $this->getProduct())) {
282  $this->_oActObject = $oProduct;
283  } elseif (($oRecommList = $this->getActiveRecommList())) {
284  $this->_oActObject = $oRecommList;
285  }
286  }
287 
288  return $this->_oActObject;
289  }
290 
296  protected function _getActiveType()
297  {
298  $sType = null;
299  if ($this->getProduct()) {
300  $sType = 'oxarticle';
301  // @deprecated since v5.3 (2016-06-17); Listmania will be moved to an own module.
302  } elseif ($this->getActiveRecommList()) {
303  $sType = 'oxrecommlist';
304  // END deprecated
305  }
306 
307  return $sType;
308  }
309 
317  public function getActiveRecommList()
318  {
319  if (!$this->getViewConfig()->getShowListmania()) {
320  return false;
321  }
322 
323  if ($this->_oActiveRecommList === null) {
324  $this->_oActiveRecommList = false;
325 
326  if ($sRecommId = oxRegistry::getConfig()->getRequestParameter('recommid')) {
327  $oActiveRecommList = oxNew('oxrecommlist');
328  if ($oActiveRecommList->load($sRecommId)) {
329  $this->_oActiveRecommList = $oActiveRecommList;
330  }
331  }
332  }
333 
335  }
336 
342  public function canRate()
343  {
344  if ($this->_blRate === null) {
345  $this->_blRate = false;
346  if (($oActObject = $this->_getActiveObject()) && ($oRevUser = $this->getReviewUser())) {
347  $oRating = oxNew('oxrating');
348  $this->_blRate = $oRating->allowRating(
349  $oRevUser->getId(),
350  $this->_getActiveType(),
351  $oActObject->getId()
352  );
353  }
354  }
355 
356  return $this->_blRate;
357  }
358 
364  public function getReviews()
365  {
366  if ($this->_aReviews === null) {
367  $this->_aReviews = false;
368  if ($oObject = $this->_getActiveObject()) {
369  $this->_aReviews = $oObject->getReviews();
370  }
371  }
372 
373  return $this->_aReviews;
374  }
375 
383  public function getRecommList()
384  {
385  if ($this->_oRecommList === null) {
386  $this->_oRecommList = false;
387  if ($oProduct = $this->getProduct()) {
388  $oRecommList = oxNew('oxrecommlist');
389  $this->_oRecommList = $oRecommList->getRecommListsByIds(array($oProduct->getId()));
390  }
391  }
392 
393  return $this->_oRecommList;
394  }
395 
403  public function getActiveRecommItems()
404  {
405  if ($this->_oActiveRecommItems === null) {
406  $this->_oActiveRecommItems = false;
407  if ($oActiveRecommList = $this->getActiveRecommList()) {
408  // sets active page
409  $iActPage = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
410  $iActPage = ($iActPage < 0) ? 0 : $iActPage;
411 
412  // load only lists which we show on screen
413  $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
414  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
415 
416  $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
417 
418  if ($oList && $oList->count()) {
419  foreach ($oList as $oItem) {
420  $oItem->text = $oActiveRecommList->getArtDescription($oItem->getId());
421  }
422  $this->_oActiveRecommItems = $oList;
423  }
424  }
425  }
426 
428  }
429 
435  public function getReviewSendStatus()
436  {
438  }
439 
445  public function getPageNavigation()
446  {
447  if ($this->_oPageNavigation === null) {
448  $this->_oPageNavigation = false;
449  // @deprecated since v5.3 (2016-06-17); Listmania will be moved to an own module.
450  if ($this->getActiveRecommList()) {
451  $this->_oPageNavigation = $this->generatePageNavigation();
452  }
453  // END deprecated
454  }
455 
457  }
458 
464  public function getAdditionalParams()
465  {
466  $sAddParams = oxUBase::getAdditionalParams();
467  // @deprecated since v5.3 (2016-06-17); Listmania will be moved to an own module.
468  if ($oActRecommList = $this->getActiveRecommList()) {
469  $sAddParams .= '&amp;recommid=' . $oActRecommList->getId();
470  }
471  // END deprecated
472 
473  return $sAddParams;
474  }
475 
481  public function getDynUrlParams()
482  {
483  $sParams = parent::getDynUrlParams();
484 
485  if ($sCnId = oxRegistry::getConfig()->getRequestParameter('cnid')) {
486  $sParams .= "&amp;cnid={$sCnId}";
487  }
488  if ($sAnId = oxRegistry::getConfig()->getRequestParameter('anid')) {
489  $sParams .= "&amp;anid={$sAnId}";
490  }
491  if ($sListType = oxRegistry::getConfig()->getRequestParameter('listtype')) {
492  $sParams .= "&amp;listtype={$sListType}";
493  }
494  // @deprecated since v5.3 (2016-06-17); Listmania will be moved to an own module.
495  if ($sRecommId = oxRegistry::getConfig()->getRequestParameter('recommid')) {
496  $sParams .= "&amp;recommid={$sRecommId}";
497  }
498  // END deprecated
499 
500  return $sParams;
501  }
502 }