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