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]); } }
public static function getActiveVotes() { $cacheKey = "activeVotes"; $allVotes = CacheHelper::get($cacheKey); if (false === $allVotes) { $allVotes = Vote::find()->active()->language()->order()->all(); CacheHelper::set($cacheKey, $allVotes, CacheHelper::getTag(Vote::className())); } return $allVotes; }
public function actionShow($id) { $vote = Vote::find()->language()->active()->where(['id' => $id])->one(); /** @var Vote $vote */ if (!$vote) { throw new NotFoundHttpException(Yii::t('f/vote', 'Request error')); } else { Yii::$app->params['skipRightVote'] = true; return $this->render('show', ['vote' => $vote, 'options' => $vote->voteOptions, 'isVoted' => true, 'maxPercent' => $vote->getMaxPercent()]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Vote::find(); $query->language(); $query->orderBy(['id' => SORT_DESC]); $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(['status' => $this->status]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }