public function run()
 {
     $bannerPlace = BannerPlace::findOne($this->place);
     if ($bannerPlace) {
         $banners = Banner::find()->active()->language()->with('stat')->all();
         if (!empty($banners)) {
             $bannersSum = 0;
             foreach ($banners as $banner) {
                 $bannersSum += $banner->priority;
             }
             if ($bannersSum > 0) {
                 $bannersRandNum = mt_rand(1, $bannersSum);
                 foreach ($banners as $banner) {
                     if ($banner->priority > 0) {
                         $data = $banner;
                         $bannersRandNum = $bannersRandNum - $banner->priority;
                         if ($bannersRandNum <= 0) {
                             break;
                         }
                     }
                 }
             } else {
                 $data = $banners[array_rand($banners)];
             }
             /** @var $data Banner */
             if (isset($data)) {
                 $data->addView();
                 return $this->render('BannerPlace', ['data' => $data]);
             } else {
                 return '';
             }
         }
     }
 }
 public function run()
 {
     $bars = [];
     if (BackendAccessControl::checkPermissionAccess(UserController::BACKEND_PERMISSION)) {
         $usersCount = User::find()->where(['status' => User::STATUS_ACTIVE])->count();
         $bars[] = ['bgClass' => 'bg-blue', 'label' => Yii::t('b/radiata/common', 'Total users'), 'data' => $usersCount, 'icon' => 'fa-user', 'url' => Url::to(['user/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(NewsController::BACKEND_PERMISSION)) {
         $newsCount = News::find()->count();
         $bars[] = ['bgClass' => 'bg-olive', 'label' => Yii::t('b/news', 'Total news'), 'data' => $newsCount, 'icon' => 'fa-bars', 'url' => Url::to(['/news/news/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(VoteController::BACKEND_PERMISSION)) {
         $newsCount = Vote::find()->count();
         $bars[] = ['bgClass' => 'bg-aqua', 'label' => Yii::t('b/vote', 'Total votes'), 'data' => $newsCount, 'icon' => 'fa-question-circle', 'url' => Url::to(['/vote/vote/index'])];
     }
     if (BackendAccessControl::checkPermissionAccess(BannerController::BACKEND_PERMISSION)) {
         $newsCount = Banner::find()->count();
         $bars[] = ['bgClass' => 'bg-maroon', 'label' => Yii::t('b/banner', 'Total banners'), 'data' => $newsCount, 'icon' => 'fa-flag', 'url' => Url::to(['/vote/vote/index'])];
     }
     if (BackendAccessControl::checkRoleAccess('developer')) {
         $migrator = new Migrator();
         $migrations = $migrator->findNewMigrations();
         if (count($migrations) > 0) {
             $bars[] = ['bgClass' => 'bg-gold', 'label' => Yii::t('b/radiata/common', 'New migrations'), 'data' => count($migrations), 'icon' => 'fa-database', 'url' => Url::to(['radiata/apply-migrations']), 'more' => Yii::t('b/radiata/common', 'Apply migrations')];
         }
     }
     if (count($bars) > 0) {
         return $this->render('SiteStatsBars', ['bars' => $bars]);
     }
 }
Example #3
0
 public function actionClick($id)
 {
     $banner = Banner::find()->language()->active()->where(['id' => $id])->with('stat')->one();
     if ($banner && $banner->link) {
         $banner->addClick();
         return $this->redirect($banner->link);
     } else {
         throw new Exception('Banner not found!');
     }
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Banner::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['place_id' => $this->place_id, 'status' => $this->status, 'locale' => $this->locale]);
     $query->andFilterWhere(['>=', 'date_start', $this->date_start ? strtotime($this->date_start) : '']);
     $query->andFilterWhere(['<=', 'date_end', $this->date_end ? strtotime($this->date_end) : '']);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }