newsInactive.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. use app\models\Authors;
  3. use yii\web\View;
  4. $this->title="Новости";
  5. //тест (заменить на новостьи дня и по календарику)
  6. /*
  7. $newsDataProvider = new \yii\data\ActiveDataProvider(
  8. [
  9. "query"=>\app\models\News::getMainView()->orderBy(["dt_pub"=>SORT_DESC])->limit(50),
  10. "pagination" =>[
  11. "pageSize"=>50
  12. ],
  13. ]
  14. );
  15. */
  16. $b_date = date("Y-m-d 00:00:00",time()-60*60*24*5);
  17. $e_date = date("3000-m-d 23:59:59");
  18. $tnow = date("Y-m-d H:i:s");
  19. //\app\models\base\News::find()->andwhere(['between', 'dt_pub', $b_date , $e_date])->orwhere(['active'=>'N'])->orderBy(["dt_pub"=>SORT_DESC])->limit(200)
  20. //echo "SELECT * FROM `news` WHERE (`dt_pub` between '$b_date' and '$e_date' and `active`='N') or (`dt_pub` > '$tnow' and `active`='Y')"; exit;
  21. $newsDataProvider = new \yii\data\ActiveDataProvider(
  22. [
  23. "query"=>\app\models\base\News::findBySql("SELECT * FROM `news` FORCE INDEX(`calendar`) WHERE (`dt_pub` between '$b_date' and '$e_date' and `active`='N') or (`dt_pub` > '$tnow' and `active`='Y') order by `dt_pub` DESC"),
  24. "pagination" =>[
  25. "pageSize"=>200
  26. ],
  27. ]
  28. );
  29. $cache = Yii::$app->cache;
  30. /**** ****/
  31. ?>
  32. <div class="table-responsive-sm custom-range-badge">
  33. <table class="table table-hover table-Light">
  34. <thead class="bg-gray table-sm">
  35. <tr>
  36. <th scope="col" class="col-md-1 col-sm-2 col-xs-5">время</th>
  37. <th scope="col" class="col-md-1 col-sm-2 col-xs-5">фото</th>
  38. <th scope="col">заголовок</th>
  39. <th scope="col">статусы</th>
  40. <th scope="col">управление</th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. <?
  45. $NewsItem = array();
  46. foreach( $newsDataProvider->getModels() as $item ){
  47. // print_r($item->getTopics());
  48. $strTopics = '';
  49. $NewsItem[] = $item->id;
  50. foreach( $item->getTopics()->primaryModel->topics as $topic ){
  51. $strTopics = $strTopics." [".$topic->title."]";
  52. }
  53. $strbage = '';
  54. if( $item->verifed == 'Y' ) $strbage .= '<span class="badge badge-success font-weight-normal">проверено</span><br>';
  55. if( $item->top == 'Y' ) $strbage .= '<span class="badge badge-primary font-weight-normal">картина дня</span><br>';
  56. if( $item->NH == 'Y' ) $strbage .= '<span class="badge badge-info font-weight-normal">НЧ</span><br>';
  57. if( $item->comments == 'N' ) $strbage .= '<span class="badge badge-secondary font-weight-normal">no comments</span><br>';
  58. if( ($item->flags & 1) == 1 ) $strbage .= '<span class="badge badge-warning font-weight-normal">без главной</span><br>';
  59. if( $res = $cache->get("editNews_".$item->id) ){
  60. $strbage .= '<span class="badge badge-danger font-weight-normal">'.unserialize($res)['author'].'</span><br>';
  61. }
  62. $show = ($item->active == 'N' || strtotime($item->dt_pub) > time())?'preview/'.$item->uid:$item->id;
  63. $author = Authors::getAuthor($item->author);
  64. $icon = $item->getImage()->getIcon();
  65. ?>
  66. <tr<?=($item->active == 'N')?' class="table-secondary"':''?>>
  67. <th scope="row" class="text-nowrap"><span class="<?=( strtotime($item->dt_pub) < time() )?'text-fuchsia':''?>"><?=date("H:i d-m-Y",strtotime($item->dt_pub))?></span></th>
  68. <td><img src="<?=$icon?>" onerror="this.src='/images/defaultsm.jpg'" width="94" height="auto"></td>
  69. <td><?=$item->title?><br><small><?=$strTopics?><br><?=str_replace(',',' ',$item->editors)?></small><small class="bg-olive px-1"><?=$author->name?></small></td>
  70. <td rel_id="<?=$item->id?>"><?=$strbage?></td>
  71. <td><div class="btn-group btn-group-toggle" data-toggle="a" role="group"><a href="update?id=<?=$item->id?>" title="Править" role="button" class="btn btn-secondary btn-sm"><i class="far fa-edit"></i></a><a href="newsshow?id=<?=$item->id?>" title="спрятать" role="button" class="btn btn-sm btn-secondary"><i class="fa <?=($item->active == 'N')?'fa-eye-slash':'fa fa-eye'?>"></i></a><a href="newskd?id=<?=$item->id?>" role="button" class="btn btn-sm <?=($item->top == 'N')?'btn-secondary':'btn-primary'?>">КД</a><a href="newsnh?id=<?=$item->id?>" role="button" class="btn <?=($item->NH == 'N')?'btn-secondary':'btn-primary'?> btn-sm">НЧ</a><a href="/news/<?=$show?>" title="открыть на сайте" role="button" class="btn btn-secondary btn-sm" target="_blank"><i class="far fa-window-restore"></i></a><?if(Yii::$app->user->can('deleteNews')){?><a href="delete?id=<?=$item->id?>" title="открыть на сайте" role="button" class="btn btn-secondary btn-sm" target="_blank" onclick="return confirm('Вы уверены?')"><i class="fa fa-trash"></i></a><?}?></div></div></td>
  72. </tr>
  73. <?
  74. // <pre>
  75. // print_r($item);
  76. // </pre>
  77. ?>
  78. <?
  79. }
  80. ?>
  81. </tbody>
  82. </table>
  83. </div>
  84. <?php
  85. $ni = serialize($NewsItem);
  86. $nij = json_encode($NewsItem);
  87. $script = <<< JS
  88. setInterval( function (){ testping() }, 10000 );
  89. function testping(){
  90. $.get( 'testping', { cmd: 'GetAuthors', data: '$ni' }, function(data){
  91. data = JSON.parse(data);
  92. if( data.status == 'ok' ){
  93. var dn = JSON.parse('$nij');
  94. $.each( dn, function( key, value ) {
  95. $("[rel_id='"+value+"'] .author").remove();
  96. $("[rel_id='"+value+"'] br:last-child").remove();
  97. });
  98. $.each( data['authors'], function( key, value ) {
  99. // $("[rel_id='"+key+"'] .author").remove();
  100. // $("[rel_id='"+key+"'] br:last-child").remove();
  101. $("[rel_id='"+key+"']").append("<span class='badge badge-danger font-weight-normal author'>"+value+"</span>");
  102. console.log(key);
  103. });
  104. }
  105. } );
  106. }
  107. JS;
  108. $this->registerJs( $script,View::POS_READY);
  109. //print_r($newsDataProvider->getModels());