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

Generated on Wed Apr 22 12:26:32 2009 for OXID eShop CE by  doxygen 1.5.5