topic_widget.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * @var integer $topic_id
  4. */
  5. $topic = \app\models\base\NewsTopic::findOne(["id"=>$topic_id]);
  6. $topic_picture = $topic->image;
  7. ?>
  8. <div class="row topic-widget">
  9. <div class="col-md-12">
  10. <div class="cont">
  11. <?php if($topic_picture instanceof \app\models\TopicImages):?>
  12. <picture class="w-100">
  13. <source srcset="<?=$topic_picture->url?>" media="(min-width: 600px)">
  14. <img src="<?=$topic_picture->url?>" alt="<?=$topic_picture->alt?>" class="w-100" loading="lazy">
  15. </picture>
  16. <?php endif;?>
  17. <div class="content">
  18. <div class="topic-title">
  19. <?=$topic->title?>
  20. </div>
  21. <div class="topic-news">
  22. <?php
  23. $newsDataProvider = new \yii\data\ActiveDataProvider(
  24. [
  25. "query"=>\app\models\News::find()->joinWith("topics t")->andWhere(["t.id"=>[$topic_id,]]),
  26. "pagination" =>[
  27. "pageSize"=>4
  28. ],
  29. ]
  30. );
  31. echo Yii::$app->cache->getOrSet("main-page-topic-widget-".$topic_id,function () use ($newsDataProvider){
  32. return \yii\widgets\ListView::widget([
  33. "dataProvider" => $newsDataProvider,
  34. 'options' => [
  35. 'tag' => false,
  36. 'class' => 'list-wrapper',
  37. 'id' => 'list-wrapper',
  38. ],
  39. "itemOptions"=>[
  40. "tag"=>false
  41. ],
  42. "itemView" => "_topic_widget_item",
  43. "layout" => "{items}"
  44. ]);
  45. },1);
  46. ?>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>