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(), true, 302 );
00113         }
00114 
00115         oxUBase::init();
00116     }
00117 
00126     public function render()
00127     {
00128         oxUBase::render();
00129         if ( ! ( $this->getReviewUser() ) ) {
00130             $this->_sThisTemplate = $this->_sThisLoginTemplate;
00131         } else {
00132 
00133             $oActiveRecommList = $this->getActiveRecommList();
00134             $oList = $this->getActiveRecommItems();
00135 
00136             if ( $oActiveRecommList ) {
00137                 if ( $oList && $oList->count()) {
00138                     $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00139                 }
00140                 // load only lists which we show on screen
00141                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00142                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00143                 $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00144             }
00145         }
00146 
00147         return $this->_sThisTemplate;
00148     }
00149 
00155     public function saveReview()
00156     {
00157         if ( ( $oRevUser = $this->getReviewUser() ) && $this->canAcceptFormData() ) {
00158 
00159             if ( ( $oActObject = $this->_getActiveObject() ) && ( $sType = $this->_getActiveType() ) ) {
00160 
00161                 if ( ( $dRating = oxConfig::getParameter( 'rating' ) ) === null ) {
00162                     $dRating = oxConfig::getParameter( 'artrating' );
00163                 }
00164 
00165                 if ( $dRating !== null ) {
00166                     $dRating = (int) $dRating;
00167                 }
00168 
00169                 //save rating
00170                 if ( $dRating !== null && $dRating >= 0 && $dRating <= 5 ) {
00171                     $oRating = oxNew( 'oxrating' );
00172                     if ( $oRating->allowRating( $oRevUser->getId(), $sType, $oActObject->getId() ) ) {
00173                         $oRating->oxratings__oxuserid   = new oxField( $oRevUser->getId() );
00174                         $oRating->oxratings__oxtype     = new oxField( $sType );
00175                         $oRating->oxratings__oxobjectid = new oxField( $oActObject->getId() );
00176                         $oRating->oxratings__oxrating   = new oxField( $dRating );
00177                         $oRating->save();
00178 
00179                         $oActObject->addToRatingAverage( $dRating);
00180 
00181                         $this->_blReviewSendStatus = true;
00182                     }
00183                 }
00184 
00185                 if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
00186                     $oReview = oxNew( 'oxreview' );
00187                     $oReview->oxreviews__oxobjectid = new oxField( $oActObject->getId() );
00188                     $oReview->oxreviews__oxtype     = new oxField( $sType );
00189                     $oReview->oxreviews__oxtext     = new oxField( $sReviewText, oxField::T_RAW );
00190                     $oReview->oxreviews__oxlang     = new oxField( oxLang::getInstance()->getBaseLanguage() );
00191                     $oReview->oxreviews__oxuserid   = new oxField( $oRevUser->getId() );
00192                     $oReview->oxreviews__oxrating   = new oxField( ( $dRating !== null ) ? $dRating : null );
00193                     $oReview->save();
00194 
00195                     $this->_blReviewSendStatus = true;
00196                 }
00197             }
00198         }
00199     }
00200 
00206     public function getReviewUser()
00207     {
00208         if ( $this->_oRevUser === null ) {
00209             $this->_oRevUser = false;
00210             $oUser = oxNew( "oxuser" );
00211 
00212             if ( $sUserId = $oUser->getReviewUserId( $this->getReviewUserHash() ) ) {
00213                 // review user, by link or other source?
00214                 if ( $oUser->load( $sUserId ) ) {
00215                     $this->_oRevUser = $oUser;
00216                 }
00217             } elseif ( $oUser = $this->getUser() ) {
00218                 // session user?
00219                 $this->_oRevUser = $oUser;
00220             }
00221 
00222         }
00223         return $this->_oRevUser;
00224     }
00225 
00231     public function getReviewUserHash()
00232     {
00233         return oxConfig::getParameter( 'reviewuserhash' );
00234     }
00235 
00241     protected function _getActiveObject()
00242     {
00243         if ( $this->_oActObject === null ) {
00244             $this->_oActObject = false;
00245 
00246             if ( ( $oProduct = $this->getProduct() ) ) {
00247                 $this->_oActObject = $oProduct;
00248             } elseif ( ( $oRecommList = $this->getActiveRecommList() ) ) {
00249                 $this->_oActObject = $oRecommList;
00250             }
00251         }
00252         return $this->_oActObject;
00253     }
00254 
00260     protected function _getActiveType()
00261     {
00262         $sType = null;
00263         if ( $this->getProduct() ) {
00264             $sType = 'oxarticle';
00265         } elseif ( $this->getActiveRecommList() ) {
00266             $sType = 'oxrecommlist';
00267         }
00268         return $sType;
00269     }
00270 
00276     public function getActiveRecommList()
00277     {
00278         if (!$this->getViewConfig()->getShowListmania()) {
00279             return false;
00280         }
00281 
00282         if ( $this->_oActiveRecommList === null ) {
00283             $this->_oActiveRecommList = false;
00284 
00285             if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00286                 $oActiveRecommList = oxNew('oxrecommlist');
00287                 if ( $oActiveRecommList->load( $sRecommId ) ) {
00288                     $this->_oActiveRecommList = $oActiveRecommList;
00289                 }
00290             }
00291         }
00292         return $this->_oActiveRecommList;
00293     }
00294 
00300     public function canRate()
00301     {
00302         if ( $this->_blRate === null ) {
00303             $this->_blRate = false;
00304             if ( ( $oActObject = $this->_getActiveObject() ) && ( $oRevUser = $this->getReviewUser() ) ) {
00305                 $oRating = oxNew( 'oxrating' );
00306                 $this->_blRate = $oRating->allowRating( $oRevUser->getId(), $this->_getActiveType(), $oActObject->getId() );
00307             }
00308         }
00309         return $this->_blRate;
00310     }
00311 
00317     public function getReviews()
00318     {
00319         if ( $this->_aReviews === null ) {
00320             $this->_aReviews = false;
00321             if ( $oObject = $this->_getActiveObject() ) {
00322                 $this->_aReviews = $oObject->getReviews();
00323             }
00324         }
00325         return $this->_aReviews;
00326     }
00327 
00333     public function getRecommList()
00334     {
00335         if ( $this->_oRecommList === null ) {
00336             $this->_oRecommList = false;
00337             if ( $oProduct = $this->getProduct() ) {
00338                 $oRecommList = oxNew('oxrecommlist');
00339                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00340             }
00341         }
00342         return $this->_oRecommList;
00343     }
00344 
00350     public function getActiveRecommItems()
00351     {
00352         if ( $this->_oActiveRecommItems === null ) {
00353             $this->_oActiveRecommItems = false;
00354             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00355                 // sets active page
00356                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00357                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00358 
00359                 // load only lists which we show on screen
00360                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00361                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00362 
00363                 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00364 
00365                 if ( $oList && $oList->count() ) {
00366                     foreach ( $oList as $oItem) {
00367                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00368                     }
00369                     $this->_oActiveRecommItems = $oList;
00370                 }
00371             }
00372         }
00373         return $this->_oActiveRecommItems;
00374     }
00375 
00381     public function getReviewSendStatus()
00382     {
00383         return $this->_blReviewSendStatus;
00384     }
00385 
00391     public function getPageNavigation()
00392     {
00393         if ( $this->_oPageNavigation === null ) {
00394             $this->_oPageNavigation = false;
00395             if ( $this->getActiveRecommList() ) {
00396                 $this->_oPageNavigation = $this->generatePageNavigation();
00397             }
00398         }
00399         return $this->_oPageNavigation;
00400     }
00401 
00407     public function getAdditionalParams()
00408     {
00409         $sAddParams = oxUBase::getAdditionalParams();
00410         if ( $oActRecommList = $this->getActiveRecommList() ) {
00411             $sAddParams .= '&amp;recommid='.$oActRecommList->getId();
00412         }
00413         return $sAddParams;
00414     }
00415 
00421     public function getDynUrlParams()
00422     {
00423         $sParams = parent::getDynUrlParams();
00424 
00425         if ( $sCnId = oxConfig::getParameter( 'cnid' ) ) {
00426             $sParams .= "&amp;cnid={$sCnId}";
00427         }
00428         if ( $sAnId = oxConfig::getParameter( 'anid' ) ) {
00429             $sParams .= "&amp;anid={$sAnId}";
00430         }
00431         if ( $sListType = oxConfig::getParameter( 'listtype' ) ) {
00432             $sParams .= "&amp;listtype={$sListType}";
00433         }
00434         if ( $sRecommId = oxConfig::getParameter( 'recommid' ) ) {
00435             $sParams .= "&amp;recommid={$sRecommId}";
00436         }
00437 
00438         return $sParams;
00439     }
00440 }