Go to the documentation of this file.00001 <?php
00002
00007 class Review extends Details
00008 {
00009
00015 protected $_oRevUser = null;
00016
00022 protected $_oActObject = null;
00023
00029 protected $_oActiveRecommList = null;
00030
00036 protected $_oActiveRecommItems = null;
00037
00043 protected $_blRate = null;
00044
00050 protected $_aReviews = null;
00051
00057 protected $_oCrossSelling = null;
00058
00064 protected $_oSimilarProducts = null;
00065
00071 protected $_oRecommList = null;
00072
00078 protected $_blReviewSendStatus = null;
00079
00085 protected $_oPageNavigation = null;
00086
00092 protected $_sThisTemplate = 'page/review/review.tpl';
00093
00099 protected $_sThisLoginTemplate = 'page/review/review_login.tpl';
00100
00106 protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00107
00113 public function getViewId()
00114 {
00115 return oxUBase::getViewId();
00116 }
00117
00121 public function init()
00122 {
00123 if (oxRegistry::getConfig()->getRequestParameter('recommid') && !$this->getActiveRecommList()) {
00124 oxRegistry::getUtils()->redirect($this->getConfig()->getShopHomeURL(), true, 302);
00125 }
00126
00127 oxUBase::init();
00128 }
00129
00138 public function render()
00139 {
00140 $oConfig = $this->getConfig();
00141
00142 if (!$oConfig->getConfigParam("bl_perfLoadReviews")) {
00143 oxRegistry::getUtils()->redirect($oConfig->getShopHomeURL());
00144 }
00145
00146 oxUBase::render();
00147 if (!($this->getReviewUser())) {
00148 $this->_sThisTemplate = $this->_sThisLoginTemplate;
00149 } else {
00150
00151 $oActiveRecommList = $this->getActiveRecommList();
00152 $oList = $this->getActiveRecommItems();
00153
00154 if ($oActiveRecommList) {
00155 if ($oList && $oList->count()) {
00156 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00157 }
00158
00159 $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
00160 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00161 $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
00162 }
00163 }
00164
00165 return $this->_sThisTemplate;
00166 }
00167
00173 public function saveReview()
00174 {
00175 if (!oxRegistry::getSession()->checkSessionChallenge()) {
00176 return;
00177 }
00178
00179 if (($oRevUser = $this->getReviewUser()) && $this->canAcceptFormData()) {
00180
00181 if (($oActObject = $this->_getActiveObject()) && ($sType = $this->_getActiveType())) {
00182
00183 if (($dRating = oxRegistry::getConfig()->getRequestParameter('rating')) === null) {
00184 $dRating = oxRegistry::getConfig()->getRequestParameter('artrating');
00185 }
00186
00187 if ($dRating !== null) {
00188 $dRating = (int) $dRating;
00189 }
00190
00191
00192 if ($dRating !== null && $dRating >= 1 && $dRating <= 5) {
00193 $oRating = oxNew('oxrating');
00194 if ($oRating->allowRating($oRevUser->getId(), $sType, $oActObject->getId())) {
00195 $oRating->oxratings__oxuserid = new oxField($oRevUser->getId());
00196 $oRating->oxratings__oxtype = new oxField($sType);
00197 $oRating->oxratings__oxobjectid = new oxField($oActObject->getId());
00198 $oRating->oxratings__oxrating = new oxField($dRating);
00199 $oRating->save();
00200
00201 $oActObject->addToRatingAverage($dRating);
00202
00203 $this->_blReviewSendStatus = true;
00204 }
00205 }
00206
00207 if (($sReviewText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('rvw_txt', true)))) {
00208 $oReview = oxNew('oxreview');
00209 $oReview->oxreviews__oxobjectid = new oxField($oActObject->getId());
00210 $oReview->oxreviews__oxtype = new oxField($sType);
00211 $oReview->oxreviews__oxtext = new oxField($sReviewText, oxField::T_RAW);
00212 $oReview->oxreviews__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
00213 $oReview->oxreviews__oxuserid = new oxField($oRevUser->getId());
00214 $oReview->oxreviews__oxrating = new oxField(($dRating !== null) ? $dRating : null);
00215 $oReview->save();
00216
00217 $this->_blReviewSendStatus = true;
00218 }
00219 }
00220 }
00221 }
00222
00228 public function getReviewUser()
00229 {
00230 if ($this->_oRevUser === null) {
00231 $this->_oRevUser = false;
00232 $oUser = oxNew("oxuser");
00233
00234 if ($sUserId = $oUser->getReviewUserId($this->getReviewUserHash())) {
00235
00236 if ($oUser->load($sUserId)) {
00237 $this->_oRevUser = $oUser;
00238 }
00239 } elseif ($oUser = $this->getUser()) {
00240
00241 $this->_oRevUser = $oUser;
00242 }
00243
00244 }
00245
00246 return $this->_oRevUser;
00247 }
00248
00254 public function getReviewUserHash()
00255 {
00256 return oxRegistry::getConfig()->getRequestParameter('reviewuserhash');
00257 }
00258
00264 protected function _getActiveObject()
00265 {
00266 if ($this->_oActObject === null) {
00267 $this->_oActObject = false;
00268
00269 if (($oProduct = $this->getProduct())) {
00270 $this->_oActObject = $oProduct;
00271 } elseif (($oRecommList = $this->getActiveRecommList())) {
00272 $this->_oActObject = $oRecommList;
00273 }
00274 }
00275
00276 return $this->_oActObject;
00277 }
00278
00284 protected function _getActiveType()
00285 {
00286 $sType = null;
00287 if ($this->getProduct()) {
00288 $sType = 'oxarticle';
00289 } elseif ($this->getActiveRecommList()) {
00290 $sType = 'oxrecommlist';
00291 }
00292
00293 return $sType;
00294 }
00295
00301 public function getActiveRecommList()
00302 {
00303 if (!$this->getViewConfig()->getShowListmania()) {
00304 return false;
00305 }
00306
00307 if ($this->_oActiveRecommList === null) {
00308 $this->_oActiveRecommList = false;
00309
00310 if ($sRecommId = oxRegistry::getConfig()->getRequestParameter('recommid')) {
00311 $oActiveRecommList = oxNew('oxrecommlist');
00312 if ($oActiveRecommList->load($sRecommId)) {
00313 $this->_oActiveRecommList = $oActiveRecommList;
00314 }
00315 }
00316 }
00317
00318 return $this->_oActiveRecommList;
00319 }
00320
00326 public function canRate()
00327 {
00328 if ($this->_blRate === null) {
00329 $this->_blRate = false;
00330 if (($oActObject = $this->_getActiveObject()) && ($oRevUser = $this->getReviewUser())) {
00331 $oRating = oxNew('oxrating');
00332 $this->_blRate = $oRating->allowRating(
00333 $oRevUser->getId(),
00334 $this->_getActiveType(),
00335 $oActObject->getId()
00336 );
00337 }
00338 }
00339
00340 return $this->_blRate;
00341 }
00342
00348 public function getReviews()
00349 {
00350 if ($this->_aReviews === null) {
00351 $this->_aReviews = false;
00352 if ($oObject = $this->_getActiveObject()) {
00353 $this->_aReviews = $oObject->getReviews();
00354 }
00355 }
00356
00357 return $this->_aReviews;
00358 }
00359
00365 public function getRecommList()
00366 {
00367 if ($this->_oRecommList === null) {
00368 $this->_oRecommList = false;
00369 if ($oProduct = $this->getProduct()) {
00370 $oRecommList = oxNew('oxrecommlist');
00371 $this->_oRecommList = $oRecommList->getRecommListsByIds(array($oProduct->getId()));
00372 }
00373 }
00374
00375 return $this->_oRecommList;
00376 }
00377
00383 public function getActiveRecommItems()
00384 {
00385 if ($this->_oActiveRecommItems === null) {
00386 $this->_oActiveRecommItems = false;
00387 if ($oActiveRecommList = $this->getActiveRecommList()) {
00388
00389 $iActPage = (int) oxRegistry::getConfig()->getRequestParameter('pgNr');
00390 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00391
00392
00393 $iNrofCatArticles = $this->getConfig()->getConfigParam('iNrofCatArticles');
00394 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00395
00396 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00397
00398 if ($oList && $oList->count()) {
00399 foreach ($oList as $oItem) {
00400 $oItem->text = $oActiveRecommList->getArtDescription($oItem->getId());
00401 }
00402 $this->_oActiveRecommItems = $oList;
00403 }
00404 }
00405 }
00406
00407 return $this->_oActiveRecommItems;
00408 }
00409
00415 public function getReviewSendStatus()
00416 {
00417 return $this->_blReviewSendStatus;
00418 }
00419
00425 public function getPageNavigation()
00426 {
00427 if ($this->_oPageNavigation === null) {
00428 $this->_oPageNavigation = false;
00429 if ($this->getActiveRecommList()) {
00430 $this->_oPageNavigation = $this->generatePageNavigation();
00431 }
00432 }
00433
00434 return $this->_oPageNavigation;
00435 }
00436
00442 public function getAdditionalParams()
00443 {
00444 $sAddParams = oxUBase::getAdditionalParams();
00445 if ($oActRecommList = $this->getActiveRecommList()) {
00446 $sAddParams .= '&recommid=' . $oActRecommList->getId();
00447 }
00448
00449 return $sAddParams;
00450 }
00451
00457 public function getDynUrlParams()
00458 {
00459 $sParams = parent::getDynUrlParams();
00460
00461 if ($sCnId = oxRegistry::getConfig()->getRequestParameter('cnid')) {
00462 $sParams .= "&cnid={$sCnId}";
00463 }
00464 if ($sAnId = oxRegistry::getConfig()->getRequestParameter('anid')) {
00465 $sParams .= "&anid={$sAnId}";
00466 }
00467 if ($sListType = oxRegistry::getConfig()->getRequestParameter('listtype')) {
00468 $sParams .= "&listtype={$sListType}";
00469 }
00470 if ($sRecommId = oxRegistry::getConfig()->getRequestParameter('recommid')) {
00471 $sParams .= "&recommid={$sRecommId}";
00472 }
00473
00474 return $sParams;
00475 }
00476 }