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 = oxConfig::getInstance();
00110
00111 $this->_iAllArtCnt = 0;
00112 $this->_aViewData['actvrecommlist'] = $this->getActiveRecommList();
00113 $this->_aViewData['itemList'] = $this->getActiveRecommItems();
00114
00115
00116 $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00117
00118
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
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 $sAdd = '';
00133 if ( $this->getRecommSearch() ) {
00134 $sAdd = "&searchrecomm=". rawurlencode( $this->getRecommSearch() );
00135 }
00136 $this->_sAdditionalParams .= "&recommid={$sOxid}" . $sAdd;
00137
00138 if (in_array('oxrss_recommlistarts', $myConfig->getConfigParam( 'aRssSelected' ))) {
00139 $oRss = oxNew('oxrssfeed');
00140 $this->addRssFeed($oRss->getRecommListArticlesTitle($oActiveRecommList), $oRss->getRecommListArticlesUrl($this->_oActiveRecommList), 'recommlistarts');
00141 }
00142
00143 } else {
00144 if ( ($oList = $this->getRecommLists()) && $oList->count() ) {
00145 $oRecommList = oxNew( 'oxrecommlist' );
00146 $this->_iAllArtCnt = $oRecommList->getSearchRecommListCount( $this->getRecommSearch() );
00147 }
00148
00149 $this->_sAdditionalParams .= "&searchrecomm=". rawurlencode( $this->getRecommSearch() );
00150 }
00151
00152 if ( !$oList = $this->getActiveRecommItems() ) {
00153 $oList = $this->getRecommLists();
00154 }
00155
00156 if ( $oList && $oList->count() ) {
00157 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00158 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00159 $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00160 }
00161
00162 $this->_aViewData['additionalparams'] = $this->getAdditionalParams();
00163
00164 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00165
00166 $this->_aViewData['template_location'] = $this->getTemplateLocation();
00167 $this->_aViewData['searchrecomm'] = $this->getRecommSearch();
00168 $this->_aViewData['searchrecommforhtml'] = $this->getSearchForHtml();
00169
00170 $this->_aViewData['loginformanchor'] = $this->getLoginFormAnchor();
00171
00172
00173 $this->_processListArticles();
00174
00175 return $this->_sThisTemplate;
00176 }
00177
00183 protected function _processListArticles()
00184 {
00185 $sAddParams = $this->getAddUrlParams();
00186 if ( $sAddParams && $this->_oActiveRecommItems ) {
00187 foreach ( $this->_oActiveRecommItems as $oArticle ) {
00188 $oArticle->appendLink( $sAddParams );
00189 }
00190 }
00191 }
00192
00198 public function getAddUrlParams()
00199 {
00200 $sAddParams = parent::getAddUrlParams();
00201 $sAddParams .= ($sAddParams?'&':'') . "listtype={$this->_sListType}";
00202
00203 if ( $sParam = rawurlencode( oxConfig::getParameter( 'searchrecomm', true ) ) ) {
00204 $sAddParams .= "&searchrecomm={$sParam}";
00205 }
00206
00207 if ( $oRecommList = $this->getActRecommList() ) {
00208 $sAddParams .= '&recommid='.$oRecommList->getId();
00209 }
00210
00211 return $sAddParams;
00212 }
00213
00219 public function saveReview()
00220 {
00221 $sReviewText = trim( ( string ) oxConfig::getParameter( 'rvw_txt' , true ) );
00222 $dRating = oxConfig::getParameter( 'recommlistrating' );
00223 if ($dRating < 0 || $dRating > 5) {
00224 $dRating = null;
00225 }
00226
00227 $sRLId = oxConfig::getParameter( 'recommid' );
00228 $sUserId = oxSession::getVar( 'usr' );
00229
00230 $oRecommList = oxNew('oxrecommlist');
00231 if (!$oRecommList->load($sRLId)) {
00232 return;
00233 }
00234
00235
00236 if ( $dRating ) {
00237 $oRating = oxNew( 'oxrating' );
00238 $blRate = $oRating->allowRating( $sUserId, 'oxrecommlist', $oRecommList->getId());
00239 if ( $blRate) {
00240 $oRating->oxratings__oxuserid = new oxField($sUserId);
00241 $oRating->oxratings__oxtype = new oxField('oxrecommlist', oxField::T_RAW);
00242 $oRating->oxratings__oxobjectid = new oxField($sRLId);
00243 $oRating->oxratings__oxrating = new oxField($dRating);
00244 $oRating->save();
00245 $oRecommList->addToRatingAverage( $dRating);
00246 } else {
00247 $dRating = null;
00248 }
00249 }
00250
00251 if ( $sReviewText ) {
00252 $oReview = oxNew( 'oxreview' );
00253 $oReview->oxreviews__oxobjectid = new oxField($sRLId);
00254 $oReview->oxreviews__oxtype = new oxField('oxrecommlist', oxField::T_RAW);
00255 $oReview->oxreviews__oxtext = new oxField($sReviewText, oxField::T_RAW);
00256 $oReview->oxreviews__oxlang = new oxField(oxLang::getInstance()->getBaseLanguage());
00257 $oReview->oxreviews__oxuserid = new oxField($sUserId);
00258 $oReview->oxreviews__oxrating = new oxField(( $dRating) ? $dRating : null);
00259 $oReview->save();
00260 }
00261 }
00262
00268 public function showLogin()
00269 {
00270 $this->_sThisTemplate = 'account_login.tpl';
00271 $this->_sLoginFormAnchor = "review";
00272 }
00273
00279 protected function _getNavigationParams()
00280 {
00281 $aParams = parent::_getNavigationParams();
00282 $aParams['recommid'] = oxConfig::getParameter( 'recommid' );
00283
00284 return $aParams;
00285 }
00286
00292 public function getActiveRecommList()
00293 {
00294 if ( $this->_oActiveRecommList === null ) {
00295 $this->_oActiveRecommList = false;
00296 if ( $sOxid = $this->getRecommId()) {
00297 $this->_oActiveRecommList = oxNew( 'oxrecommlist' );
00298 $this->_oActiveRecommList->load( $sOxid);
00299 }
00300 }
00301 return $this->_oActiveRecommList;
00302 }
00303
00309 public function getActiveRecommItems()
00310 {
00311 if ( $this->_oActiveRecommItems === null ) {
00312 $this->_oActiveRecommItems = false;
00313 if ( $oActiveRecommList = $this->getActiveRecommList()) {
00314
00315 $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00316 $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00317
00318
00319 $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00320 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00321
00322 $oList = $oActiveRecommList->getArticles($iNrofCatArticles * $iActPage, $iNrofCatArticles);
00323
00324 if ( $oList && $oList->count() ) {
00325 foreach ( $oList as $oItem) {
00326 $oItem->text = $oActiveRecommList->getArtDescription( $oItem->getId() );
00327 }
00328 $this->_oActiveRecommItems = $oList;
00329 }
00330 }
00331 }
00332 return $this->_oActiveRecommItems;
00333 }
00334
00340 public function getSimilarRecommLists()
00341 {
00342 if ( $this->_oOtherRecommList === null ) {
00343 $this->_oOtherRecommList = false;
00344 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00345 if ( $oList = $this->getActiveRecommItems() ) {
00346 $oRecommLists = $oActiveRecommList->getRecommListsByIds( $oList->arrayKeys());
00347
00348 unset($oRecommLists[$this->getRecommId()]);
00349 $this->_oOtherRecommList = $oRecommLists;
00350 }
00351 }
00352 }
00353 return $this->_oOtherRecommList;
00354 }
00355
00361 public function getRecommId()
00362 {
00363 if ( $this->_sRecommId === null ) {
00364 $this->_sRecommId = false;
00365 if ( $sOxid = oxConfig::getParameter( 'recommid' )) {
00366 $this->_sRecommId = $sOxid;
00367 }
00368 }
00369 return $this->_sRecommId;
00370 }
00371
00377 public function getReviews()
00378 {
00379 if ( $this->_aReviews === null ) {
00380 $this->_aReviews = false;
00381 if ( $this->isReviewActive() ) {
00382 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00383 $this->_aReviews = $oActiveRecommList->getReviews();
00384 }
00385 }
00386 }
00387 return $this->_aReviews;
00388 }
00389
00395 public function isReviewActive()
00396 {
00397 $myConfig = $this->getConfig();
00398 if ( $this->_blReviewActive === null ) {
00399 $this->_blReviewActive = false;
00400 if ( $myConfig->getConfigParam( 'bl_perfLoadReviews' ) ) {
00401 $this->_blReviewActive = true;
00402 }
00403 }
00404 return $this->_blReviewActive;
00405 }
00406
00412 public function canRate()
00413 {
00414 if ( $this->_blRate === null ) {
00415 $this->_blRate = false;
00416 if ( $this->isReviewActive() ) {
00417 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00418 $oRating = oxNew( 'oxrating' );
00419 $this->_blRate = $oRating->allowRating( oxSession::getVar( 'usr' ), 'oxrecommlist', $oActiveRecommList->getId());
00420 }
00421 }
00422 }
00423 return $this->_blRate;
00424 }
00425
00431 public function getRatingValue()
00432 {
00433 if ( $this->_dRatingValue === null ) {
00434 $this->_dRatingValue = false;
00435 if ( $this->isReviewActive() ) {
00436 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00437 $this->_dRatingValue = round( $oActiveRecommList->oxrecommlists__oxrating->value, 1);
00438 }
00439 }
00440 }
00441 return $this->_dRatingValue;
00442 }
00443
00449 public function getRatingCount()
00450 {
00451 if ( $this->_iRatingCnt === null ) {
00452 $this->_iRatingCnt = false;
00453 if ( $this->isReviewActive() ) {
00454 if ( $oActiveRecommList = $this->getActiveRecommList() ) {
00455 $this->_iRatingCnt = $oActiveRecommList->oxrecommlists__oxratingcnt->value;
00456 }
00457 }
00458 }
00459 return $this->_iRatingCnt;
00460 }
00461
00467 public function getRecommLists()
00468 {
00469 if ( $this->_oSearchRecommLists === null ) {
00470 $this->_oSearchRecommLists = array();
00471 if ( !$this->getRecommId()) {
00472 $sSearch = $this->getRecommSearch();
00473
00474 $oRecommList = oxNew( 'oxrecommlist' );
00475 $oList = $oRecommList->getSearchRecommLists( $sSearch );
00476 if ( $oList && $oList->count() ) {
00477 $this->_oSearchRecommLists = $oList;
00478 }
00479 }
00480 }
00481 return $this->_oSearchRecommLists;
00482 }
00483
00489 public function getRecommSearch()
00490 {
00491 if ( $this->_sSearch === null ) {
00492 $this->_sSearch = false;
00493 if ( $sSearch = oxConfig::getParameter( 'searchrecomm', true ) ) {
00494 $this->_sSearch = $sSearch;
00495 }
00496 }
00497 return $this->_sSearch;
00498 }
00499
00505 public function getTemplateLocation()
00506 {
00507 if ( $this->_sTplLocation === null ) {
00508 $this->_sTplLocation = false;
00509 if ( $sSearchparam = $this->getRecommSearch() ) {
00510 $sUrl = $this->getConfig()->getShopHomeURL();
00511 $sLink = "{$sUrl}cl=recommlist&searchrecomm=".rawurlencode( $sSearchparam );
00512 $sTitle = oxLang::getInstance()->translateString('RECOMMLIST');
00513 $sTitle .= " / ".oxLang::getInstance()->translateString('RECOMMLIST_SEARCH').' "'.$sSearchparam.'"';
00514 $this->_sTplLocation = "<a href='".$sLink."'>".$sTitle."</a>";
00515 } else {
00516 $this->_sTplLocation = oxLang::getInstance()->translateString('RECOMMLIST');
00517 }
00518 }
00519 return $this->_sTplLocation;
00520 }
00521
00527 public function getSearchForHtml()
00528 {
00529 return oxConfig::getParameter( 'searchrecomm' );
00530 }
00531
00537 public function getLoginFormAnchor()
00538 {
00539 return $this->_sLoginFormAnchor;
00540 }
00541
00547 public function getPageNavigation()
00548 {
00549 if ( $this->_oPageNavigation === null ) {
00550 $this->_oPageNavigation = false;
00551 $this->_oPageNavigation = $this->generatePageNavigation();
00552 }
00553 return $this->_oPageNavigation;
00554 }
00555
00556 }