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         $oUser = $this->getUser();
00233         $blAllow = false;
00234         if ($oUser && ($sReviewUserId == $oUser->getId())) {
00235             $blAllow = true;
00236         } else {
00237             $blAllow = $this->_allowDirectReview( $sReviewUserId );
00238         }
00239         return $blAllow;
00240     }
00241 
00250     protected function _allowDirectReview( $sUserId )
00251     {
00252         if ( $sUserId == 'oxdefaultadmin' ) {
00253             return false;
00254         }
00255 
00256         $oUser = oxNew( 'oxuser' );
00257         if ( !$oUser->exists( $sUserId ) ) {
00258             return false;
00259         }
00260 
00261         return true;
00262     }
00263 
00269     public function getReviewUserId()
00270     {
00271         if ( $this->_sReviewUserId === null ) {
00272             $this->_sReviewUserId = false;
00273 
00274             $sReviewUserId = oxConfig::getParameter( 'reviewuserid' );
00275             $oUser = $this->getUser();
00276             if (!$sReviewUserId && $oUser) {
00277                 $sReviewUserId = $oUser->getId();
00278             }
00279             $this->_sReviewUserId = $sReviewUserId;
00280         }
00281         return $this->_sReviewUserId;
00282     }
00283 
00289     public function getProduct()
00290     {
00291         if ( $this->_oProduct === null ) {
00292             $this->_oProduct = false;
00293 
00294             if ( $sAnid = oxConfig::getParameter( 'anid' ) ) {
00295                 $this->_oProduct = oxNewArticle( $sAnid );
00296             }
00297         }
00298         return $this->_oProduct;
00299     }
00300 
00306     protected function _getActiveObject()
00307     {
00308         if ( $this->_oActObject === null ) {
00309             $this->_oActObject = false;
00310 
00311             if ( $oProduct = $this->getProduct() ) {
00312                 $this->_oActObject = $oProduct;
00313             } elseif ( $this->_oActiveRecommList ) {
00314                 $this->_oActObject = $this->_oActiveRecommList;
00315             }
00316         }
00317         return $this->_oActObject;
00318     }
00319 
00325     protected function _getActiveType()
00326     {
00327         if ( $this->getProduct() ) {
00328             $sType = 'oxarticle';
00329         } elseif ($this->_oActiveRecommList) {
00330             $sType = 'oxrecommlist';
00331         }
00332         return $sType;
00333     }
00334 
00340     public function getActiveRecommList()
00341     {
00342         if ( $this->_oActiveRecommList === null ) {
00343             $this->_oActiveRecommList = false;
00344 
00345             if( $sRecommId = oxConfig::getParameter( 'recommid' ) ){
00346                 $oActiveRecommList = oxNew('oxrecommlist');
00347                 if ( $oActiveRecommList->load( $sRecommId ) ) {
00348                     $this->_oActiveRecommList = $oActiveRecommList;
00349                 }
00350             }
00351         }
00352         return $this->_oActiveRecommList;
00353     }
00354 
00360     public function canRate()
00361     {
00362         if ( $this->_blRate === null ) {
00363             $this->_blRate = false;
00364             $sType     = $this->_getActiveType();
00365             $sObjectId = $this->_getActiveObject()->getId();
00366             $oRating = oxNew( 'oxrating' );
00367             $this->_blRate = $oRating->allowRating( $this->getReviewUserId(), $sType, $sObjectId);
00368 
00369         }
00370         return $this->_blRate;
00371     }
00372 
00378     public function getReviews()
00379     {
00380         if ( $this->_aReviews === null ) {
00381             $this->_aReviews = false;
00382             if ( $oObject = $this->_getActiveObject() ) {
00383                 $this->_aReviews = $oObject->getReviews();
00384             }
00385         }
00386         return $this->_aReviews;
00387     }
00388 
00394     public function getCrossSelling()
00395     {
00396         if ( $this->_oCrossSelling === null ) {
00397             $this->_oCrossSelling = false;
00398             if ( $oProduct = $this->getProduct() ) {
00399                 $this->_oCrossSelling = $oProduct->getCrossSelling();
00400             }
00401         }
00402         return $this->_oCrossSelling;
00403     }
00404 
00410     public function getSimilarProducts()
00411     {
00412         if ( $this->_oSimilarProducts === null ) {
00413             $this->_oSimilarProducts = false;
00414             if ( $oProduct = $this->getProduct() ) {
00415                 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00416             }
00417         }
00418         return $this->_oSimilarProducts;
00419     }
00420 
00426     public function getRecommList()
00427     {
00428         if ( $this->_oRecommList === null ) {
00429             $this->_oRecommList = false;
00430             if ( $oProduct = $this->getProduct() ) {
00431                 $oRecommList = oxNew('oxrecommlist');
00432                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00433             }
00434         }
00435         return $this->_oRecommList;
00436     }
00437 
00443     public function getActiveRecommItems()
00444     {
00445         if ( $this->_oActiveRecommItems === null ) {
00446             $this->_oActiveRecommItems = false;
00447             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00448                 // sets active page
00449                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00450                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00451 
00452                 // load only lists which we show on screen
00453                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00454                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00455 
00456                 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00457 
00458                 if ( $oList && $oList->count() ) {
00459                     foreach ( $oList as $oItem) {
00460                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00461                     }
00462                     $this->_oActiveRecommItems = $oList;
00463                 }
00464             }
00465         }
00466         return $this->_oActiveRecommItems;
00467     }
00468 
00474     public function getReviewSendStatus()
00475     {
00476         return $this->_blReviewSendStatus;
00477     }
00478 
00484     public function getPageNavigation()
00485     {
00486         if ( $this->_oPageNavigation === null ) {
00487             $this->_oPageNavigation = false;
00488             if ( $this->_oActiveRecommList ) {
00489                 $this->_oPageNavigation = $this->generatePageNavigation();
00490             }
00491         }
00492         return $this->_oPageNavigation;
00493     }
00494 
00500     public function getAdditionalParams()
00501     {
00502         $sAddParams = parent::getAdditionalParams();
00503         if ( $oActRecommList = $this->getActiveRecommList() ) {
00504             $sAddParams .= '&amp;recommid='.$oActRecommList->getId();
00505         }
00506         return $sAddParams;
00507     }
00508 }

Generated on Tue Apr 21 15:45:45 2009 for OXID eShop CE by  doxygen 1.5.5