recommlist.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class RecommList extends aList
00009 {
00014     protected $_sListType = 'recommlist';
00015 
00020     protected $_sThisTemplate = 'page/recommendations/recommlist.tpl';
00021 
00026     protected $_oOtherRecommList = null;
00027 
00032     protected $_aReviews = null;
00033 
00038     protected $_blRate = null;
00039 
00044     protected $_dRatingValue = null;
00045 
00050     protected $_iRatingCnt = null;
00051 
00056     protected $_oSearchRecommLists = null;
00057 
00062     protected $_sSearch = null;
00063 
00069     protected $_sTplLocation = null;
00070 
00075     protected $_oPageNavigation = null;
00076 
00082     public function render()
00083     {
00084         oxUBase::render();
00085         $myConfig = $this->getConfig();
00086 
00087         $this->_iAllArtCnt = 0;
00088 
00089         if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00090             if ( ( $oList = $this->getArticleList() ) && $oList->count()) {
00091                 $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00092             }
00093 
00094             if ( $myConfig->getConfigParam( 'bl_rssRecommListArts' ) ) {
00095                 $oRss = oxNew('oxrssfeed');
00096                 $this->addRssFeed($oRss->getRecommListArticlesTitle($oActiveRecommList), $oRss->getRecommListArticlesUrl($this->_oActiveRecommList), 'recommlistarts');
00097             }
00098 
00099         } else {
00100             if ( ( $oList = $this->getRecommLists() ) && $oList->count() ) {
00101                 $oRecommList = oxNew( 'oxrecommlist' );
00102                 $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount( $this->getRecommSearch() );
00103             }
00104         }
00105 
00106         if ( !( $oList = $this->getArticleList() ) ) {
00107             $oList = $this->getRecommLists();
00108         }
00109 
00110         if ( $oList && $oList->count() ) {
00111             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00112             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00113             $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00114         }
00115         // processing list articles
00116         $this->_processListArticles();
00117 
00118         return $this->_sThisTemplate;
00119     }
00120 
00126     protected function _getProductLinkType()
00127     {
00128         return OXARTICLE_LINKTYPE_RECOMM;
00129     }
00130 
00136     public function getAddUrlParams()
00137     {
00138         $sAddParams  = parent::getAddUrlParams();
00139         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00140 
00141         if ( $oRecommList = $this->getActiveRecommList() ) {
00142             $sAddParams .= "&amp;recommid=".$oRecommList->getId();
00143         }
00144 
00145         return $sAddParams;
00146     }
00147 
00153     public function getAddSeoUrlParams()
00154     {
00155         $sAddParams = parent::getAddSeoUrlParams();
00156         if ( $sParam = oxConfig::getParameter( "searchrecomm", true ) ) {
00157             $sAddParams .= "&amp;searchrecomm=" . rawurlencode( $sParam );
00158         }
00159         return $sAddParams;
00160     }
00161 
00167     public function saveReview()
00168     {
00169         if ( $this->canAcceptFormData() &&
00170              ( $oRecommList = $this->getActiveRecommList() ) && ( $oUser = $this->getUser() ) ) {
00171 
00172             //save rating
00173             $dRating = oxConfig::getParameter( 'recommlistrating' );
00174             if ( $dRating !== null ) {
00175                 $dRating = (int) $dRating;
00176             }
00177 
00178             if ( $dRating !== null && $dRating >= 0 && $dRating <= 5 ) {
00179                 $oRating = oxNew( 'oxrating' );
00180                 if ( $oRating->allowRating( $oUser->getId(), 'oxrecommlist', $oRecommList->getId() ) ) {
00181                     $oRating->oxratings__oxuserid   = new oxField( $oUser->getId() );
00182                     $oRating->oxratings__oxtype     = new oxField( 'oxrecommlist' );
00183                     $oRating->oxratings__oxobjectid = new oxField( $oRecommList->getId() );
00184                     $oRating->oxratings__oxrating   = new oxField( $dRating );
00185                     $oRating->save();
00186                     $oRecommList->addToRatingAverage( $dRating );
00187                 }
00188             }
00189 
00190             if ( ( $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt', true ) ) ) ) {
00191                 $oReview = oxNew( 'oxreview' );
00192                 $oReview->oxreviews__oxobjectid = new oxField( $oRecommList->getId() );
00193                 $oReview->oxreviews__oxtype     = new oxField( 'oxrecommlist' );
00194                 $oReview->oxreviews__oxtext     = new oxField( $sReviewText, oxField::T_RAW );
00195                 $oReview->oxreviews__oxlang     = new oxField( oxLang::getInstance()->getBaseLanguage() );
00196                 $oReview->oxreviews__oxuserid   = new oxField( $oUser->getId() );
00197                 $oReview->oxreviews__oxrating   = new oxField( ( $dRating !== null ) ? $dRating : null );
00198                 $oReview->save();
00199             }
00200         }
00201     }
00202 
00208     public function getNavigationParams()
00209     {
00210         $aParams = oxUBase::getNavigationParams();
00211         $aParams['recommid'] = oxConfig::getParameter( 'recommid' );
00212 
00213         return $aParams;
00214     }
00215 
00221     public function getArticleList()
00222     {
00223         if ( $this->_aArticleList === null ) {
00224             $this->_aArticleList = false;
00225             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00226                 // sets active page
00227                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00228                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00229 
00230                 // load only lists which we show on screen
00231                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00232                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00233 
00234                 $this->_aArticleList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00235 
00236                 if ( $this->_aArticleList && $this->_aArticleList->count() ) {
00237                     foreach ( $this->_aArticleList as $oItem ) {
00238                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00239                     }
00240                 }
00241             }
00242         }
00243         return $this->_aArticleList;
00244     }
00245 
00251     public function getSimilarRecommLists()
00252     {
00253         if ( $this->_oOtherRecommList === null ) {
00254             $this->_oOtherRecommList = false;
00255             if ( ( $oActiveRecommList = $this->getActiveRecommList() ) && ( $oList = $this->getArticleList() ) ) {
00256                 $oRecommLists = $oActiveRecommList->getRecommListsByIds( $oList->arrayKeys());
00257                 //do not show the same list
00258                 unset( $oRecommLists[$oActiveRecommList->getId()] );
00259                 $this->_oOtherRecommList = $oRecommLists;
00260             }
00261         }
00262         return $this->_oOtherRecommList;
00263     }
00264 
00270     public function getReviews()
00271     {
00272         if ( $this->_aReviews === null ) {
00273             $this->_aReviews = false;
00274             if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00275                 $this->_aReviews = $oActiveRecommList->getReviews();
00276             }
00277         }
00278         return $this->_aReviews;
00279     }
00280 
00286     public function isReviewActive()
00287     {
00288         return $this->getConfig()->getConfigParam( 'bl_perfLoadReviews' );
00289     }
00290 
00296     public function canRate()
00297     {
00298         if ( $this->_blRate === null ) {
00299             $this->_blRate = false;
00300             if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00301                 $oRating = oxNew( 'oxrating' );
00302                 $this->_blRate = $oRating->allowRating( oxSession::getVar( 'usr' ), 'oxrecommlist', $oActiveRecommList->getId());
00303             }
00304         }
00305         return $this->_blRate;
00306     }
00307 
00313     public function getRatingValue()
00314     {
00315         if ( $this->_dRatingValue === null ) {
00316             $this->_dRatingValue = (double)0;
00317             if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00318                 $this->_dRatingValue = round( $oActiveRecommList->oxrecommlists__oxrating->value, 1);
00319             }
00320         }
00321         return (double) $this->_dRatingValue;
00322     }
00323 
00329     public function getRatingCount()
00330     {
00331         if ( $this->_iRatingCnt === null ) {
00332             $this->_iRatingCnt = false;
00333             if ( $this->isReviewActive() && ( $oActiveRecommList = $this->getActiveRecommList() ) ) {
00334                 $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
00335             }
00336         }
00337         return $this->_iRatingCnt;
00338     }
00339 
00345     public function getRecommLists()
00346     {
00347         if ( $this->_oSearchRecommLists === null ) {
00348             $this->_oSearchRecommLists = array();
00349             if ( !$this->getActiveRecommList() ) {
00350                 // list of found oxrecommlists
00351                 $oRecommList = oxNew( 'oxrecommlist' );
00352                 $oList = $oRecommList->getSearchRecommLists( $this->getRecommSearch() );
00353                 if ( $oList && $oList->count() ) {
00354                     $this->_oSearchRecommLists = $oList;
00355                 }
00356             }
00357         }
00358         return $this->_oSearchRecommLists;
00359     }
00360 
00366     public function getRecommSearch()
00367     {
00368         if ( $this->_sSearch === null ) {
00369             $this->_sSearch = false;
00370             if ( $sSearch = oxConfig::getParameter( 'searchrecomm', true ) ) {
00371                 $this->_sSearch = $sSearch;
00372             }
00373         }
00374         return $this->_sSearch;
00375     }
00376 
00382     public function getTreePath()
00383     {
00384         $oLang = oxLang::getInstance();
00385 
00386         $aPath[0] = oxNew( "oxcategory" );
00387         $aPath[0]->setLink( false );
00388         $aPath[0]->oxcategories__oxtitle = new oxField( $oLang->translateString('RECOMMLIST') );
00389 
00390         if ( $sSearchparam = $this->getRecommSearch() ) {
00391             $sUrl   = $this->getConfig()->getShopHomeURL()."cl=recommlist&amp;searchrecomm=".rawurlencode( $sSearchparam );
00392             $sTitle = $oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
00393 
00394             $aPath[1] = oxNew( "oxcategory" );
00395             $aPath[1]->setLink( $sUrl );
00396             $aPath[1]->oxcategories__oxtitle = new oxField( $sTitle );
00397         }
00398 
00399         return $aPath;
00400     }
00401 
00407     public function getSearchForHtml()
00408     {
00409         // #M1450 if active recommlist is loaded return it's title
00410         if ( $oActiveRecommList = $this->getActiveRecommList()) {
00411             return $oActiveRecommList->oxrecommlists__oxtitle->value;
00412         }
00413         return oxConfig::getParameter( 'searchrecomm' );
00414     }
00415 
00421     public function generatePageNavigationUrl()
00422     {
00423         if ( ( oxUtils::getInstance()->seoIsActive() && ( $oRecomm = $this->getActiveRecommList() ) ) ) {
00424             $sUrl = $oRecomm->getLink();
00425         } else {
00426             $sUrl = oxUBase::generatePageNavigationUrl();
00427         }
00428         return $sUrl;
00429     }
00430 
00440     protected function _addPageNrParam( $sUrl, $iPage, $iLang = null)
00441     {
00442         if ( oxUtils::getInstance()->seoIsActive() && ( $oRecomm = $this->getActiveRecommList() ) ) {
00443             if ( $iPage ) {
00444                 // only if page number > 0
00445                 $sUrl = $oRecomm->getBaseSeoLink( $iLang, $iPage );
00446             }
00447         } else {
00448             $sUrl = oxUBase::_addPageNrParam( $sUrl, $iPage, $iLang );
00449         }
00450         return $sUrl;
00451     }
00452 
00458     public function getAdditionalParams()
00459     {
00460         $sAddParams = oxUBase::getAdditionalParams();
00461 
00462         if ( $oRecomm = $this->getActiveRecommList() ) {
00463             $sAddParams .= "&amp;recommid=".$oRecomm->getId();
00464         }
00465 
00466         if ( $sSearch = $this->getRecommSearch() ) {
00467             $sAddParams .= "&amp;searchrecomm=". rawurlencode( $sSearch );
00468         }
00469 
00470         return $sAddParams;
00471     }
00472 
00480     public function getLink( $iLang = null )
00481     {
00482         if ( $oRecomm = $this->getActiveRecommList() ) {
00483             $sLink = $oRecomm->getLink( $iLang );
00484         } else {
00485             $sLink = oxUBase::getLink( $iLang );
00486         }
00487         $sSearch = oxConfig::getParameter( 'searchrecomm' );
00488         if ( $sSearch ) {
00489             $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "searchrecomm={$sSearch}";
00490         }
00491 
00492         return $sLink;
00493     }
00494 
00500     public function getBreadCrumb()
00501     {
00502         $aPaths = array();
00503         $aPath = array();
00504 
00505         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_RECOMMENDATIONS_PRODUCTS_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
00506         $aPath['link']  = $this->getLink();
00507         $aPaths[] = $aPath;
00508 
00509         return $aPaths;
00510     }
00511 }