main_view_auto.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. use app\models\front\News;
  3. /*
  4. $newsDataProvider = new \yii\data\ActiveDataProvider(
  5. [
  6. "query"=>\app\models\News::getMainView()->orderBy(["dt_pub"=>SORT_DESC])->limit(3),
  7. "pagination" =>[
  8. "pageSize"=>4
  9. ],
  10. ]
  11. );
  12. */
  13. $keyadd = News::keyFilter();
  14. $NHDataProvider = new \yii\data\ActiveDataProvider(
  15. [
  16. "query"=>News::getNH()->limit(1),
  17. "pagination" => false
  18. ]
  19. );
  20. $NH = $NHDataProvider->getModels();
  21. $newsDataProvider = new \yii\data\ActiveDataProvider(
  22. [
  23. "query"=>News::findFilter()->andWhere(["(flags & 1)"=>0])->andWhere(['<>', 'id', $NH[0]->id])->andWhere(['or',['NH'=>'Y'],['top'=>'Y']])->limit(3),
  24. "pagination" => false
  25. ]
  26. );
  27. $sort = $newsDataProvider->getModels();
  28. $news = new \yii\data\ActiveDataProvider();
  29. $models = [];
  30. if($NH[0] instanceof \app\models\front\News) $models[] = $NH[0] ;
  31. foreach( $sort as $item ){
  32. $model = News::findOne($item->id);
  33. if($model instanceof \app\models\front\News) $models[] = $model;
  34. }
  35. $news->setModels($models);
  36. echo \yii\helpers\Html::beginTag("div",["class"=>"main-view"]);
  37. echo Yii::$app->cache->getOrSet("main-page-main-view-$keyadd",function () use ($news){
  38. return \yii\widgets\ListView::widget([
  39. "dataProvider" => $news,
  40. 'options' => [
  41. 'tag' => false,
  42. 'class' => 'list-wrapper',
  43. 'id' => 'list-wrapper',
  44. ],
  45. "itemOptions"=>[
  46. "tag"=>false
  47. ],
  48. "itemView" => "_main_view_item",
  49. "layout" => "{items}"
  50. ]);
  51. },News::$keysCache['main-page-main-view']);
  52. echo \yii\helpers\Html::endTag("div");