/** * Lists all Blocks models. * @return mixed */ public function actionIndex() { $searchModel = new BlocksSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public function init() { parent::init(); unset(Yii::$app->view->params['blocks']); unset(Yii::$app->view->params['categoryColumn1']); unset(Yii::$app->view->params['categoryColumn2']); Yii::$app->view->params['blocks'] = BlocksSearch::find()->where(['active' => 1])->orderBy('sortOrder ASC')->all(); $allCategoryCounts = PostsSearch::find()->published()->count(); if (Yii::$app->params['showNullCategory']) { $categories = CategoriesSearch::find()->active()->orderBy('title ASC')->all(); } else { $categories = CategoriesSearch::find()->active()->innerJoin("{{%sources}}", "[[sources.categories_id]]=[[categories.id]]")->innerJoin("{{%posts}}", "[[posts.sources_id]] = [[sources.id]]")->orderBy('title ASC')->groupBy("[[categories.title]]")->all(); } if (is_array($categories)) { $i = 1; $halfCountCategories = ceil(count($categories) / 2); Yii::$app->view->params['categoryColumn1'][] = ['url' => '/', 'title' => Yii::t('app/categories', 'All Categories ({0})', [$allCategoryCounts])]; foreach ($categories as $category) { $countPostInCategory = $category->countPosts; $url = Yii::$app->request->get('category') != $category->slugUrl ? $category->url : NULL; $title = $category->title; if ($i <= $halfCountCategories) { Yii::$app->view->params['categoryColumn1'][] = ['url' => $url, 'title' => $title . " ({$countPostInCategory})"]; } else { Yii::$app->view->params['categoryColumn2'][] = ['url' => $url, 'title' => $title . " ({$countPostInCategory})"]; } $i++; } } }