review.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Review extends Details
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 getViewId()
00100     {
00101         return oxUBase::getViewId();
00102     }
00103 
00109     public function init()
00110     {
00111         if ( oxConfig::getParameter( 'recommid' ) && !$this->getActiveRecommList() ) {
00112             oxUtils::getInstance()->redirect( $this->getConfig()->getShopHomeURL() );
00113         }
00114 
00115         oxUBase::init();
00116     }
00117 
00130     public function render()
00131     {
00132         oxUBase::render();
00133 
00134         if ( !$this->_checkDirectReview( $this->getReviewUserId() ) ) {
00135             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00136         }
00137 
00138         $sReviewUser = oxConfig::getParameter( 'reviewuser' );
00139         $this->_aViewData['reviewuserid'] = ( !$sReviewUser ) ? oxConfig::getParameter( 'reviewuserid' ) : $sReviewUser;
00140 
00141         $this->_aViewData['reviews'] = $this->getReviews();
00142         $this->_aViewData['product'] = $this->getProduct();
00143 
00144         // loading product reviews
00145         $this->_aViewData['crossselllist']     = $this->getCrossSelling();
00146         $this->_aViewData['similarlist']       = $this->getSimilarProducts();
00147         $this->_aViewData['similarrecommlist'] = $this->getRecommList();
00148 
00149 
00150         $this->_aViewData['actvrecommlist'] = $oActiveRecommList = $this->getActiveRecommList();
00151         $this->_aViewData['itemList']       = $oList = $this->getActiveRecommItems();
00152 
00153         if ( $oActiveRecommList ) {
00154             if ( $oList && $oList->count()) {
00155                 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00156             }
00157             // load only lists which we show on screen
00158             $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00159             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00160             $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00161         }
00162 
00163         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00164         $this->_aViewData['rate'] = $this->canRate();
00165         $this->_aViewData['success'] = $this->getReviewSendStatus();
00166 
00167         return $this->_sThisTemplate;
00168     }
00169 
00178     public function saveReview()
00179     {
00180         $sReviewUserId = $this->getReviewUserId();
00181         if ( $sReviewUserId && $this->canAcceptFormData() && $this->_checkDirectReview( $sReviewUserId ) ) {
00182 
00183             if ( ( $oActObject = $this->_getActiveObject() ) && ( $sType = $this->_getActiveType() ) ) {
00184 
00185                 if ( ( $dRating = oxConfig::getParameter( 'rating' ) ) === null ) {
00186                     $dRating = oxConfig::getParameter( 'artrating' );
00187                 }
00188 
00189                 if ( $dRating !== null ) {
00190                     $dRating = (int) $dRating;
00191                 }
00192 
00193                 //save rating
00194                 if ( $dRating !== null && $dRating >= 0 && $dRating <= 5 ) {
00195                     $oRating = oxNew( 'oxrating' );
00196                     if ( $oRating->allowRating( $sReviewUserId, $sType, $oActObject->getId() ) ) {
00197                         $oRating->oxratings__oxuserid   = new oxField( $sReviewUserId );
00198                         $oRating->oxratings__oxtype     = new oxField( $sType );
00199                         $oRating->oxratings__oxobjectid = new oxField( $oActObject->getId() );
00200                         $oRating->oxratings__oxrating   = new oxField( $dRating );
00201                         $oRating->save();
00202 
00203                         $oActObject->addToRatingAverage( $dRating);
00204 
00205                         $this->_blReviewSendStatus = true;
00206                     }
00207                 }
00208 
00209                 if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
00210                     $oReview = oxNew( 'oxreview' );
00211                     $oReview->oxreviews__oxobjectid = new oxField( $oActObject->getId() );
00212                     $oReview->oxreviews__oxtype     = new oxField( $sType );
00213                     $oReview->oxreviews__oxtext     = new oxField( $sReviewText, oxField::T_RAW );
00214                     $oReview->oxreviews__oxlang     = new oxField( oxLang::getInstance()->getBaseLanguage() );
00215                     $oReview->oxreviews__oxuserid   = new oxField( $sReviewUserId );
00216                     $oReview->oxreviews__oxrating   = new oxField( ( $dRating !== null ) ? $dRating : null );
00217                     $oReview->save();
00218 
00219                     $this->_blReviewSendStatus = true;
00220                 }
00221             }
00222         }
00223     }
00224 
00232     protected function _checkDirectReview( $sReviewUserId )
00233     {
00234         $oUser = $this->getUser();
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         $oUser = oxNew( 'oxuser' );
00254         return $oUser->exists( $sUserId );
00255     }
00256 
00262     public function getReviewUserId()
00263     {
00264         if ( $this->_sReviewUserId === null ) {
00265             $this->_sReviewUserId = false;
00266 
00267             //review user from order email
00268             $sReviewUser = oxConfig::getParameter( 'reviewuser' );
00269             $sReviewUser = ( !$sReviewUser ) ? oxConfig::getParameter( 'reviewuserid' ) : $sReviewUser;
00270             if ( $sReviewUser ) {
00271                 $oUser = oxNew( 'oxuser' );
00272                 $this->_sReviewUserId = $sReviewUser;
00273             } elseif ( ( $oUser = $this->getUser() ) ) {
00274                 $this->_sReviewUserId = $oUser->getId();
00275             }
00276         }
00277         return $this->_sReviewUserId;
00278     }
00279 
00285     protected function _getActiveObject()
00286     {
00287         if ( $this->_oActObject === null ) {
00288             $this->_oActObject = false;
00289 
00290             if ( ( $oProduct = $this->getProduct() ) ) {
00291                 $this->_oActObject = $oProduct;
00292             } elseif ( ( $oRecommList = $this->getActiveRecommList() ) ) {
00293                 $this->_oActObject = $oRecommList;
00294             }
00295         }
00296         return $this->_oActObject;
00297     }
00298 
00304     protected function _getActiveType()
00305     {
00306         $sType = null;
00307         if ( $this->getProduct() ) {
00308             $sType = 'oxarticle';
00309         } elseif ( $this->getActiveRecommList() ) {
00310             $sType = 'oxrecommlist';
00311         }
00312         return $sType;
00313     }
00314 
00320     public function getActiveRecommList()
00321     {
00322         if (!$this->getViewConfig()->getShowListmania()) {
00323             return false;
00324         }
00325 
00326         if ( $this->_oActiveRecommList === null ) {
00327             $this->_oActiveRecommList = false;
00328 
00329             if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00330                 $oActiveRecommList = oxNew('oxrecommlist');
00331                 if ( $oActiveRecommList->load( $sRecommId ) ) {
00332                     $this->_oActiveRecommList = $oActiveRecommList;
00333                 }
00334             }
00335         }
00336         return $this->_oActiveRecommList;
00337     }
00338 
00344     public function canRate()
00345     {
00346         if ( $this->_blRate === null ) {
00347             $this->_blRate = false;
00348             if ( ( $oActObject = $this->_getActiveObject() ) ) {
00349                 $oRating = oxNew( 'oxrating' );
00350                 $this->_blRate = $oRating->allowRating( $this->getReviewUserId(), $this->_getActiveType(), $oActObject->getId() );
00351             }
00352         }
00353         return $this->_blRate;
00354     }
00355 
00361     public function getReviews()
00362     {
00363         if ( $this->_aReviews === null ) {
00364             $this->_aReviews = false;
00365             if ( $oObject = $this->_getActiveObject() ) {
00366                 $this->_aReviews = $oObject->getReviews();
00367             }
00368         }
00369         return $this->_aReviews;
00370     }
00371 
00377     public function getRecommList()
00378     {
00379         if ( $this->_oRecommList === null ) {
00380             $this->_oRecommList = false;
00381             if ( $oProduct = $this->getProduct() ) {
00382                 $oRecommList = oxNew('oxrecommlist');
00383                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00384             }
00385         }
00386         return $this->_oRecommList;
00387     }
00388 
00394     public function getActiveRecommItems()
00395     {
00396         if ( $this->_oActiveRecommItems === null ) {
00397             $this->_oActiveRecommItems = false;
00398             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00399                 // sets active page
00400                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00401                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00402 
00403                 // load only lists which we show on screen
00404                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00405                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00406 
00407                 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00408 
00409                 if ( $oList && $oList->count() ) {
00410                     foreach ( $oList as $oItem) {
00411                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00412                     }
00413                     $this->_oActiveRecommItems = $oList;
00414                 }
00415             }
00416         }
00417         return $this->_oActiveRecommItems;
00418     }
00419 
00425     public function getReviewSendStatus()
00426     {
00427         return $this->_blReviewSendStatus;
00428     }
00429 
00435     public function getPageNavigation()
00436     {
00437         if ( $this->_oPageNavigation === null ) {
00438             $this->_oPageNavigation = false;
00439             if ( $this->getActiveRecommList() ) {
00440                 $this->_oPageNavigation = $this->generatePageNavigation();
00441             }
00442         }
00443         return $this->_oPageNavigation;
00444     }
00445 
00451     public function getAdditionalParams()
00452     {
00453         $sAddParams = oxUBase::getAdditionalParams();
00454         if ( $oActRecommList = $this->getActiveRecommList() ) {
00455             $sAddParams .= '&amp;recommid='.$oActRecommList->getId();
00456         }
00457         return $sAddParams;
00458     }
00459 
00465     public function getDynUrlParams()
00466     {
00467         $sParams = parent::getDynUrlParams();
00468 
00469         if ( $sCnId = oxConfig::getParameter( 'cnid' ) ) {
00470             $sParams .= "&amp;cnid={$sCnId}";
00471         }
00472         if ( $sAnId = oxConfig::getParameter( 'anid' ) ) {
00473             $sParams .= "&amp;anid={$sAnId}";
00474         }
00475         if ( $sListType = oxConfig::getParameter( 'listtype' ) ) {
00476             $sParams .= "&amp;listtype={$sListType}";
00477         }
00478         if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00479             $sParams .= "&amp;recommid={$sRecommId}";
00480         }
00481 
00482         return $sParams;
00483     }
00484 }

Generated by  doxygen 1.6.2