review.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class Review extends Details
00008 {
00013     protected $_oRevUser = 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->getReviewUser() ) ) {
00135             $this->_sThisTemplate = $this->_sThisLoginTemplate;
00136         } else {
00137 
00138             $this->_aViewData['reviewuserhash'] = $this->getReviewUserHash();
00139 
00140             $this->_aViewData['reviews'] = $this->getReviews();
00141             $this->_aViewData['product'] = $this->getProduct();
00142 
00143             // loading product reviews
00144             $this->_aViewData['crossselllist']     = $this->getCrossSelling();
00145             $this->_aViewData['similarlist']       = $this->getSimilarProducts();
00146             $this->_aViewData['similarrecommlist'] = $this->getRecommList();
00147 
00148             $this->_aViewData['actvrecommlist'] = $oActiveRecommList = $this->getActiveRecommList();
00149             $this->_aViewData['itemList']       = $oList = $this->getActiveRecommItems();
00150 
00151             if ( $oActiveRecommList ) {
00152                 if ( $oList && $oList->count()) {
00153                     $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00154                 }
00155                 // load only lists which we show on screen
00156                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00157                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00158                 $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00159             }
00160 
00161             $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00162             $this->_aViewData['rate'] = $this->canRate();
00163             $this->_aViewData['success'] = $this->getReviewSendStatus();
00164         }
00165 
00166         return $this->_sThisTemplate;
00167     }
00168 
00177     public function saveReview()
00178     {
00179         if ( ( $oRevUser = $this->getReviewUser() ) && $this->canAcceptFormData() ) {
00180 
00181             if ( ( $oActObject = $this->_getActiveObject() ) && ( $sType = $this->_getActiveType() ) ) {
00182 
00183                 if ( ( $dRating = oxConfig::getParameter( 'rating' ) ) === null ) {
00184                     $dRating = oxConfig::getParameter( 'artrating' );
00185                 }
00186 
00187                 if ( $dRating !== null ) {
00188                     $dRating = (int) $dRating;
00189                 }
00190 
00191                 //save rating
00192                 if ( $dRating !== null && $dRating >= 0 && $dRating <= 5 ) {
00193                     $oRating = oxNew( 'oxrating' );
00194                     if ( $oRating->allowRating( $oRevUser->getId(), $sType, $oActObject->getId() ) ) {
00195                         $oRating->oxratings__oxuserid   = new oxField( $oRevUser->getId() );
00196                         $oRating->oxratings__oxtype     = new oxField( $sType );
00197                         $oRating->oxratings__oxobjectid = new oxField( $oActObject->getId() );
00198                         $oRating->oxratings__oxrating   = new oxField( $dRating );
00199                         $oRating->save();
00200 
00201                         $oActObject->addToRatingAverage( $dRating);
00202 
00203                         $this->_blReviewSendStatus = true;
00204                     }
00205                 }
00206 
00207                 if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
00208                     $oReview = oxNew( 'oxreview' );
00209                     $oReview->oxreviews__oxobjectid = new oxField( $oActObject->getId() );
00210                     $oReview->oxreviews__oxtype     = new oxField( $sType );
00211                     $oReview->oxreviews__oxtext     = new oxField( $sReviewText, oxField::T_RAW );
00212                     $oReview->oxreviews__oxlang     = new oxField( oxLang::getInstance()->getBaseLanguage() );
00213                     $oReview->oxreviews__oxuserid   = new oxField( $oRevUser->getId() );
00214                     $oReview->oxreviews__oxrating   = new oxField( ( $dRating !== null ) ? $dRating : null );
00215                     $oReview->save();
00216 
00217                     $this->_blReviewSendStatus = true;
00218                 }
00219             }
00220         }
00221     }
00222 
00232     protected function _checkDirectReview( $sReviewUserId )
00233     {
00234         return ( bool ) $this->getReviewUser();
00235     }
00236 
00247     protected function _allowDirectReview( $sUserId )
00248     {
00249         return ( bool ) $this->getReviewUser();
00250     }
00251 
00257     public function getReviewUser()
00258     {
00259         if ( $this->_oRevUser === null ) {
00260             $this->_oRevUser = false;
00261             $oUser = oxNew( "oxuser" );
00262 
00263             if ( $sUserId = $oUser->getReviewUserId( $this->getReviewUserHash() ) ) {
00264                 // review user, by link or other source?
00265                 if ( $oUser->load( $sUserId ) ) {
00266                     $this->_oRevUser = $oUser;
00267                 }
00268             } elseif ( $oUser = $this->getUser() ) {
00269                 // session user?
00270                 $this->_oRevUser = $oUser;
00271             }
00272 
00273         }
00274         return $this->_oRevUser;
00275     }
00276 
00282     public function getReviewUserHash()
00283     {
00284         return oxConfig::getParameter( 'reviewuserhash' );
00285     }
00286 
00294     public function getReviewUserId()
00295     {
00296         $sId = null;
00297         if ( $oRevUser = $this->getReviewUser() ) {
00298             $sId = $oRevUser->getId();
00299         }
00300         return $sId;
00301     }
00302 
00308     protected function _getActiveObject()
00309     {
00310         if ( $this->_oActObject === null ) {
00311             $this->_oActObject = false;
00312 
00313             if ( ( $oProduct = $this->getProduct() ) ) {
00314                 $this->_oActObject = $oProduct;
00315             } elseif ( ( $oRecommList = $this->getActiveRecommList() ) ) {
00316                 $this->_oActObject = $oRecommList;
00317             }
00318         }
00319         return $this->_oActObject;
00320     }
00321 
00327     protected function _getActiveType()
00328     {
00329         $sType = null;
00330         if ( $this->getProduct() ) {
00331             $sType = 'oxarticle';
00332         } elseif ( $this->getActiveRecommList() ) {
00333             $sType = 'oxrecommlist';
00334         }
00335         return $sType;
00336     }
00337 
00343     public function getActiveRecommList()
00344     {
00345         if (!$this->getViewConfig()->getShowListmania()) {
00346             return false;
00347         }
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             if ( ( $oActObject = $this->_getActiveObject() ) && ( $oRevUser = $this->getReviewUser() ) ) {
00372                 $oRating = oxNew( 'oxrating' );
00373                 $this->_blRate = $oRating->allowRating( $oRevUser->getId(), $this->_getActiveType(), $oActObject->getId() );
00374             }
00375         }
00376         return $this->_blRate;
00377     }
00378 
00384     public function getReviews()
00385     {
00386         if ( $this->_aReviews === null ) {
00387             $this->_aReviews = false;
00388             if ( $oObject = $this->_getActiveObject() ) {
00389                 $this->_aReviews = $oObject->getReviews();
00390             }
00391         }
00392         return $this->_aReviews;
00393     }
00394 
00400     public function getRecommList()
00401     {
00402         if ( $this->_oRecommList === null ) {
00403             $this->_oRecommList = false;
00404             if ( $oProduct = $this->getProduct() ) {
00405                 $oRecommList = oxNew('oxrecommlist');
00406                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00407             }
00408         }
00409         return $this->_oRecommList;
00410     }
00411 
00417     public function getActiveRecommItems()
00418     {
00419         if ( $this->_oActiveRecommItems === null ) {
00420             $this->_oActiveRecommItems = false;
00421             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00422                 // sets active page
00423                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00424                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00425 
00426                 // load only lists which we show on screen
00427                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00428                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00429 
00430                 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00431 
00432                 if ( $oList && $oList->count() ) {
00433                     foreach ( $oList as $oItem) {
00434                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00435                     }
00436                     $this->_oActiveRecommItems = $oList;
00437                 }
00438             }
00439         }
00440         return $this->_oActiveRecommItems;
00441     }
00442 
00448     public function getReviewSendStatus()
00449     {
00450         return $this->_blReviewSendStatus;
00451     }
00452 
00458     public function getPageNavigation()
00459     {
00460         if ( $this->_oPageNavigation === null ) {
00461             $this->_oPageNavigation = false;
00462             if ( $this->getActiveRecommList() ) {
00463                 $this->_oPageNavigation = $this->generatePageNavigation();
00464             }
00465         }
00466         return $this->_oPageNavigation;
00467     }
00468 
00474     public function getAdditionalParams()
00475     {
00476         $sAddParams = oxUBase::getAdditionalParams();
00477         if ( $oActRecommList = $this->getActiveRecommList() ) {
00478             $sAddParams .= '&amp;recommid='.$oActRecommList->getId();
00479         }
00480         return $sAddParams;
00481     }
00482 
00488     public function getDynUrlParams()
00489     {
00490         $sParams = parent::getDynUrlParams();
00491 
00492         if ( $sCnId = oxConfig::getParameter( 'cnid' ) ) {
00493             $sParams .= "&amp;cnid={$sCnId}";
00494         }
00495         if ( $sAnId = oxConfig::getParameter( 'anid' ) ) {
00496             $sParams .= "&amp;anid={$sAnId}";
00497         }
00498         if ( $sListType = oxConfig::getParameter( 'listtype' ) ) {
00499             $sParams .= "&amp;listtype={$sListType}";
00500         }
00501         if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00502             $sParams .= "&amp;recommid={$sRecommId}";
00503         }
00504 
00505         return $sParams;
00506     }
00507 }