Go to the documentation of this file.00001 <?php
00002
00007 class Review extends Details
00008 {
00013 protected $_oRevUser = null;
00014
00019 protected $_oActObject = null;
00020
00025 protected $_oActiveRecommList = null;
00026
00031 protected $_oActiveRecommItems = null;
00032
00037 protected $_blRate = null;
00038
00043 protected $_aReviews = null;
00044
00049 protected $_oCrossSelling = null;
00050
00055 protected $_oSimilarProducts = null;
00056
00061 protected $_oRecommList = null;
00062
00067 protected $_blReviewSendStatus = null;
00068
00073 protected $_oPageNavigation = null;
00074
00079 protected $_sThisTemplate = 'page/review/review.tpl';
00080
00085 protected $_sThisLoginTemplate = 'page/review/review_login.tpl';
00086
00092 protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00093
00099 public function getViewId()
00100 {
00101 return oxUBase::getViewId();
00102 }
00103
00109 public function init()
00110 {
00111 if ( oxConfig::getParameter( 'recommid' ) && !$this->getActiveRecommList() ) {
00112 oxRegistry::getUtils()->redirect( $this->getConfig()->getShopHomeURL(), true, 302 );
00113 }
00114
00115 oxUBase::init();
00116 }
00117
00126 public function render()
00127 {
00128 $oConfig = $this->getConfig();
00129
00130 if ( !$oConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
00131 oxRegistry::getUtils()->redirect( $oConfig->getShopHomeURL() );
00132 }
00133
00134 oxUBase::render();
00135 if ( ! ( $this->getReviewUser() ) ) {
00136 $this->_sThisTemplate = $this->_sThisLoginTemplate;
00137 } else {
00138
00139 $oActiveRecommList = $this->getActiveRecommList();
00140 $oList = $this->getActiveRecommItems();
00141
00142 if ( $oActiveRecommList ) {
00143 if ( $oList && $oList->count()) {
00144 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00145 }
00146
00147 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00148 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00149 $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00150 }
00151 }
00152
00153 return $this->_sThisTemplate;
00154 }
00155
00161 public function saveReview()
00162 {
00163 if (!oxRegistry::getSession()->checkSessionChallenge()) {
00164 return;
00165 }
00166
00167 if ( ( $oRevUser = $this->getReviewUser() ) && $this->canAcceptFormData() ) {
00168
00169 if ( ( $oActObject = $this->_getActiveObject() ) && ( $sType = $this->_getActiveType() ) ) {
00170
00171 if ( ( $dRating = oxConfig::getParameter( 'rating' ) ) === null ) {
00172 $dRating = oxConfig::getParameter( 'artrating' );
00173 }
00174
00175 if ( $dRating !== null ) {
00176 $dRating = (int) $dRating;
00177 }
00178
00179
00180 if ( $dRating !== null && $dRating >= 1 && $dRating <= 5 ) {
00181 $oRating = oxNew( 'oxrating' );
00182 if ( $oRating->allowRating( $oRevUser->getId(), $sType, $oActObject->getId() ) ) {
00183 $oRating->oxratings__oxuserid = new oxField( $oRevUser->getId() );
00184 $oRating->oxratings__oxtype = new oxField( $sType );
00185 $oRating->oxratings__oxobjectid = new oxField( $oActObject->getId() );
00186 $oRating->oxratings__oxrating = new oxField( $dRating );
00187 $oRating->save();
00188
00189 $oActObject->addToRatingAverage( $dRating);
00190
00191 $this->_blReviewSendStatus = true;
00192 }
00193 }
00194
00195 if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
00196 $oReview = oxNew( 'oxreview' );
00197 $oReview->oxreviews__oxobjectid = new oxField( $oActObject->getId() );
00198 $oReview->oxreviews__oxtype = new oxField( $sType );
00199 $oReview->oxreviews__oxtext = new oxField( $sReviewText, oxField::T_RAW );
00200 $oReview->oxreviews__oxlang = new oxField( oxRegistry::getLang()->getBaseLanguage() );
00201 $oReview->oxreviews__oxuserid = new oxField( $oRevUser->getId() );
00202 $oReview->oxreviews__oxrating = new oxField( ( $dRating !== null ) ? $dRating : null );
00203 $oReview->save();
00204
00205 $this->_blReviewSendStatus = true;
00206 }
00207 }
00208 }
00209 }
00210
00216 public function getReviewUser()
00217 {
00218 if ( $this->_oRevUser === null ) {
00219 $this->_oRevUser = false;
00220 $oUser = oxNew( "oxuser" );
00221
00222 if ( $sUserId = $oUser->getReviewUserId( $this->getReviewUserHash() ) ) {
00223
00224 if ( $oUser->load( $sUserId ) ) {
00225 $this->_oRevUser = $oUser;
00226 }
00227 } elseif ( $oUser = $this->getUser() ) {
00228
00229 $this->_oRevUser = $oUser;
00230 }
00231
00232 }
00233 return $this->_oRevUser;
00234 }
00235
00241 public function getReviewUserHash()
00242 {
00243 return oxConfig::getParameter( 'reviewuserhash' );
00244 }
00245
00251 protected function _getActiveObject()
00252 {
00253 if ( $this->_oActObject === null ) {
00254 $this->_oActObject = false;
00255
00256 if ( ( $oProduct = $this->getProduct() ) ) {
00257 $this->_oActObject = $oProduct;
00258 } elseif ( ( $oRecommList = $this->getActiveRecommList() ) ) {
00259 $this->_oActObject = $oRecommList;
00260 }
00261 }
00262 return $this->_oActObject;
00263 }
00264
00270 protected function _getActiveType()
00271 {
00272 $sType = null;
00273 if ( $this->getProduct() ) {
00274 $sType = 'oxarticle';
00275 } elseif ( $this->getActiveRecommList() ) {
00276 $sType = 'oxrecommlist';
00277 }
00278 return $sType;
00279 }
00280
00286 public function getActiveRecommList()
00287 {
00288 if (!$this->getViewConfig()->getShowListmania()) {
00289 return false;
00290 }
00291
00292 if ( $this->_oActiveRecommList === null ) {
00293 $this->_oActiveRecommList = false;
00294
00295 if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00296 $oActiveRecommList = oxNew('oxrecommlist');
00297 if ( $oActiveRecommList->load( $sRecommId ) ) {
00298 $this->_oActiveRecommList = $oActiveRecommList;
00299 }
00300 }
00301 }
00302 return $this->_oActiveRecommList;
00303 }
00304
00310 public function canRate()
00311 {
00312 if ( $this->_blRate === null ) {
00313 $this->_blRate = false;
00314 if ( ( $oActObject = $this->_getActiveObject() ) && ( $oRevUser = $this->getReviewUser() ) ) {
00315 $oRating = oxNew( 'oxrating' );
00316 $this->_blRate = $oRating->allowRating( $oRevUser->getId(), $this->_getActiveType(), $oActObject->getId() );
00317 }
00318 }
00319 return $this->_blRate;
00320 }
00321
00327 public function getReviews()
00328 {
00329 if ( $this->_aReviews === null ) {
00330 $this->_aReviews = false;
00331 if ( $oObject = $this->_getActiveObject() ) {
00332 $this->_aReviews = $oObject->getReviews();
00333 }
00334 }
00335 return $this->_aReviews;
00336 }
00337
00343 public function getRecommList()
00344 {
00345 if ( $this->_oRecommList === null ) {
00346 $this->_oRecommList = false;
00347 if ( $oProduct = $this->getProduct() ) {
00348 $oRecommList = oxNew('oxrecommlist');
00349 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00350 }
00351 }
00352 return $this->_oRecommList;
00353 }
00354
00360 public function getActiveRecommItems()
00361 {
00362 if ( $this->_oActiveRecommItems === null ) {
00363 $this->_oActiveRecommItems = false;
00364 if ( $oActiveRecommList = $this->getActiveRecommList()) {
00365
00366 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00367 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00368
00369
00370 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00371 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00372
00373 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00374
00375 if ( $oList && $oList->count() ) {
00376 foreach ( $oList as $oItem) {
00377 $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00378 }
00379 $this->_oActiveRecommItems = $oList;
00380 }
00381 }
00382 }
00383 return $this->_oActiveRecommItems;
00384 }
00385
00391 public function getReviewSendStatus()
00392 {
00393 return $this->_blReviewSendStatus;
00394 }
00395
00401 public function getPageNavigation()
00402 {
00403 if ( $this->_oPageNavigation === null ) {
00404 $this->_oPageNavigation = false;
00405 if ( $this->getActiveRecommList() ) {
00406 $this->_oPageNavigation = $this->generatePageNavigation();
00407 }
00408 }
00409 return $this->_oPageNavigation;
00410 }
00411
00417 public function getAdditionalParams()
00418 {
00419 $sAddParams = oxUBase::getAdditionalParams();
00420 if ( $oActRecommList = $this->getActiveRecommList() ) {
00421 $sAddParams .= '&recommid='.$oActRecommList->getId();
00422 }
00423 return $sAddParams;
00424 }
00425
00431 public function getDynUrlParams()
00432 {
00433 $sParams = parent::getDynUrlParams();
00434
00435 if ( $sCnId = oxConfig::getParameter( 'cnid' ) ) {
00436 $sParams .= "&cnid={$sCnId}";
00437 }
00438 if ( $sAnId = oxConfig::getParameter( 'anid' ) ) {
00439 $sParams .= "&anid={$sAnId}";
00440 }
00441 if ( $sListType = oxConfig::getParameter( 'listtype' ) ) {
00442 $sParams .= "&listtype={$sListType}";
00443 }
00444 if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00445 $sParams .= "&recommid={$sRecommId}";
00446 }
00447
00448 return $sParams;
00449 }
00450 }