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 
00093     protected $_iViewIndexState = 1;
00094 
00100     public function init()
00101     {
00102         $myConfig = $this->getConfig();
00103 
00104         parent::init();
00105 
00106         $this->_oProduct = $this->getProduct();
00107         $this->_oActiveRecommList = $this->getActiveRecommList();
00108         if ( oxConfig::getParameter( 'recommid' ) && !$this->_oActiveRecommList ) {
00109             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() );
00110         }
00111     }
00112 
00125     public function render()
00126     {
00127         parent::render();
00128 
00129         if ( !$this->_checkDirectReview($this->getReviewUserId()) ) {
00130             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00131         }
00132 
00133         $this->_aViewData['reviewuserid'] = $this->getReviewUserId();
00134 
00135         $this->_aViewData['reviews'] = $this->getReviews();
00136         $this->_aViewData['product'] = $this->getProduct();
00137 
00138         // loading product reviews
00139         $this->_aViewData['crossselllist']     = $this->getCrossSelling();
00140         $this->_aViewData['similarlist']       = $this->getSimilarProducts();
00141         $this->_aViewData['similarrecommlist'] = $this->getRecommList();
00142 
00143 
00144         $this->_aViewData['actvrecommlist'] = $this->getActiveRecommList();
00145         $this->_aViewData['itemList']       = $this->getActiveRecommItems();
00146 
00147         if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00148             $oList = $this->getActiveRecommItems();
00149             if ( $oList && $oList->count()) {
00150                 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00151             }
00152             // load only lists which we show on screen
00153             $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00154             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00155             $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00156         }
00157 
00158         if ( $this->_oActiveRecommList) {
00159             $this->_sAdditionalParams .= '&amp;recommid='.$this->_oActiveRecommList->getId();
00160         }
00161 
00162         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00163 
00164         $this->_aViewData['rate'] = $this->canRate();
00165 
00166         $this->_aViewData['success'] = $this->getReviewSendStatus();
00167 
00168         return $this->_sThisTemplate;
00169     }
00170 
00179     public function saveReview()
00180     {
00181         $sReviewUserId = $this->getReviewUserId();
00182 
00183         if ( !$this->_checkDirectReview($sReviewUserId) ) {
00184             return;
00185         }
00186 
00187         $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt' ) );
00188         $dRating     = ( oxConfig::getParameter( 'rating' ) ) ? oxConfig::getParameter( 'rating' ) : oxConfig::getParameter( 'artrating' );
00189 
00190         if ($dRating < 0 || $dRating > 5) {
00191             $dRating = null;
00192         }
00193         // #1590M
00194         /*if ( !$sReviewText ) {
00195             $this->_aViewData['success'] = true;
00196             return;
00197         }*/
00198 
00199         $sType     = $this->_getActiveType();
00200         $sObjectId = $this->_getActiveObject()->getId();
00201         if ($sType && $sObjectId) {
00202             //save rating
00203             if ( $dRating ) {
00204                 $oRating = oxNew( 'oxrating' );
00205                 $oRating->oxratings__oxuserid   = new oxField($sReviewUserId);
00206                 $oRating->oxratings__oxtype     = new oxField($sType, oxField::T_RAW);
00207                 $oRating->oxratings__oxobjectid = new oxField($sObjectId);
00208                 $oRating->oxratings__oxrating   = new oxField($dRating);
00209                 $oRating->save();
00210                 if ($this->_oProduct) {
00211                     $this->_oProduct->addToRatingAverage( $dRating);
00212                 } elseif ($this->_oActiveRecommList) {
00213                     $this->_oActiveRecommList->addToRatingAverage( $dRating);
00214                 }
00215                 $this->_blReviewSendStatus = true;
00216             }
00217 
00218             if ( $sReviewText ) {
00219                 $oReview = oxNew( 'oxreview' );
00220                 $oReview->oxreviews__oxuserid   = new oxField($sReviewUserId);
00221                 $oReview->oxreviews__oxtype     = new oxField($sType, oxField::T_RAW);
00222                 $oReview->oxreviews__oxobjectid = new oxField($sObjectId);
00223                 $oReview->oxreviews__oxtext     = new oxField($sReviewText);
00224                 $oReview->oxreviews__oxlang     = new oxField(oxLang::getInstance()->getBaseLanguage());
00225                 $oReview->oxreviews__oxrating   = new oxField(( $dRating) ? $dRating : null);
00226                 $oReview->save();
00227                 $this->_blReviewSendStatus = true;
00228             }
00229         }
00230     }
00231 
00239     protected function _checkDirectReview($sReviewUserId) {
00240         $oUser = $this->getUser();
00241         $blAllow = false;
00242         if ($oUser && ($sReviewUserId == $oUser->getId())) {
00243             $blAllow = true;
00244         } else {
00245             $blAllow = $this->_allowDirectReview( $sReviewUserId );
00246         }
00247         return $blAllow;
00248     }
00249 
00258     protected function _allowDirectReview( $sUserId )
00259     {
00260         if ( $sUserId == 'oxdefaultadmin' ) {
00261             return false;
00262         }
00263 
00264         $oUser = oxNew( 'oxuser' );
00265         if ( !$oUser->exists( $sUserId ) ) {
00266             return false;
00267         }
00268 
00269         return true;
00270     }
00271 
00277     public function getReviewUserId()
00278     {
00279         if ( $this->_sReviewUserId === null ) {
00280             $this->_sReviewUserId = false;
00281 
00282             $sReviewUserId = oxConfig::getParameter( 'reviewuserid' );
00283             $oUser = $this->getUser();
00284             if (!$sReviewUserId && $oUser) {
00285                 $sReviewUserId = $oUser->getId();
00286             }
00287             $this->_sReviewUserId = $sReviewUserId;
00288         }
00289         return $this->_sReviewUserId;
00290     }
00291 
00297     public function getProduct()
00298     {
00299         if ( $this->_oProduct === null ) {
00300             $this->_oProduct = false;
00301 
00302             if ( $sAnid = oxConfig::getParameter( 'anid' ) ) {
00303                 $this->_oProduct = oxNewArticle( $sAnid );
00304             }
00305         }
00306         return $this->_oProduct;
00307     }
00308 
00314     protected function _getActiveObject()
00315     {
00316         if ( $this->_oActObject === null ) {
00317             $this->_oActObject = false;
00318 
00319             if ( $this->_oProduct ) {
00320                 $this->_oActObject = $this->_oProduct;
00321             } elseif ( $this->_oActiveRecommList ) {
00322                 $this->_oActObject = $this->_oActiveRecommList;
00323             }
00324         }
00325         return $this->_oActObject;
00326     }
00327 
00333     protected function _getActiveType()
00334     {
00335         if ($this->_oProduct) {
00336             $sType = 'oxarticle';
00337         } elseif ($this->_oActiveRecommList) {
00338             $sType = 'oxrecommlist';
00339         }
00340         return $sType;
00341     }
00342 
00348     public function getActiveRecommList()
00349     {
00350         if ( $this->_oActiveRecommList === null ) {
00351             $this->_oActiveRecommList = false;
00352 
00353             if( $sRecommId = oxConfig::getParameter( 'recommid' ) ){
00354                 $oActiveRecommList = oxNew('oxrecommlist');
00355                 if ( $oActiveRecommList->load( $sRecommId ) ) {
00356                     $this->_oActiveRecommList = $oActiveRecommList;
00357                 }
00358             }
00359         }
00360         return $this->_oActiveRecommList;
00361     }
00362 
00368     public function canRate()
00369     {
00370         if ( $this->_blRate === null ) {
00371             $this->_blRate = false;
00372             $sType     = $this->_getActiveType();
00373             $sObjectId = $this->_getActiveObject()->getId();
00374             $oRating = oxNew( 'oxrating' );
00375             $this->_blRate = $oRating->allowRating( $this->getReviewUserId(), $sType, $sObjectId);
00376 
00377         }
00378         return $this->_blRate;
00379     }
00380 
00386     public function getReviews()
00387     {
00388         if ( $this->_aReviews === null ) {
00389             $this->_aReviews = false;
00390             if ( $oObject = $this->_getActiveObject() ) {
00391                 $this->_aReviews = $oObject->getReviews();
00392             }
00393         }
00394         return $this->_aReviews;
00395     }
00396 
00402     public function getCrossSelling()
00403     {
00404         if ( $this->_oCrossSelling === null ) {
00405             $this->_oCrossSelling = false;
00406             if ( $this->_oProduct ) {
00407                 $this->_oCrossSelling = $this->_oProduct->getCrossSelling();
00408             }
00409         }
00410         return $this->_oCrossSelling;
00411     }
00412 
00418     public function getSimilarProducts()
00419     {
00420         if ( $this->_oSimilarProducts === null ) {
00421             $this->_oSimilarProducts = false;
00422             if ( $this->_oProduct ) {
00423                 $this->_oSimilarProducts = $this->_oProduct->getSimilarProducts();
00424             }
00425         }
00426         return $this->_oSimilarProducts;
00427     }
00428 
00434     public function getRecommList()
00435     {
00436         if ( $this->_oRecommList === null ) {
00437             $this->_oRecommList = false;
00438             if ( $this->_oProduct ) {
00439                 $oRecommList = oxNew('oxrecommlist');
00440                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array($this->_oProduct->getId()));
00441             }
00442         }
00443         return $this->_oRecommList;
00444     }
00445 
00451     public function getActiveRecommItems()
00452     {
00453         if ( $this->_oActiveRecommItems === null ) {
00454             $this->_oActiveRecommItems = false;
00455             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00456                 // sets active page
00457                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00458                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00459 
00460                 // load only lists which we show on screen
00461                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00462                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00463 
00464                 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00465 
00466                 if ( $oList && $oList->count() ) {
00467                     foreach ( $oList as $oItem) {
00468                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00469                     }
00470                     $this->_oActiveRecommItems = $oList;
00471                 }
00472             }
00473         }
00474         return $this->_oActiveRecommItems;
00475     }
00476 
00482     public function getReviewSendStatus()
00483     {
00484         return $this->_blReviewSendStatus;
00485     }
00486 
00492     public function getPageNavigation()
00493     {
00494         if ( $this->_oPageNavigation === null ) {
00495             $this->_oPageNavigation = false;
00496             if ( $this->_oActiveRecommList ) {
00497                 $this->_oPageNavigation = $this->generatePageNavigation();
00498             }
00499         }
00500         return $this->_oPageNavigation;
00501     }
00502 }

Generated on Fri Dec 19 14:20:30 2008 for OXID eShop CE by  doxygen 1.5.5