Esempio n. 1
0
 public function actionIndex()
 {
     $lastPosts = Post::find()->orderBy('created_at desc')->limit(10)->all();
     $featured = Post::featured();
     $drafts = Post::drafts();
     $mostPopularCategory = Category::find()->joinWith('posts')->select('category.id, post.category_id, count(distinct post.title) as qty, category.title')->groupBy('post.category_id')->orderBy('qty desc')->one();
     $mostPopularTag = Tag::find()->joinWith('posts')->select('tags.id, posts_tags.tag_id, count(distinct posts_tags.post_id) as qty, tags.title')->groupBy('posts_tags.tag_id')->orderBy('qty desc')->one();
     $postsCount = Post::find()->where('active = 1')->count();
     $categoryCount = Category::find()->count();
     return $this->render('index', ['lastPosts' => $lastPosts, 'featured' => $featured, 'drafts' => $drafts, 'mostPopularCategory' => $mostPopularCategory, 'mostPopularTag' => $mostPopularTag, 'postsCount' => $postsCount, 'categoryCount' => $categoryCount]);
 }