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

Generated on Tue Aug 18 09:21:09 2009 for OXID eShop CE by  doxygen 1.5.5