Example #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;
 }