recommlist.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class RecommList extends oxUBase
00009 {
00014     protected $_sListType = 'recommlist';
00015 
00020     protected $_sThisTemplate = 'recommlist.tpl';
00021 
00026     protected $_sRecommId = null;
00027 
00032     protected $_oActiveRecommList = null;
00033 
00038     protected $_oActiveRecommItems = null;
00039 
00044     protected $_oOtherRecommList = null;
00045 
00050     protected $_aReviews = null;
00051 
00056     protected $_blReviewActive = null;
00057 
00062     protected $_blRate = null;
00063 
00068     protected $_dRatingValue = null;
00069 
00074     protected $_iRatingCnt = null;
00075 
00080     protected $_oSearchRecommLists = null;
00081 
00086     protected $_sSearch = null;
00087 
00093     protected $_sTplLocation = null;
00094 
00099     protected $_oPageNavigation = null;
00100 
00106     public function render()
00107     {
00108         parent::render();
00109         $myConfig = $this->getConfig();
00110 
00111         $this->_iAllArtCnt = 0;
00112         $this->_aViewData['actvrecommlist'] = $this->getActiveRecommList();
00113         $this->_aViewData['itemList'] = $this->getActiveRecommItems();
00114 
00115         // loading other recommlists
00116         $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00117 
00118         // Loads rating parameters
00119         $this->_aViewData['rate']      = $this->canRate();
00120         $this->_aViewData['rating']    = $this->getRatingValue();
00121         $this->_aViewData['ratingcnt'] = $this->getRatingCount();
00122         $this->_aViewData['reviews']   = $this->getReviews();
00123 
00124         // list of found oxrecommlists
00125         $this->_aViewData['recommlists'] = $this->getRecommLists();
00126         if ( $sOxid = $this->getRecommId()) {
00127             $oActiveRecommList = $this->getActiveRecommList();
00128             $oList = $this->getActiveRecommItems();
00129             if ( $oList && $oList->count()) {
00130                     $this->_iAllArtCnt = $oActiveRecommList->getArtCount();
00131             }
00132 
00133             if (in_array('oxrss_recommlistarts', $myConfig->getConfigParam( 'aRssSelected' ))) {
00134                 $oRss = oxNew('oxrssfeed');
00135                 $this->addRssFeed($oRss->getRecommListArticlesTitle($oActiveRecommList), $oRss->getRecommListArticlesUrl($this->_oActiveRecommList), 'recommlistarts');
00136             }
00137 
00138         } else {
00139             if ( ($oList = $this->getRecommLists()) && $oList->count() ) {
00140                 $oRecommList = oxNew( 'oxrecommlist' );
00141                 $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount( $this->getRecommSearch() );
00142             }
00143         }
00144 
00145         if ( !$oList = $this->getActiveRecommItems() ) {
00146             $oList = $this->getRecommLists();
00147         }
00148 
00149         if ( $oList && $oList->count() ) {
00150             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00151             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00152             $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00153         }
00154 
00155         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00156         $this->_aViewData['template_location']   = $this->getTemplateLocation();
00157         $this->_aViewData['searchrecomm']        = $this->getRecommSearch();
00158         $this->_aViewData['searchrecommforhtml'] = $this->getSearchForHtml();
00159 
00160         $this->_aViewData['loginformanchor'] = $this->getLoginFormAnchor();
00161 
00162         // processing list articles
00163         $this->_processListArticles();
00164 
00165         return $this->_sThisTemplate;
00166     }
00167 
00173     protected function _processListArticles()
00174     {
00175         $sAddParams = $this->getAddUrlParams();
00176         if ( $sAddParams && $this->_oActiveRecommItems ) {
00177             foreach ( $this->_oActiveRecommItems as $oArticle ) {
00178                 $oArticle->appendLink( $sAddParams );
00179             }
00180         }
00181     }
00182 
00188     public function getAddUrlParams()
00189     {
00190         $sAddParams  = parent::getAddUrlParams();
00191         $sAddParams .= ($sAddParams?'&amp;':'') . "listtype={$this->_sListType}";
00192 
00193         if ( $sParam = rawurlencode( oxConfig::getParameter( 'searchrecomm', true ) ) ) {
00194             $sAddParams .= "&amp;searchrecomm={$sParam}";
00195         }
00196 
00197         if ( $oRecommList = $this->getActRecommList() ) {
00198             $sAddParams .= '&amp;recommid='.$oRecommList->getId();
00199         }
00200 
00201         return $sAddParams;
00202     }
00203 
00209     public function saveReview()
00210     {
00211         $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt' , true ) );
00212         $dRating     = oxConfig::getParameter( 'recommlistrating' );
00213         if ( $dRating < 0 || $dRating > 5 ) {
00214             $dRating = null;
00215         }
00216 
00217         $sRLId  = oxConfig::getParameter( 'recommid' );
00218         $sUserId = oxSession::getVar( 'usr' );
00219 
00220         $oRecommList = oxNew('oxrecommlist');
00221         if (!$oRecommList->load($sRLId)) {
00222             return;
00223         }
00224 
00225         //save rating
00226         if ( $dRating ) {
00227             $oRating = oxNew( 'oxrating' );
00228             $blRate = $oRating->allowRating( $sUserId, 'oxrecommlist', $oRecommList->getId());
00229             if ( $blRate) {
00230                 $oRating->oxratings__oxuserid   = new oxField($sUserId);
00231                 $oRating->oxratings__oxtype     = new oxField('oxrecommlist', oxField::T_RAW);
00232                 $oRating->oxratings__oxobjectid = new oxField($sRLId);
00233                 $oRating->oxratings__oxrating   = new oxField($dRating);
00234                 $oRating->save();
00235                 $oRecommList->addToRatingAverage( $dRating);
00236             } else {
00237                 $dRating = null;
00238             }
00239         }
00240 
00241         if ( $sReviewText ) {
00242             $oReview = oxNew( 'oxreview' );
00243             $oReview->oxreviews__oxobjectid = new oxField($sRLId);
00244             $oReview->oxreviews__oxtype     = new oxField('oxrecommlist', oxField::T_RAW);
00245             $oReview->oxreviews__oxtext     = new oxField($sReviewText, oxField::T_RAW);
00246             $oReview->oxreviews__oxlang     = new oxField(oxLang::getInstance()->getBaseLanguage());
00247             $oReview->oxreviews__oxuserid   = new oxField($sUserId);
00248             $oReview->oxreviews__oxrating   = new oxField(( $dRating) ? $dRating : null);
00249             $oReview->save();
00250         }
00251     }
00252 
00258     public function showLogin()
00259     {
00260         $this->_sThisTemplate = 'account_login.tpl';
00261         $this->_sLoginFormAnchor = "review";
00262     }
00263 
00269     public function getNavigationParams()
00270     {
00271         $aParams = parent::getNavigationParams();
00272         $aParams['recommid'] = oxConfig::getParameter( 'recommid' );
00273 
00274         return $aParams;
00275     }
00276 
00282     public function getActiveRecommList()
00283     {
00284         if ( $this->_oActiveRecommList === null ) {
00285             $this->_oActiveRecommList = false;
00286             if ( $sOxid = $this->getRecommId()) {
00287                 $this->_oActiveRecommList = oxNew( 'oxrecommlist' );
00288                 $this->_oActiveRecommList->load( $sOxid);
00289             }
00290         }
00291         return $this->_oActiveRecommList;
00292     }
00293 
00299     public function getActiveRecommItems()
00300     {
00301         if ( $this->_oActiveRecommItems === null ) {
00302             $this->_oActiveRecommItems = false;
00303             if ( $oActiveRecommList = $this->getActiveRecommList()) {
00304                 // sets active page
00305                 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00306                 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00307 
00308                 // load only lists which we show on screen
00309                 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00310                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00311 
00312                 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00313 
00314                 if ( $oList && $oList->count() ) {
00315                     foreach ( $oList as $oItem) {
00316                         $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00317                     }
00318                     $this->_oActiveRecommItems = $oList;
00319                 }
00320             }
00321         }
00322         return $this->_oActiveRecommItems;
00323     }
00324 
00330     public function getSimilarRecommLists()
00331     {
00332         if ( $this->_oOtherRecommList === null ) {
00333             $this->_oOtherRecommList = false;
00334             if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00335                 if ( $oList = $this->getActiveRecommItems() ) {
00336                     $oRecommLists  = $oActiveRecommList->getRecommListsByIds( $oList->arrayKeys());
00337                     //do not show the same list
00338                     unset($oRecommLists[$this->getRecommId()]);
00339                     $this->_oOtherRecommList = $oRecommLists;
00340                 }
00341             }
00342         }
00343         return $this->_oOtherRecommList;
00344     }
00345 
00351     public function getRecommId()
00352     {
00353         if ( $this->_sRecommId === null ) {
00354             $this->_sRecommId = false;
00355             if ( $sOxid = oxConfig::getParameter( 'recommid' )) {
00356                 $this->_sRecommId = $sOxid;
00357             }
00358         }
00359         return $this->_sRecommId;
00360     }
00361 
00367     public function getReviews()
00368     {
00369         if ( $this->_aReviews === null ) {
00370             $this->_aReviews = false;
00371             if ( $this->isReviewActive() ) {
00372                 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00373                     $this->_aReviews = $oActiveRecommList->getReviews();
00374                 }
00375             }
00376         }
00377         return $this->_aReviews;
00378     }
00379 
00385     public function isReviewActive()
00386     {
00387         $myConfig  = $this->getConfig();
00388         if ( $this->_blReviewActive === null ) {
00389             $this->_blReviewActive = false;
00390             if ( $myConfig->getConfigParam( 'bl_perfLoadReviews' ) ) {
00391                 $this->_blReviewActive = true;
00392             }
00393         }
00394         return $this->_blReviewActive;
00395     }
00396 
00402     public function canRate()
00403     {
00404         if ( $this->_blRate === null ) {
00405             $this->_blRate = false;
00406             if ( $this->isReviewActive() ) {
00407                 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00408                     $oRating = oxNew( 'oxrating' );
00409                     $this->_blRate = $oRating->allowRating( oxSession::getVar( 'usr' ), 'oxrecommlist', $oActiveRecommList->getId());
00410                 }
00411             }
00412         }
00413         return $this->_blRate;
00414     }
00415 
00421     public function getRatingValue()
00422     {
00423         if ( $this->_dRatingValue === null ) {
00424             $this->_dRatingValue = false;
00425             if ( $this->isReviewActive() ) {
00426                 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00427                     $this->_dRatingValue = round( $oActiveRecommList->oxrecommlists__oxrating->value, 1);
00428                 }
00429             }
00430         }
00431         return $this->_dRatingValue;
00432     }
00433 
00439     public function getRatingCount()
00440     {
00441         if ( $this->_iRatingCnt === null ) {
00442             $this->_iRatingCnt = false;
00443             if ( $this->isReviewActive() ) {
00444                 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00445                     $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
00446                 }
00447             }
00448         }
00449         return $this->_iRatingCnt;
00450     }
00451 
00457     public function getRecommLists()
00458     {
00459         if ( $this->_oSearchRecommLists === null ) {
00460             $this->_oSearchRecommLists = array();
00461             if ( !$this->getRecommId()) {
00462                 $sSearch = $this->getRecommSearch();
00463                 // list of found oxrecommlists
00464                 $oRecommList = oxNew( 'oxrecommlist' );
00465                 $oList = $oRecommList->getSearchRecommLists( $sSearch );
00466                 if ( $oList && $oList->count() ) {
00467                     $this->_oSearchRecommLists = $oList;
00468                 }
00469             }
00470         }
00471         return $this->_oSearchRecommLists;
00472     }
00473 
00479     public function getRecommSearch()
00480     {
00481         if ( $this->_sSearch === null ) {
00482             $this->_sSearch = false;
00483             if ( $sSearch = oxConfig::getParameter( 'searchrecomm', true ) ) {
00484                 $this->_sSearch = $sSearch;
00485             }
00486         }
00487         return $this->_sSearch;
00488     }
00489 
00495     public function getTemplateLocation()
00496     {
00497         if ( $this->_sTplLocation === null ) {
00498             $this->_sTplLocation = false;
00499             $oLang = oxLang::getInstance();
00500             if ( $sSearchparam = $this->getRecommSearch() ) {
00501                 $sUrl = $this->getConfig()->getShopHomeURL();
00502                 $sLink = "{$sUrl}cl=recommlist&amp;searchrecomm=".rawurlencode( $sSearchparam );
00503                 $sTitle = $oLang->translateString('RECOMMLIST');
00504                 $sTitle .= " / ".$oLang->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
00505                 $this->_sTplLocation = "<a href='".$sLink."'>".$sTitle."</a>";
00506             } else {
00507                 $this->_sTplLocation = $oLang->translateString('RECOMMLIST');
00508             }
00509         }
00510         return $this->_sTplLocation;
00511     }
00512 
00518     public function getSearchForHtml()
00519     {
00520         return oxConfig::getParameter( 'searchrecomm' );
00521     }
00522 
00528     public function getLoginFormAnchor()
00529     {
00530         return $this->_sLoginFormAnchor;
00531     }
00532 
00538     public function getPageNavigation()
00539     {
00540         if ( $this->_oPageNavigation === null ) {
00541             $this->_oPageNavigation = false;
00542             $this->_oPageNavigation = $this->generatePageNavigation();
00543         }
00544         return $this->_oPageNavigation;
00545     }
00546 
00552     public function getAdditionalParams()
00553     {
00554         $sAddParams = parent::getAdditionalParams();
00555 
00556         if ( $sOxid = $this->getRecommId() ) {
00557             $sAddParams .= "&amp;recommid={$sOxid}";
00558         }
00559 
00560         if ( $sSearch = $this->getRecommSearch() ) {
00561             $sAddParams .= "&amp;searchrecomm=". rawurlencode( $sSearch );
00562         }
00563 
00564         return $sAddParams;
00565     }
00566 }

Generated on Wed Apr 22 12:26:32 2009 for OXID eShop CE by  doxygen 1.5.5