<?php

use app\models\front\News;
use yii\data\ActiveDataProvider;
$items = (isset($items) && $items > 0)?$items:50;

if( isset($topic) && $topic ){
$news_query = \app\models\front\News::find()->leftJoin('news_topic_relation t', 't.news_id = id')->andWhere(['t.topic_id'=>$topic]);

$newsDataProvider = new ActiveDataProvider([
    "query"=>$news_query,
    'sort'=> [
        'defaultOrder' => ['dt_pub' => SORT_DESC],
    ],
    "pagination" =>[
        "pageSize"=>$items
    ],
]);
?>
<a class="news-link" href="/news">Лента новостей</a>
<div class="lenta">
    <?= Yii::$app->cache->getOrSet("topics_page_lenta_".$topic,function () use ($newsDataProvider){
        return \yii\widgets\ListView::widget([
            "dataProvider"=>$newsDataProvider,
            'options' => [
                'tag' => 'div',
                'class' => 'list-wrapper',
                'id' => 'list-wrapper',
            ],
            "layout" => "{items}",
            "itemView"=> "/layouts/lenta/_item"
        ]);
    },120);

    ?>
    <div class="all-news">
        <a href="/news">Все новости</a>
    </div>
</div>
<?
}
