index.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_auto",[]);
  26. }else{
  27. echo $this->render("index/main_view",[]);
  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. if($i==3) echo $this->render('@app/views/_etc/banners/firstDesktopTransparant');
  78. if($i==6 && Yii::$app->deviceDetect->isMobile()) echo $this->render('@app/views/_etc/banners/bannerMobile3');
  79. if($i==6 && !Yii::$app->deviceDetect->isMobile()) echo $this->render('@app/views/_etc/banners/bannerDesktop3');
  80. /**
  81. * @var $item Design
  82. */
  83. switch ($item->design)
  84. {
  85. case Design::TOPIC_WIDGET:
  86. $pageSize = 10;
  87. break;
  88. case Design::IMAGINE_NEWS_WIDGET:
  89. $pageSize = 3;
  90. break;
  91. default:
  92. $pageSize = 4;
  93. }
  94. switch ($item->type)
  95. {
  96. case "topic":
  97. $newsDataProvider = new \yii\data\ActiveDataProvider(
  98. [
  99. "query"=>News::find()->joinWith("topics t")->andWhere(["t.id"=>[$item->parent_id], "(flags & 1)"=>0]),
  100. "pagination" =>[
  101. "pageSize"=>$pageSize
  102. ],
  103. ]
  104. );
  105. $topic = \app\models\base\NewsTopic::findOne(['id'=>$item->parent_id]);
  106. break;
  107. case "tag":
  108. $newsDataProvider = new \yii\data\ActiveDataProvider(
  109. [
  110. "query"=>News::find()->joinWith("tags t")->andWhere(["t.id"=>[$item->parent_id], "(flags & 1)"=>0]),
  111. "pagination" =>[
  112. "pageSize"=>$pageSize
  113. ],
  114. ]
  115. );
  116. $topic = \app\models\base\Tags::findOne(['id'=>$item->parent_id]);
  117. break;
  118. default:
  119. $newsDataProvider = new \yii\data\ActiveDataProvider(
  120. [
  121. "query"=>News::find()->joinWith("stories t")->andWhere(["t.id"=>[$item->parent_id], "(flags & 1)"=>0]),
  122. "pagination" =>[
  123. "pageSize"=>$pageSize
  124. ],
  125. ]
  126. );
  127. $topic = \app\models\base\Story::findOne(['id'=>$item->parent_id]);
  128. break;
  129. }
  130. $view = \yii\helpers\ArrayHelper::getValue(Design::$id_to_view_map,$item->design,Design::$id_to_view_map[Design::IMAGINE_NEWS_WIDGET]);
  131. echo $this->render($view,['newsDataProvider'=>$newsDataProvider,"topic"=>$topic,"design" => $item]);
  132. }
  133. // if(!Yii::$app->deviceDetect->isMobile()) echo $this->render('@app/views/_etc/banners/desktopfirstPage');
  134. $this->endCache();
  135. }
  136. ?>
  137. </div>