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' );
00189         if ($dRating < 0 || $dRating > 5) {
00190             $dRating = null;
00191         }
00192         // #1590M
00193         /*if ( !$sReviewText ) {
00194             $this->_aViewData['success'] = true;
00195             return;
00196         }*/
00197 
00198         $sType     = $this->_getActiveType();
00199         $sObjectId = $this->_getActiveObject()->getId();
00200         if ($sType && $sObjectId) {
00201             //save rating
00202             if ( $dRating ) {
00203                 $oRating = oxNew( 'oxrating' );
00204                 $oRating->oxratings__oxuserid   = new oxField($sReviewUserId);
00205                 $oRating->oxratings__oxtype     = new oxField($sType, oxField::T_RAW);
00206                 $oRating->oxratings__oxobjectid = new oxField($sObjectId);
00207                 $oRating->oxratings__oxrating   = new oxField($dRating);
00208                 $oRating->save();
00209                 if ($this->_oProduct) {
00210                     $this->_oProduct->addToRatingAverage( $dRating);
00211                 } elseif ($this->_oActiveRecommList) {
00212                     $this->_oActiveRecommList->addToRatingAverage( $dRating);
00213                 }
00214                 $this->_blReviewSendStatus = true;
00215             }
00216 
00217             if ( $sReviewText ) {
00218                 $oReview = oxNew( 'oxreview' );
00219                 $oReview->oxreviews__oxuserid   = new oxField($sReviewUserId);
00220                 $oReview->oxreviews__oxtype     = new oxField($sType, oxField::T_RAW);
00221                 $oReview->oxreviews__oxobjectid = new oxField($sObjectId);
00222                 $oReview->oxreviews__oxtext     = new oxField($sReviewText);
00223                 $oReview->oxreviews__oxlang     = new oxField(oxLang::getInstance()->getBaseLanguage());
00224                 $oReview->oxreviews__oxrating   = new oxField(( $dRating) ? $dRating : null);
00225                 $oReview->save();
00226                 $this->_blReviewSendStatus = true;
00227             }
00228         }
00229     }
00230 
00238     protected function _checkDirectReview($sReviewUserId) {
00239         $oUser = $this->getUser();
00240         $blAllow = false;
00241         if ($oUser && ($sReviewUserId == $oUser->getId())) {
00242             $blAllow = true;
00243         } else {
00244             $blAllow = $this->_allowDirectReview( $sReviewUserId );
00245         }
00246         return $blAllow;
00247     }
00248 
00257     protected function _allowDirectReview( $sUserId )
00258     {
00259         if ( $sUserId == 'oxdefaultadmin' ) {
00260             return false;
00261         }
00262 
00263         $oUser = oxNew( 'oxuser' );
00264         if ( !$oUser->exists( $sUserId ) ) {
00265             return false;
00266         }
00267 
00268         return true;
00269     }
00270 
00276     public function getReviewUserId()
00277     {
00278         if ( $this->_sReviewUserId === null ) {
00279             $this->_sReviewUserId = false;
00280 
00281             $sReviewUserId = oxConfig::getParameter( 'reviewuserid' );
00282             $oUser = $this->getUser();
00283             if (!$sReviewUserId && $oUser) {
00284                 $sReviewUserId = $oUser->getId();
00285             }
00286             $this->_sReviewUserId = $sReviewUserId;
00287         }
00288         return $this->_sReviewUserId;
00289     }
00290 
00296     public function getProduct()
00297     {
00298         if ( $this->_oProduct === null ) {
00299             $this->_oProduct = false;
00300 
00301             if ( $sAnid = oxConfig::getParameter( 'anid' ) ) {
00302                 $this->_oProduct = oxNewArticle( $sAnid );
00303             }
00304         }
00305         return $this->_oProduct;
00306     }
00307 
00313     protected function _getActiveObject()
00314     {
00315         if ( $this->_oActObject === null ) {
00316             $this->_oActObject = false;
00317 
00318             if ( $this->_oProduct ) {
00319                 $this->_oActObject = $this->_oProduct;
00320             } elseif ( $this->_oActiveRecommList ) {
00321                 $this->_oActObject = $this->_oActiveRecommList;
00322             }
00323         }
00324         return $this->_oActObject;
00325     }
00326 
00332     protected function _getActiveType()
00333     {
00334         if ($this->_oProduct) {
00335             $sType = 'oxarticle';
00336         } elseif ($this->_oActiveRecommList) {
00337             $sType = 'oxrecommlist';
00338         }
00339         return $sType;
00340     }
00341 
00347     public function getActiveRecommList()
00348     {
00349         if ( $this->_oActiveRecommList === null ) {
00350             $this->_oActiveRecommList = false;
00351 
00352             if( $sRecommId = oxConfig::getParameter( 'recommid' ) ){
00353                 $oActiveRecommList = oxNew('oxrecommlist');
00354                 if ( $oActiveRecommList->load( $sRecommId ) ) {
00355                     $this->_oActiveRecommList = $oActiveRecommList;
00356                 }
00357             }
00358         }
00359         return $this->_oActiveRecommList;
00360     }
00361 
00367     public function canRate()
00368     {
00369         if ( $this->_blRate === null ) {
00370             $this->_blRate = false;
00371             $sType     = $this->_getActiveType();
00372             $sObjectId = $this->_getActiveObject()->getId();
00373             $oRating = oxNew( 'oxrating' );
00374             $this->_blRate = $oRating->allowRating( $this->getReviewUserId(), $sType, $sObjectId);
00375 
00376         }
00377         return $this->_blRate;
00378     }
00379 
00385     public function getReviews()
00386     {
00387         if ( $this->_aReviews === null ) {
00388             $this->_aReviews = false;
00389             if ( $oObject = $this->_getActiveObject() ) {
00390                 $this->_aReviews = $oObject->getReviews();
00391             }
00392         }
00393         return $this->_aReviews;
00394     }
00395 
00401     public function getCrossSelling()
00402     {
00403         if ( $this->_oCrossSelling === null ) {
00404             $this->_oCrossSelling = false;
00405             if ( $this->_oProduct ) {
00406                 $this->_oCrossSelling = $this->_oProduct->getCrossSelling();
00407             }
00408         }
00409         return $this->_oCrossSelling;
00410     }
00411 
00417     public function getSimilarProducts()
00418     {
00419         if ( $this->_oSimilarProducts === null ) {
00420             $this->_oSimilarProducts = false;
00421             if ( $this->_oProduct ) {
00422                 $this->_oSimilarProducts = $this->_oProduct->getSimilarProducts();
00423             }
00424         }
00425         return $this->_oSimilarProducts;
00426     }
00427 
00433     public function getRecommList()
00434     {
00435         if ( $this->_oRecommList === null ) {
00436             $this->_oRecommList = false;
00437             if ( $this->_oProduct ) {
00438                 $oRecommList = oxNew('oxrecommlist');
00439                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array($this->_oProduct->getId()));
00440             }
00441         }
00442         return $this->_oRecommList;
00443     }
00444 
00450     public function getActiveRecommItems()
00451     {
00452         if ( $this->_oActiveRecommItems === null ) {
00453             $this->_oActiveRecommItems = false;
00454             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00455                 // sets active page
00456                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00457                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00458 
00459                 // load only lists which we show on screen
00460                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00461                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00462 
00463                 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00464 
00465                 if ( $oList && $oList->count() ) {
00466                     foreach ( $oList as $oItem) {
00467                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00468                     }
00469                     $this->_oActiveRecommItems = $oList;
00470                 }
00471             }
00472         }
00473         return $this->_oActiveRecommItems;
00474     }
00475 
00481     public function getReviewSendStatus()
00482     {
00483         return $this->_blReviewSendStatus;
00484     }
00485 
00491     public function getPageNavigation()
00492     {
00493         if ( $this->_oPageNavigation === null ) {
00494             $this->_oPageNavigation = false;
00495             if ( $this->_oActiveRecommList ) {
00496                 $this->_oPageNavigation = $this->generatePageNavigation();
00497             }
00498         }
00499         return $this->_oPageNavigation;
00500     }
00501 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5