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 function actionView($slug) { $news = News::find()->active()->language()->andWhere(['slug' => $slug])->one(); if (!$news) { throw new NotFoundHttpException(); } return $this->render('view', ['news' => $news]); }
public function run() { if (BackendAccessControl::checkPermissionAccess(UserController::BACKEND_PERMISSION)) { $news = News::find()->language()->orderBy(['date' => SORT_DESC])->limit($this->limit)->all(); if (count($news) > 0) { return $this->render('LastNews', ['news' => $news]); } } }
public function actionView($slug) { $category = NewsCategory::find()->active()->language()->andWhere(['slug' => $slug])->one(); if (!$category) { throw new NotFoundHttpException(); } $query = News::find()->active()->language()->category($category); $pages = new Pagination(['totalCount' => $query->count(), 'defaultPageSize' => Yii::t('f/news', 'defaultPageSize'), 'forcePageParam' => false]); $news = $query->order()->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('view', ['category' => $category, 'news' => $news, 'pages' => $pages]); }
public function actionView($name) { $tag = NewsTag::find()->language()->andWhere(['name' => $name])->one(); if (!$tag) { throw new NotFoundHttpException(); } $query = News::find()->active()->language()->tag($tag); $pages = new Pagination(['totalCount' => $query->count(), 'defaultPageSize' => Yii::t('f/news', 'defaultPageSize'), 'forcePageParam' => false]); $news = $query->order()->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('view', ['tag' => $tag, 'news' => $news, 'pages' => $pages]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); $query->language(); $query->order(); $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(['id' => $this->id, 'category_id' => $this->category_id, 'status' => $this->status]); list($from, $to) = FieldHelper::getDateFromRange($this->date); $query->andFilterWhere(['between', 'date', $from, $to]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Finds the News model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return News the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $model = News::find()->where(['id' => $id])->with('translations')->with('categories')->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }