Example #1
0
 public function getBannerPlace()
 {
     if ($this->_bannerPlace != null) {
         return $this->_bannerPlace;
     }
     $this->_bannerPlace = BannerPlace::model()->findByPk($this->idBannerPlace);
     return $this->_bannerPlace;
 }
Example #2
0
 public function deactivate(Plugin $plugin)
 {
     $data = $plugin->getData();
     if ($data === null || !isset($data['id_site_module'])) {
         throw new ErrorException('Плагин установлен неверно.');
     }
     $siteModule = SiteModule::model()->findByPk($data['id_site_module']);
     $idBannerPlace = $siteModule->phpScriptInstance->getParameterValue('idBannerPlace');
     if (is_numeric($idBannerPlace) && ($bp = BannerPlace::model()->findByPk($idBannerPlace)) != null) {
         if (count($bp->banners) == 0) {
             $bp->delete();
         }
     }
     $data = $this->deleteSiteModule($data['id_site_module'], $data, 'site_module_place');
     unset($data['id_site_module']);
     $plugin->setData($data);
 }
Example #3
0
 public function actionIndex()
 {
     $bannerPlacesInfo = Yii::app()->request->getQuery('bp', array());
     if ($bannerPlacesInfo === array()) {
         echo CJSON::encode(array());
         Yii::app()->end();
         //throw new CHttpException('400', 'Invalid request. Please do not repeat this request again.');
     }
     $filteredBannerPlacesInfo = array();
     $ids = array();
     $bannersWidgetsPath = Yii::app()->getModule('banners')->bannersWidgetsPath;
     $widgetsPath = Yii::getPathOfAlias($bannersWidgetsPath) . DIRECTORY_SEPARATOR;
     $countBannerPlacesInfo = count($bannerPlacesInfo);
     for ($i = 0; $i < $countBannerPlacesInfo; $i++) {
         if (!isset($bannerPlacesInfo[$i]['id'], $bannerPlacesInfo[$i]['cls'])) {
             continue;
         }
         //получаем ИД баннерного места и класс виджета, который отвечает за его отрисовку
         //если файл класса не найден, то пропускаем это баннерное место
         $curBannerPlaceId = $bannerPlacesInfo[$i]['id'];
         $curBannerPlaceWidgetClass = $bannerPlacesInfo[$i]['cls'];
         if (!file_exists($widgetsPath . $curBannerPlaceWidgetClass . '.php')) {
             Yii::log('Файл "' . $widgetsPath . $curBannerPlaceWidgetClass . '.php' . '" не найден.', CLogger::LEVEL_WARNING, 'application.modules.banners');
             continue;
         }
         //если файл класса найден, то кладем его в массив
         $filteredBannerPlacesInfo[] = array('id' => $curBannerPlaceId, 'widget' => $bannersWidgetsPath . '.' . $curBannerPlaceWidgetClass);
         $ids[] = $curBannerPlaceId;
     }
     //сюда будем собирать код для отрисовки баннерных мест
     $placesReplaceCode = array();
     if (!empty($ids)) {
         $bannerPlaces = BannerPlace::model()->findAllByPk($ids, array('index' => 'id_banner_place'));
         $countFiltered = count($filteredBannerPlacesInfo);
         for ($i = 0; $i < $countFiltered; $i++) {
             $curBannerPlaceId = $filteredBannerPlacesInfo[$i]['id'];
             $curBannerPlaceWidget = $filteredBannerPlacesInfo[$i]['widget'];
             if (!isset($bannerPlaces[$curBannerPlaceId])) {
                 continue;
             }
             //модель текущего обрабатываемого баннерного места
             $bannerPlace = $bannerPlaces[$curBannerPlaceId];
             //получаем все баннеры для данного баннерного места
             $banners = Banner::model()->with('bannerFile')->findAll(array('condition' => 't.id_banner_place = :idPlace', 'order' => 'sequence ASC', 'params' => array(':idPlace' => $curBannerPlaceId)));
             //если баннеров нет, то пропускаем это баннерное место
             $countBanners = count($banners);
             if ($countBanners == 0) {
                 continue;
             }
             $bannersToShow = array();
             $indexBannerToShow = -1;
             if ($bannerPlace->showing == BannerPlace::ST_BY_ORDER || $bannerPlace->showing == BannerPlace::ST_RANDOM) {
                 while (true) {
                     //Если баннеры выводятся в определенном порядке
                     if ($bannerPlace->showing == BannerPlace::ST_BY_ORDER) {
                         $indexBannerToShow++;
                         //Если баннеры отображаются рандомно
                     } else {
                         $indexBannerToShow = rand(0, $countBanners - 1);
                     }
                     $curBanner = $banners[$indexBannerToShow];
                     if (!$this->bannerWasShown($curBanner, $countBanners)) {
                         $bannersToShow = array($curBanner);
                         break;
                     }
                 }
                 //вывод всех баннеров
             } else {
                 $bannersToShow = $banners;
                 // TODO Добавить ограничение на количество выводимых баннеров в данном месте
                 /*
                 for ($k = 0; $k < $countBanners; $k++) {
                   $curBanner = $banners[$k];
                   $bannersToShow[] = $curBanner;
                 }
                 */
             }
             if (!empty($bannersToShow)) {
                 $idCont = Yii::app()->getModule('banners')->getBannerReplaceContainerId($curBannerPlaceId);
                 //получаем html-код для баннерных мест и html-код баннеров
                 $bannersCode = array();
                 ob_start();
                 $widget = $this->widget($curBannerPlaceWidget, array('banners' => $bannersToShow));
                 $code = ob_get_clean();
                 //сюда заносим html-код для замены по интервалу таймера
                 $bannersCode = $widget->getBannerReplacementCode();
                 $placesReplaceCode[] = array('id' => $idCont, 'code' => $code, 'banners' => $bannersCode);
             }
         }
     }
     echo CJSON::encode($placesReplaceCode);
 }