/** * Get block with top 6 news * @return array Data */ public static function getTop6News($cache = true) { if ($cache) { $cacheBlock = CacheBlock::find()->where(['machine_name' => 'top6News'])->one(); if (isset($cacheBlock)) { return ['view' => '@frontend/views/blocks/cache_block', 'data' => ['content' => $cacheBlock->content]]; } } $postTable = Post::tableName(); $assetTable = Asset::tableName(); // TOP 6 $query = Post::find()->innerJoin($assetTable, "{$assetTable}.assetable_id = {$postTable}.id")->where(['is_public' => 1, 'is_top' => 1, 'content_category_id' => Post::CATEGORY_NEWS, "{$assetTable}.assetable_type" => Asset::ASSETABLE_POST, "{$assetTable}.thumbnail" => Asset::THUMBNAIL_NEWS]); $top6News = $query->andWhere(['not in', "{$postTable}.id", self::$postExcludeIds])->orderBy(['created_at' => SORT_DESC])->limit(6)->all(); foreach ($top6News as $post) { self::$postExcludeIds[] = $post->id; } $block = ['view' => '@frontend/views/blocks/main_news_block', 'data' => ['top6News' => $top6News]]; if (!$cache) { $view = new \yii\base\View(); return $view->renderFile($block['view'] . '.php', $block['data']); } return $block; }