review.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Review extends oxUBase
00008 {
00013     protected $_sReviewUserId = 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 = 'review.tpl';
00080 
00085     protected $_sThisLoginTemplate = 'review_login.tpl';
00086 
00092     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00093 
00099     public function init()
00100     {
00101         $myConfig = $this->getConfig();
00102 
00103         parent::init();
00104 
00105         $this->_oActiveRecommList = $this->getActiveRecommList();
00106         if ( oxConfig::getParameter( 'recommid' ) && !$this->_oActiveRecommList ) {
00107             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() );
00108         }
00109     }
00110 
00123     public function render()
00124     {
00125         parent::render();
00126 
00127         if ( !$this->_checkDirectReview($this->getReviewUserId()) ) {
00128             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00129         }
00130 
00131         $this->_aViewData['reviewuserid'] = $this->getReviewUserId();
00132 
00133         $this->_aViewData['reviews'] = $this->getReviews();
00134         $this->_aViewData['product'] = $this->getProduct();
00135 
00136         // loading product reviews
00137         $this->_aViewData['crossselllist']     = $this->getCrossSelling();
00138         $this->_aViewData['similarlist']       = $this->getSimilarProducts();
00139         $this->_aViewData['similarrecommlist'] = $this->getRecommList();
00140 
00141 
00142         $this->_aViewData['actvrecommlist'] = $this->getActiveRecommList();
00143         $this->_aViewData['itemList']       = $this->getActiveRecommItems();
00144 
00145         if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00146             $oList = $this->getActiveRecommItems();
00147             if ( $oList && $oList->count()) {
00148                 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00149             }
00150             // load only lists which we show on screen
00151             $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00152             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00153             $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00154         }
00155 
00156         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00157         $this->_aViewData['rate'] = $this->canRate();
00158         $this->_aViewData['success'] = $this->getReviewSendStatus();
00159 
00160         return $this->_sThisTemplate;
00161     }
00162 
00171     public function saveReview()
00172     {
00173         $sReviewUserId = $this->getReviewUserId();
00174 
00175         if ( !$this->_checkDirectReview($sReviewUserId) ) {
00176             return;
00177         }
00178 
00179         $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt' ) );
00180         $dRating     = ( oxConfig::getParameter( 'rating' ) ) ? oxConfig::getParameter( 'rating' ) : oxConfig::getParameter( 'artrating' );
00181 
00182         if ($dRating < 0 || $dRating > 5) {
00183             $dRating = null;
00184         }
00185         // #1590M
00186         /*if ( !$sReviewText ) {
00187             $this->_aViewData['success'] = true;
00188             return;
00189         }*/
00190 
00191         $sType     = $this->_getActiveType();
00192         $sObjectId = $this->_getActiveObject()->getId();
00193         if ($sType && $sObjectId) {
00194             //save rating
00195             if ( $dRating ) {
00196                 $oRating = oxNew( 'oxrating' );
00197                 $oRating->oxratings__oxuserid   = new oxField($sReviewUserId);
00198                 $oRating->oxratings__oxtype     = new oxField($sType, oxField::T_RAW);
00199                 $oRating->oxratings__oxobjectid = new oxField($sObjectId);
00200                 $oRating->oxratings__oxrating   = new oxField($dRating);
00201                 $oRating->save();
00202                 if ( $oProduct = $this->getProduct() ) {
00203                     $oProduct->addToRatingAverage( $dRating);
00204                 } elseif ($this->_oActiveRecommList) {
00205                     $this->_oActiveRecommList->addToRatingAverage( $dRating);
00206                 }
00207                 $this->_blReviewSendStatus = true;
00208             }
00209 
00210             if ( $sReviewText ) {
00211                 $oReview = oxNew( 'oxreview' );
00212                 $oReview->oxreviews__oxuserid   = new oxField($sReviewUserId);
00213                 $oReview->oxreviews__oxtype     = new oxField($sType, oxField::T_RAW);
00214                 $oReview->oxreviews__oxobjectid = new oxField($sObjectId);
00215                 $oReview->oxreviews__oxtext     = new oxField($sReviewText);
00216                 $oReview->oxreviews__oxlang     = new oxField(oxLang::getInstance()->getBaseLanguage());
00217                 $oReview->oxreviews__oxrating   = new oxField(( $dRating) ? $dRating : null);
00218                 $oReview->save();
00219                 $this->_blReviewSendStatus = true;
00220             }
00221         }
00222     }
00223 
00231     protected function _checkDirectReview( $sReviewUserId )
00232     {
00233         $oUser = $this->getUser();
00234         $blAllow = false;
00235         if ($oUser && ($sReviewUserId == $oUser->getId())) {
00236             $blAllow = true;
00237         } else {
00238             $blAllow = $this->_allowDirectReview( $sReviewUserId );
00239         }
00240         return $blAllow;
00241     }
00242 
00251     protected function _allowDirectReview( $sUserId )
00252     {
00253         $oUser = oxNew( 'oxuser' );
00254         if ( !$oUser->exists( $sUserId ) ) {
00255             return false;
00256         }
00257 
00258         return true;
00259     }
00260 
00266     public function getReviewUserId()
00267     {
00268         if ( $this->_sReviewUserId === null ) {
00269             $this->_sReviewUserId = false;
00270 
00271             //review user from order email
00272             if ( $sReviewUser = oxConfig::getParameter( 'reviewuser' ) ) {
00273                 $oUser = oxNew( 'oxuser' );
00274                 $sReviewUserId = $oUser->getReviewUserId( $sReviewUser );
00275             }
00276             if ( !$sReviewUserId ) {
00277                 $sReviewUserId = oxConfig::getParameter( 'reviewuserid' );
00278             }
00279             $oUser = $this->getUser();
00280             if (!$sReviewUserId && $oUser) {
00281                 $sReviewUserId = $oUser->getId();
00282             }
00283             $this->_sReviewUserId = $sReviewUserId;
00284         }
00285         return $this->_sReviewUserId;
00286     }
00287 
00293     public function getProduct()
00294     {
00295         if ( $this->_oProduct === null ) {
00296             $this->_oProduct = false;
00297 
00298             if ( $sAnid = oxConfig::getParameter( 'anid' ) ) {
00299                 $this->_oProduct = oxNewArticle( $sAnid );
00300             }
00301         }
00302         return $this->_oProduct;
00303     }
00304 
00310     protected function _getActiveObject()
00311     {
00312         if ( $this->_oActObject === null ) {
00313             $this->_oActObject = false;
00314 
00315             if ( $oProduct = $this->getProduct() ) {
00316                 $this->_oActObject = $oProduct;
00317             } elseif ( $this->_oActiveRecommList ) {
00318                 $this->_oActObject = $this->_oActiveRecommList;
00319             }
00320         }
00321         return $this->_oActObject;
00322     }
00323 
00329     protected function _getActiveType()
00330     {
00331         if ( $this->getProduct() ) {
00332             $sType = 'oxarticle';
00333         } elseif ($this->_oActiveRecommList) {
00334             $sType = 'oxrecommlist';
00335         }
00336         return $sType;
00337     }
00338 
00344     public function getActiveRecommList()
00345     {
00346         if ( $this->_oActiveRecommList === null ) {
00347             $this->_oActiveRecommList = false;
00348 
00349             if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00350                 $oActiveRecommList = oxNew('oxrecommlist');
00351                 if ( $oActiveRecommList->load( $sRecommId ) ) {
00352                     $this->_oActiveRecommList = $oActiveRecommList;
00353                 }
00354             }
00355         }
00356         return $this->_oActiveRecommList;
00357     }
00358 
00364     public function canRate()
00365     {
00366         if ( $this->_blRate === null ) {
00367             $this->_blRate = false;
00368             $sType     = $this->_getActiveType();
00369             $sObjectId = $this->_getActiveObject()->getId();
00370             $oRating = oxNew( 'oxrating' );
00371             $this->_blRate = $oRating->allowRating( $this->getReviewUserId(), $sType, $sObjectId);
00372 
00373         }
00374         return $this->_blRate;
00375     }
00376 
00382     public function getReviews()
00383     {
00384         if ( $this->_aReviews === null ) {
00385             $this->_aReviews = false;
00386             if ( $oObject = $this->_getActiveObject() ) {
00387                 $this->_aReviews = $oObject->getReviews();
00388             }
00389         }
00390         return $this->_aReviews;
00391     }
00392 
00398     public function getCrossSelling()
00399     {
00400         if ( $this->_oCrossSelling === null ) {
00401             $this->_oCrossSelling = false;
00402             if ( $oProduct = $this->getProduct() ) {
00403                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00404             }
00405         }
00406         return $this->_oCrossSelling;
00407     }
00408 
00414     public function getSimilarProducts()
00415     {
00416         if ( $this->_oSimilarProducts === null ) {
00417             $this->_oSimilarProducts = false;
00418             if ( $oProduct = $this->getProduct() ) {
00419                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00420             }
00421         }
00422         return $this->_oSimilarProducts;
00423     }
00424 
00430     public function getRecommList()
00431     {
00432         if ( $this->_oRecommList === null ) {
00433             $this->_oRecommList = false;
00434             if ( $oProduct = $this->getProduct() ) {
00435                 $oRecommList = oxNew('oxrecommlist');
00436                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00437             }
00438         }
00439         return $this->_oRecommList;
00440     }
00441 
00447     public function getActiveRecommItems()
00448     {
00449         if ( $this->_oActiveRecommItems === null ) {
00450             $this->_oActiveRecommItems = false;
00451             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00452                 // sets active page
00453                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00454                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00455 
00456                 // load only lists which we show on screen
00457                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00458                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00459 
00460                 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00461 
00462                 if ( $oList && $oList->count() ) {
00463                     foreach ( $oList as $oItem) {
00464                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00465                     }
00466                     $this->_oActiveRecommItems = $oList;
00467                 }
00468             }
00469         }
00470         return $this->_oActiveRecommItems;
00471     }
00472 
00478     public function getReviewSendStatus()
00479     {
00480         return $this->_blReviewSendStatus;
00481     }
00482 
00488     public function getPageNavigation()
00489     {
00490         if ( $this->_oPageNavigation === null ) {
00491             $this->_oPageNavigation = false;
00492             if ( $this->_oActiveRecommList ) {
00493                 $this->_oPageNavigation = $this->generatePageNavigation();
00494             }
00495         }
00496         return $this->_oPageNavigation;
00497     }
00498 
00504     public function getAdditionalParams()
00505     {
00506         $sAddParams = parent::getAdditionalParams();
00507         if ( $oActRecommList = $this->getActiveRecommList() ) {
00508             $sAddParams .= '&amp;recommid='.$oActRecommList->getId();
00509         }
00510         return $sAddParams;
00511     }
00512 }

Generated on Wed May 13 13:25:55 2009 for OXID eShop CE by  doxygen 1.5.5