index.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @var $topic NewsTopic | NULL
  4. * @var $this \yii\web\View
  5. * @var $news_query \yii\db\ActiveQuery
  6. */
  7. use app\models\base\NewsTopic;
  8. use app\models\base\Story;
  9. use app\models\base\Tags;
  10. use yii\widgets\ListView;
  11. use yii\helpers\Url;
  12. $this->params['breadcrumbs'] = [
  13. [
  14. "text"=>"НОВОСТИ",
  15. "url"=>"/news"
  16. ]
  17. ];
  18. $page = \Yii::$app->request->get('page');
  19. $addpage = $page?'?page='.$page:'';
  20. $addtpage = $page?". Страница ($page)":'';
  21. if($topic instanceof NewsTopic || $topic instanceof Story || $topic instanceof Tags){
  22. $this->params['breadcrumbs'][] =
  23. [
  24. "text"=>$topic->title,
  25. "url"=>$topic->url
  26. ];
  27. $addtitle = ( $topic instanceof Tags )?'Тег: ':'';
  28. // $addtitle = ( $topic instanceof Story )?'Сюэет: ':''; открыть если будут дубли
  29. Yii::$app->og->canonical = $topic->getUrl(true);
  30. $this->title = $topic->title;
  31. Yii::$app->og->title = $addtitle.$topic->title.$addtpage;
  32. Yii::$app->og->description = $topic->description.$addtpage?:'Лента новостей - '.Yii::$app->og->description.$addtpage;
  33. Yii::$app->og->og_title = str_replace( '"',"&quot;",$topic->title);
  34. Yii::$app->og->og_description = str_replace( '"', "&quot;", Yii::$app->og->description );
  35. }else{
  36. Yii::$app->og->title = 'Лента новостей - '.Yii::$app->og->title.$addtpage;
  37. Yii::$app->og->description = 'Лента новостей - '.Yii::$app->og->description.$addtpage;
  38. Yii::$app->og->og_title = str_replace( '"',"&quot;", Yii::$app->og->title );
  39. Yii::$app->og->og_description = str_replace( '"',"&quot;", Yii::$app->og->description );
  40. Yii::$app->og->canonical = Url::base('https')."/news".$addpage;
  41. }
  42. //$pages->setPageSize(0,true);
  43. ?>
  44. <div class="archive">
  45. <div class="row">
  46. <div class="col-md-3">
  47. <div class="topics-list">
  48. <div class="topics-continer">
  49. <?php
  50. echo Yii::$app->cache->getOrSet("archive_rubrics-{$topic->id}",function () use($topic){
  51. return \yii\widgets\ListView::widget([
  52. "dataProvider" => new \yii\data\ActiveDataProvider([
  53. "query"=>NewsTopic::find()->andWhere(["show"=>"Y","active"=>1,"topic_id"=>null])->orderBy(["order"=>SORT_ASC]), //"topic_id"=>$topic->id next lavel maybe
  54. "pagination" =>[
  55. "pageSize"=>0
  56. ],
  57. ]),
  58. 'options' => [
  59. 'tag' => "ul",
  60. 'class' => 'list-wrapper',
  61. 'id' => 'list-wrapper',
  62. ],
  63. "itemOptions"=>[
  64. "tag"=>"li"
  65. ],
  66. "itemView" => function($model) use($topic) {
  67. if( $model->url == '----'){
  68. $ret = \yii\helpers\Html::tag('div','',['class' => ['hr']]);
  69. $ret .= \yii\helpers\Html::tag('span',$model->title,['class' => ['header']]);
  70. return $ret;
  71. }
  72. return \yii\helpers\Html::a($model->title,["news/{$model->url}"],['class'=>$model->id==$topic->id?"active":""]);
  73. },
  74. "layout" => "{items}"
  75. ]);
  76. },NewsTopic::$keysCache['archive_rubrics-##']);
  77. ?>
  78. </div>
  79. </div>
  80. </div>
  81. <div class="col-md-9">
  82. <div class="news-list">
  83. <?=$this->render("/layouts/breadcrumbs")?>
  84. <?=$this->render("archive/filters")?>
  85. <?php
  86. $adkey = ($topic instanceof Story)?'Story-':'';
  87. $adkey =$adkey.($keycahe ?? '');
  88. $request = Yii::$app->request;
  89. $ppage = $request->get('page');
  90. $ppage = ($ppage)?'-'.$ppage:'';
  91. $daterange = $request->get('daterange');
  92. $dr = ($daterange)?'-'.$daterange:'';
  93. echo Yii::$app->cache->getOrSet("archive_news-{$adkey}{$dr}{$topic->id}{$ppage}",function () use($news_query, $pages){
  94. return ListView::widget([
  95. "dataProvider" => new \yii\data\ActiveDataProvider([
  96. "query"=>$news_query,
  97. "pagination"=>$pages,
  98. "totalCount"=>$pages->totalCount,
  99. ]),
  100. 'options' => [
  101. 'tag' => "ul",
  102. 'class' => 'list-wrapper',
  103. 'id' => 'list-wrapper',
  104. ],
  105. "itemOptions"=>[
  106. "tag"=>"li"
  107. ],
  108. "itemView" => "archive/_archive_item",
  109. "layout" => "{items}{pager}"
  110. ]);
  111. },NewsTopic::$keysCache['archive_news-##']);
  112. ?>
  113. </div>
  114. </div>
  115. </div>
  116. </div>