Beispiel #1
0
 /**
  * Get banners content by specified banners IDs depend on Rotation mode
  *
  * @param array $bannerIds
  * @param array $segmentIds
  * @param int $storeId
  * @return array
  */
 protected function _getBannersContent($bannerIds, $segmentIds = array())
 {
     $bannersSequence = $content = array();
     if (!empty($bannerIds)) {
         //Choose rotation mode
         switch ($this->getRotate()) {
             case self::BANNER_WIDGET_RORATE_RANDOM:
                 $bannerId = $bannerIds[array_rand($bannerIds, 1)];
                 $_content = $this->_bannerResource->getStoreContent($bannerId, $this->_currentStoreId, $segmentIds);
                 if (!empty($_content)) {
                     $content[$bannerId] = $_content;
                 }
                 break;
             case self::BANNER_WIDGET_RORATE_SHUFFLE:
             case self::BANNER_WIDGET_RORATE_SERIES:
                 $bannerId = $bannerIds[0];
                 if (!$this->_sessionInstance->_getData($this->getUniqueId())) {
                     $this->_sessionInstance->setData($this->getUniqueId(), array($bannerIds[0]));
                 } else {
                     $bannersSequence = $this->_sessionInstance->_getData($this->getUniqueId());
                     $canShowIds = array_merge(array_diff($bannerIds, $bannersSequence), array());
                     if (!empty($canShowIds)) {
                         $showId = 0;
                         if ($this->getRotate() == self::BANNER_WIDGET_RORATE_SHUFFLE) {
                             $showId = array_rand($canShowIds, 1);
                         }
                         $bannersSequence[] = $canShowIds[$showId];
                         $bannerId = $canShowIds[$showId];
                     } else {
                         $bannersSequence = array($bannerIds[0]);
                     }
                     $this->_sessionInstance->setData($this->getUniqueId(), $bannersSequence);
                 }
                 $_content = $this->_bannerResource->getStoreContent($bannerId, $this->_currentStoreId, $segmentIds);
                 if (!empty($_content)) {
                     $content[$bannerId] = $_content;
                 }
                 break;
             default:
                 $content = $this->_bannerResource->getBannersContent($bannerIds, $this->_currentStoreId, $segmentIds);
                 break;
         }
     }
     return $content;
 }
 /**
  * Get banners content by specified banners IDs depend on Rotation mode
  *
  * @param array $bannerIds
  * @param array $segmentIds
  * @return array
  */
 protected function _getBannersContent($bannerIds, $segmentIds = array())
 {
     $this->_setRenderedParam('bannerIds', $bannerIds)->_setRenderedParam('renderedBannerIds', array());
     $content = array();
     if (!empty($bannerIds)) {
         $bannerResource = $this->_bannerResource;
         // Process suggested params
         $suggestedParams = $this->getSuggestedParams();
         $suggBannersSelected = $suggestedParams['bannersSelected'];
         $suggBannersSequence = $suggestedParams['bannersSequence'];
         // Choose banner depending on rotation mode
         switch ($this->getRotate()) {
             case self::BANNER_WIDGET_RORATE_RANDOM:
                 // Choose banner either as suggested or randomly
                 $bannerId = null;
                 if ($suggBannersSelected && count($suggBannersSelected) == 1) {
                     $suggBannerId = $suggBannersSelected[0];
                     if (array_search($suggBannerId, $bannerIds) !== false) {
                         $bannerId = $suggBannerId;
                     }
                 }
                 if ($bannerId === null) {
                     $bannerId = $bannerIds[array_rand($bannerIds, 1)];
                 }
                 $_content = $bannerResource->getStoreContent($bannerId, $this->_currentStoreId, $segmentIds);
                 if (!empty($_content)) {
                     $content[$bannerId] = $_content;
                 }
                 $this->_setRenderedParam('renderedBannerIds', array($bannerId));
                 break;
             case self::BANNER_WIDGET_RORATE_SHUFFLE:
             case self::BANNER_WIDGET_RORATE_SERIES:
                 $isShuffle = $this->getRotate() == self::BANNER_WIDGET_RORATE_SHUFFLE;
                 $bannerId = null;
                 $bannersSequence = null;
                 // Compose banner sequence either from suggested sequence or from user session data
                 if ($suggBannersSequence !== null) {
                     // Check that suggested sequence is valid - contains only banner ids from list
                     if (!array_diff($suggBannersSequence, $bannerIds)) {
                         $bannersSequence = $suggBannersSequence;
                     }
                 }
                 if ($bannersSequence === null) {
                     $bannersSequence = $this->_sessionInstance->_getData($this->getUniqueId());
                 }
                 // Check that we have suggested banner to render
                 $suggBannerId = null;
                 if ($suggBannersSelected && count($suggBannersSelected) == 1) {
                     $suggBannerId = $suggBannersSelected[0];
                 }
                 // If some banners were shown, get the list of unshown ones and choose banner to show
                 if ($bannersSequence) {
                     $canShowIds = array_merge(array_diff($bannerIds, $bannersSequence), array());
                     if (!empty($canShowIds)) {
                         // Stil not whole serie is shown, choose the banner to show
                         if ($suggBannerId && array_search($suggBannerId, $canShowIds) !== false) {
                             $bannerId = $suggBannerId;
                         } else {
                             $canShowKeys = array_keys($canShowIds);
                             $showKey = $isShuffle ? array_rand($canShowIds, 1) : $canShowKeys[0];
                             $bannerId = $canShowIds[$showKey];
                         }
                         $bannersSequence[] = $bannerId;
                     }
                 }
                 // Start new serie (either no banners has been shown at all or whole serie has been shown)
                 if (!$bannerId) {
                     if ($suggBannerId && array_search($suggBannerId, $bannerIds) !== false) {
                         $bannerId = $suggBannerId;
                     } else {
                         $bannerKeys = array_keys($bannerIds);
                         $bannerKey = $isShuffle ? array_rand($bannerIds, 1) : $bannerKeys[0];
                         $bannerId = $bannerIds[$bannerKey];
                     }
                     $bannersSequence = array($bannerId);
                 }
                 $this->_sessionInstance->setData($this->getUniqueId(), $bannersSequence);
                 $_content = $bannerResource->getStoreContent($bannerId, $this->_currentStoreId, $segmentIds);
                 if (!empty($_content)) {
                     $content[$bannerId] = $_content;
                 }
                 $this->_setRenderedParam('renderedBannerIds', array($bannerId))->_setRenderedParam('bannersSequence', $bannersSequence);
                 break;
             default:
                 // We must always render all available banners - so suggested values are ignored
                 $content = $bannerResource->getBannersContent($bannerIds, $this->_currentStoreId, $segmentIds);
                 $this->_setRenderedParam('renderedBannerIds', $bannerIds);
                 break;
         }
     }
     $this->_prepareCacheTags();
     return $content;
 }