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 ( ( $oRevUser = $this->getReviewUser() ) && $this->canAcceptFormData() ) {
00164
00165 if ( ( $oActObject = $this->_getActiveObject() ) && ( $sType = $this->_getActiveType() ) ) {
00166
00167 if ( ( $dRating = oxConfig::getParameter( 'rating' ) ) === null ) {
00168 $dRating = oxConfig::getParameter( 'artrating' );
00169 }
00170
00171 if ( $dRating !== null ) {
00172 $dRating = (int) $dRating;
00173 }
00174
00175
00176 if ( $dRating !== null && $dRating >= 0 && $dRating <= 5 ) {
00177 $oRating = oxNew( 'oxrating' );
00178 if ( $oRating->allowRating( $oRevUser->getId(), $sType, $oActObject->getId() ) ) {
00179 $oRating->oxratings__oxuserid = new oxField( $oRevUser->getId() );
00180 $oRating->oxratings__oxtype = new oxField( $sType );
00181 $oRating->oxratings__oxobjectid = new oxField( $oActObject->getId() );
00182 $oRating->oxratings__oxrating = new oxField( $dRating );
00183 $oRating->save();
00184
00185 $oActObject->addToRatingAverage( $dRating);
00186
00187 $this->_blReviewSendStatus = true;
00188 }
00189 }
00190
00191 if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
00192 $oReview = oxNew( 'oxreview' );
00193 $oReview->oxreviews__oxobjectid = new oxField( $oActObject->getId() );
00194 $oReview->oxreviews__oxtype = new oxField( $sType );
00195 $oReview->oxreviews__oxtext = new oxField( $sReviewText, oxField::T_RAW );
00196 $oReview->oxreviews__oxlang = new oxField( oxRegistry::getLang()->getBaseLanguage() );
00197 $oReview->oxreviews__oxuserid = new oxField( $oRevUser->getId() );
00198 $oReview->oxreviews__oxrating = new oxField( ( $dRating !== null ) ? $dRating : null );
00199 $oReview->save();
00200
00201 $this->_blReviewSendStatus = true;
00202 }
00203 }
00204 }
00205 }
00206
00212 public function getReviewUser()
00213 {
00214 if ( $this->_oRevUser === null ) {
00215 $this->_oRevUser = false;
00216 $oUser = oxNew( "oxuser" );
00217
00218 if ( $sUserId = $oUser->getReviewUserId( $this->getReviewUserHash() ) ) {
00219
00220 if ( $oUser->load( $sUserId ) ) {
00221 $this->_oRevUser = $oUser;
00222 }
00223 } elseif ( $oUser = $this->getUser() ) {
00224
00225 $this->_oRevUser = $oUser;
00226 }
00227
00228 }
00229 return $this->_oRevUser;
00230 }
00231
00237 public function getReviewUserHash()
00238 {
00239 return oxConfig::getParameter( 'reviewuserhash' );
00240 }
00241
00247 protected function _getActiveObject()
00248 {
00249 if ( $this->_oActObject === null ) {
00250 $this->_oActObject = false;
00251
00252 if ( ( $oProduct = $this->getProduct() ) ) {
00253 $this->_oActObject = $oProduct;
00254 } elseif ( ( $oRecommList = $this->getActiveRecommList() ) ) {
00255 $this->_oActObject = $oRecommList;
00256 }
00257 }
00258 return $this->_oActObject;
00259 }
00260
00266 protected function _getActiveType()
00267 {
00268 $sType = null;
00269 if ( $this->getProduct() ) {
00270 $sType = 'oxarticle';
00271 } elseif ( $this->getActiveRecommList() ) {
00272 $sType = 'oxrecommlist';
00273 }
00274 return $sType;
00275 }
00276
00282 public function getActiveRecommList()
00283 {
00284 if (!$this->getViewConfig()->getShowListmania()) {
00285 return false;
00286 }
00287
00288 if ( $this->_oActiveRecommList === null ) {
00289 $this->_oActiveRecommList = false;
00290
00291 if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00292 $oActiveRecommList = oxNew('oxrecommlist');
00293 if ( $oActiveRecommList->load( $sRecommId ) ) {
00294 $this->_oActiveRecommList = $oActiveRecommList;
00295 }
00296 }
00297 }
00298 return $this->_oActiveRecommList;
00299 }
00300
00306 public function canRate()
00307 {
00308 if ( $this->_blRate === null ) {
00309 $this->_blRate = false;
00310 if ( ( $oActObject = $this->_getActiveObject() ) && ( $oRevUser = $this->getReviewUser() ) ) {
00311 $oRating = oxNew( 'oxrating' );
00312 $this->_blRate = $oRating->allowRating( $oRevUser->getId(), $this->_getActiveType(), $oActObject->getId() );
00313 }
00314 }
00315 return $this->_blRate;
00316 }
00317
00323 public function getReviews()
00324 {
00325 if ( $this->_aReviews === null ) {
00326 $this->_aReviews = false;
00327 if ( $oObject = $this->_getActiveObject() ) {
00328 $this->_aReviews = $oObject->getReviews();
00329 }
00330 }
00331 return $this->_aReviews;
00332 }
00333
00339 public function getRecommList()
00340 {
00341 if ( $this->_oRecommList === null ) {
00342 $this->_oRecommList = false;
00343 if ( $oProduct = $this->getProduct() ) {
00344 $oRecommList = oxNew('oxrecommlist');
00345 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00346 }
00347 }
00348 return $this->_oRecommList;
00349 }
00350
00356 public function getActiveRecommItems()
00357 {
00358 if ( $this->_oActiveRecommItems === null ) {
00359 $this->_oActiveRecommItems = false;
00360 if ( $oActiveRecommList = $this->getActiveRecommList()) {
00361
00362 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00363 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00364
00365
00366 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00367 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00368
00369 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00370
00371 if ( $oList && $oList->count() ) {
00372 foreach ( $oList as $oItem) {
00373 $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00374 }
00375 $this->_oActiveRecommItems = $oList;
00376 }
00377 }
00378 }
00379 return $this->_oActiveRecommItems;
00380 }
00381
00387 public function getReviewSendStatus()
00388 {
00389 return $this->_blReviewSendStatus;
00390 }
00391
00397 public function getPageNavigation()
00398 {
00399 if ( $this->_oPageNavigation === null ) {
00400 $this->_oPageNavigation = false;
00401 if ( $this->getActiveRecommList() ) {
00402 $this->_oPageNavigation = $this->generatePageNavigation();
00403 }
00404 }
00405 return $this->_oPageNavigation;
00406 }
00407
00413 public function getAdditionalParams()
00414 {
00415 $sAddParams = oxUBase::getAdditionalParams();
00416 if ( $oActRecommList = $this->getActiveRecommList() ) {
00417 $sAddParams .= '&recommid='.$oActRecommList->getId();
00418 }
00419 return $sAddParams;
00420 }
00421
00427 public function getDynUrlParams()
00428 {
00429 $sParams = parent::getDynUrlParams();
00430
00431 if ( $sCnId = oxConfig::getParameter( 'cnid' ) ) {
00432 $sParams .= "&cnid={$sCnId}";
00433 }
00434 if ( $sAnId = oxConfig::getParameter( 'anid' ) ) {
00435 $sParams .= "&anid={$sAnId}";
00436 }
00437 if ( $sListType = oxConfig::getParameter( 'listtype' ) ) {
00438 $sParams .= "&listtype={$sListType}";
00439 }
00440 if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00441 $sParams .= "&recommid={$sRecommId}";
00442 }
00443
00444 return $sParams;
00445 }
00446 }