Commit 9ca92883 authored by christian.zenker's avatar christian.zenker

simplified the logic in banner display:

	the displayed banners were stored in a user session to display different banners on
	every hit. But using caching/varnish this is rather useless.


git-svn-id: http://svn.t3o.typo3.org/extensions/projects/t3org/randombanners/trunk@1738 e8cb78a8-64f2-4011-8042-bd1ea5058d47
parent e8566430
...@@ -75,58 +75,8 @@ class Tx_Randombanners_Controller_BannerController extends Tx_Extbase_MVC_Contro ...@@ -75,58 +75,8 @@ class Tx_Randombanners_Controller_BannerController extends Tx_Extbase_MVC_Contro
public function listAction($numberOfBannersShown=0) { public function listAction($numberOfBannersShown=0) {
// initialization // initialization
$banners = $this->bannerRepository->findRandomBanners(); $banners = $this->bannerRepository->findRandomBanners();
$newBanners = array();
$saveIntoSession = array();
// get the last set of banners from session $this->view->assign('banners', $banners);
$lastBanners = $GLOBALS['TSFE']->fe_user->getKey('ses', 'tx_randombanners');
$numberOfBannersShown = ($numberOfBannersShown!==0?$numberOfBannersShown:$this->settings['numberOfBannersShown']);
if ($numberOfBannersShown == -1) {
// just show all banners
$newBanners = $banners;
} else {
// first round to get all banners not displayed the last time
foreach ($banners as $key => $banner) {
if (sizeof($newBanners) < $numberOfBannersShown) {
if (empty($lastBanners)) {
$newBanners[] = $banner;
} elseif (array_search($banner->getUid(), $lastBanners) === FALSE) {
$newBanners[] = $banner;
unset($banners[$key]);
}
} else {
break;
}
}
// second round to get some other banners if not enough banners in the list
foreach ($banners as $banner) {
if (sizeof($newBanners) < $numberOfBannersShown) {
$newBanners[] = $banner;
} else {
break;
}
}
}
foreach ($newBanners as $newBanner) {
if (!($newBanner->getLogo() instanceof Tx_Extbase_Domain_Model_Dam)) {
$newBanner->setLogo(Tx_ExtbaseDam_Utility_Dam::getOne('tx_randombanners_domain_model_banner', $newBanner->getUid(), 'tx_randombanner_dam_images'));
}
// get uids of all shown banners to save into session
$saveIntoSession[] = $newBanner->getUid();
// increment the displayed counter
$newBanner->setDisplayedThisMonth($newBanner->getDisplayedThisMonth() + 1);
}
// set array of uids into session
$GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_randombanners', $saveIntoSession);
$this->view->assign('banners', $newBanners);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment