index.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /** @var yii\web\View $this */
  3. /** @var \yii\data\ActiveDataProvider $newsDataProvider */
  4. use app\models\Design;
  5. use app\modules\ldjson\jsonLD;
  6. use app\models\front\News;
  7. jsonLD::addAmicORG();
  8. jsonLD::$ld = jsonLD::$wp;
  9. Yii::$app->og->title = 'Новости Барнаула и Алтайского края — на сайте amic.ru ИА Амител';
  10. Yii::$app->og->og_title = Yii::$app->og->title;
  11. Yii::$app->og->canonical = '/';
  12. Yii::$app->og->og_description = 'Новости в Барнауле и Алтайском крае: оперативно репортажи с фото и видео. Интересные темы, эксперты, ответы на вопросы, тесты, игры.';
  13. Yii::$app->og->og_url = 'https://www.amic.ru';
  14. Yii::$app->og->og_type = 'website';
  15. Yii::$app->og->og_image = 'https://www.amic.ru/img/amic-logo.svg';
  16. $auto_news = Yii::$app->cache->get('main_auto_news');
  17. ?>
  18. <div class="site-index">
  19. <div class="row">
  20. <div class="col-md-8 " id="main-view-container">
  21. <?
  22. $keyadd = News::keyFilter();
  23. if ($this->beginCache('main-page-main-view-glob'.$keyadd, ['duration' => News::$keysCache['main-page-main-view-glob']])) {
  24. if( $auto_news || $keyadd){
  25. echo $this->render("index/main_view_slider",['auto'=>true]);
  26. }else{
  27. echo $this->render("index/main_view_slider",['auto'=>false]);
  28. }
  29. $this->endCache();
  30. }
  31. ?>
  32. </div>
  33. <script>
  34. (function (){
  35. let main_view_cont = document.getElementById('main-view-container');
  36. let height = main_view_cont.offsetHeight;
  37. console.log(height)
  38. let style = document.createElement("style");
  39. style.innerHTML = "#lenta-container{ max-height:"+height+"px;}";
  40. main_view_cont.parentNode.append(style);
  41. })()
  42. </script>
  43. <div class="col-md-4" id="lenta-wrapper">
  44. <div id="lenta-container">
  45. <?=$this->render("/layouts/lenta/lenta")?>
  46. </div>
  47. </div>
  48. </div>
  49. <?//$this->render("index/colorful_widget",['design'=>new Design(['id'=>1]),'newsDataProvider'=>new \yii\data\ActiveDataProvider(["query"=>News::find()])])?>
  50. <?
  51. if ($this->beginCache('MainPageBlock_' . ((Yii::$app->deviceDetect->isMobile())?"mobile":"desktop"), ['duration' => News::$keysCache['MainPageBlock']])) { //News::$keysCache['MainPageBlock']
  52. if( $auto_news ){
  53. $q = News::find()->andWhere(["(flags & 1)"=>0])->andWhere(['<>', 'id', News::getNH()->select('id')->limit(1)])->andWhere(['or',['NH'=>'Y'],['top'=>'Y']])->limit(3)->offset(3);
  54. }else{
  55. $q = \app\models\Kd::find()->andWhere(['>','order',2])->orderBy(["order"=>SORT_ASC])->limit(3);
  56. }
  57. $newsDataProvider = new \yii\data\ActiveDataProvider(
  58. [
  59. "query"=>$q,
  60. "pagination" => false
  61. ]
  62. );
  63. $sort = $newsDataProvider->getModels();
  64. $ActiveNews = new \yii\data\ActiveDataProvider();
  65. $models = [];
  66. foreach( $sort as $item ){
  67. $models[] = \app\models\News::findOne($item->id);
  68. }
  69. $ActiveNews->setModels($models);
  70. ?>
  71. <?=$this->render("index/three_widgets",['newsDataProvider'=>$ActiveNews])?>
  72. <?php
  73. $i = 0;
  74. $design = Design::find()->andWhere(['active'=>'Y'])->orderBy(['order'=>SORT_ASC])->all();
  75. foreach ($design as $item) {
  76. $i++;
  77. echo "<!-- item-{$i} -->";
  78. if($i==3) echo $this->render('@app/views/_etc/banners/firstDesktopTransparant');
  79. if($i==6 && Yii::$app->deviceDetect->isMobile()) echo $this->render('@app/views/_etc/banners/bannerMobile3');
  80. if($i==6 && !Yii::$app->deviceDetect->isMobile()) echo $this->render('@app/views/_etc/banners/bannerDesktop3');
  81. if($i==8 && !Yii::$app->deviceDetect->isMobile()) echo $this->render('@app/views/_etc/banners/bannerDesktop4');
  82. /**
  83. * @var $item Design
  84. */
  85. switch ($item->design)
  86. {
  87. case Design::TOPIC_WIDGET:
  88. $pageSize = 10;
  89. break;
  90. case Design::IMAGINE_NEWS_WIDGET:
  91. $pageSize = 3;
  92. break;
  93. default:
  94. $pageSize = 4;
  95. }
  96. switch ($item->type)
  97. {
  98. case "topic":
  99. $newsDataProvider = new \yii\data\ActiveDataProvider(
  100. [
  101. "query"=>News::find()->joinWith("topics t")->andWhere(["t.id"=>[$item->parent_id], "(flags & 1)"=>0]),
  102. "pagination" =>[
  103. "pageSize"=>$pageSize
  104. ],
  105. ]
  106. );
  107. $topic = \app\models\base\NewsTopic::findOne(['id'=>$item->parent_id]);
  108. break;
  109. case "tag":
  110. $newsDataProvider = new \yii\data\ActiveDataProvider(
  111. [
  112. "query"=>News::find()->joinWith("tags t")->andWhere(["t.id"=>[$item->parent_id], "(flags & 1)"=>0]),
  113. "pagination" =>[
  114. "pageSize"=>$pageSize
  115. ],
  116. ]
  117. );
  118. $topic = \app\models\base\Tags::findOne(['id'=>$item->parent_id]);
  119. break;
  120. default:
  121. $newsDataProvider = new \yii\data\ActiveDataProvider(
  122. [
  123. "query"=>News::find()->joinWith("stories t")->andWhere(["t.id"=>[$item->parent_id], "(flags & 1)"=>0]),
  124. "pagination" =>[
  125. "pageSize"=>$pageSize
  126. ],
  127. ]
  128. );
  129. $topic = \app\models\base\Story::findOne(['id'=>$item->parent_id]);
  130. break;
  131. }
  132. $view = \yii\helpers\ArrayHelper::getValue(Design::$id_to_view_map,$item->design,Design::$id_to_view_map[Design::IMAGINE_NEWS_WIDGET]);
  133. echo $this->render($view,['newsDataProvider'=>$newsDataProvider,"topic"=>$topic,"design" => $item]);
  134. }
  135. // if(!Yii::$app->deviceDetect->isMobile()) echo $this->render('@app/views/_etc/banners/desktopfirstPage');
  136. $this->endCache();
  137. }
  138. ?>
  139. </div>