three_widgets.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @var \yii\web\View $this
  4. * @var $post \app\models\News
  5. * @var \yii\data\ActiveDataProvider $newsDataProvider
  6. * @var \app\models\base\NewsTopic | \app\models\base\Story $topic
  7. */
  8. use app\models\News;
  9. $view = $this;
  10. echo \yii\helpers\Html::beginTag("div",["class"=>"partner-news row"]);
  11. echo Yii::$app->cache->getOrSet("main-page-third-row-l2",function () use ($newsDataProvider,$view){
  12. $result = "";
  13. $sliderItems = \app\models\front\TopSlider::find()
  14. ->andWhere(['<','published_from',date("Y-m-d H:i:s")])
  15. ->andWhere(['>','published_to',date("Y-m-d H:i:s")])
  16. ->andWhere(['is_active'=>1])->all();
  17. $k=0;
  18. foreach ($newsDataProvider->getModels() as $post)
  19. {
  20. if($k>=2 && count($sliderItems)>0) continue;
  21. $k++;
  22. $result.= $view->render('_partner_news_item',["model"=>$post,"key"=>$k]);
  23. }
  24. try {
  25. $result .= "<!-- slider -->\n";
  26. $result.= $view->render('_three_widgets_slider',['models'=>$sliderItems]);
  27. } catch (Exception $e) {
  28. // var_dump($e);
  29. }
  30. return $result;
  31. },60);
  32. echo \yii\helpers\Html::endTag("div");