newsInactive.php 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. use app\models\Authors;
  3. $this->title="Новости";
  4. //тест (заменить на новостьи дня и по календарику)
  5. /*
  6. $newsDataProvider = new \yii\data\ActiveDataProvider(
  7. [
  8. "query"=>\app\models\News::getMainView()->orderBy(["dt_pub"=>SORT_DESC])->limit(50),
  9. "pagination" =>[
  10. "pageSize"=>50
  11. ],
  12. ]
  13. );
  14. */
  15. $b_date = date("Y-m-d 00:00:00",time()-60*60*24*5);
  16. $e_date = date("3000-m-d 23:59:59");
  17. $tnow = date("Y-m-d H:i:s");
  18. //\app\models\base\News::find()->andwhere(['between', 'dt_pub', $b_date , $e_date])->orwhere(['active'=>'N'])->orderBy(["dt_pub"=>SORT_DESC])->limit(200)
  19. //echo "SELECT * FROM `news` WHERE (`dt_pub` between '$b_date' and '$e_date' and `active`='N') or (`dt_pub` > '$tnow' and `active`='Y')"; exit;
  20. $newsDataProvider = new \yii\data\ActiveDataProvider(
  21. [
  22. "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"),
  23. "pagination" =>[
  24. "pageSize"=>200
  25. ],
  26. ]
  27. );
  28. $cache = Yii::$app->cache;
  29. /**** ****/
  30. ?>
  31. <div class="table-responsive-sm custom-range-badge">
  32. <table class="table table-hover table-Light">
  33. <thead class="bg-gray table-sm">
  34. <tr>
  35. <th scope="col" class="col-md-1 col-sm-2 col-xs-5">время</th>
  36. <th scope="col" class="col-md-1 col-sm-2 col-xs-5">фото</th>
  37. <th scope="col">заголовок</th>
  38. <th scope="col">статусы</th>
  39. <th scope="col">управление</th>
  40. </tr>
  41. </thead>
  42. <tbody>
  43. <?
  44. foreach( $newsDataProvider->getModels() as $item ){
  45. // print_r($item->getTopics());
  46. $strTopics = '';
  47. foreach( $item->getTopics()->primaryModel->topics as $topic ){
  48. $strTopics = $strTopics." [".$topic->title."]";
  49. }
  50. $strbage = '';
  51. if( $item->verifed == 'Y' ) $strbage .= '<span class="badge badge-success font-weight-normal">проверено</span><br>';
  52. if( $item->top == 'Y' ) $strbage .= '<span class="badge badge-primary font-weight-normal">картина дня</span><br>';
  53. if( $item->NH == 'Y' ) $strbage .= '<span class="badge badge-info font-weight-normal">НЧ</span><br>';
  54. if( $item->comments == 'N' ) $strbage .= '<span class="badge badge-secondary font-weight-normal">no comments</span><br>';
  55. if( ($item->flags & 1) == 1 ) $strbage .= '<span class="badge badge-warning font-weight-normal">без главной</span><br>';
  56. if( $res = $cache->get("editNews_".$item->id) ){
  57. $strbage .= '<span class="badge badge-danger font-weight-normal">'.unserialize($res)['author'].'</span><br>';
  58. }
  59. $show = ($item->active == 'N' || strtotime($item->dt_pub) > time())?'preview/'.$item->uid:$item->id;
  60. $author = Authors::getAuthor($item->author);
  61. $icon = $item->getImage()->getIcon();
  62. ?>
  63. <tr<?=($item->active == 'N')?' class="table-secondary"':''?>>
  64. <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>
  65. <td><img src="<?=$icon?>" onerror="this.src='/images/defaultsm.jpg'" width="94" height="auto"></td>
  66. <td><?=$item->title?><br><small><?=$strTopics?><br><?=str_replace(',',' ',$item->editors)?></small><small class="bg-olive px-1"><?=$author->name?></small></td>
  67. <td><?=$strbage?></td>
  68. <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>
  69. </tr>
  70. <?
  71. // <pre>
  72. // print_r($item);
  73. // </pre>
  74. ?>
  75. <?
  76. }
  77. ?>
  78. </tbody>
  79. </table>
  80. </div>
  81. <?php
  82. //print_r($newsDataProvider->getModels());