list.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. use \app\models\base\Story;
  3. use \app\models\base\NewsTopic;
  4. use \app\models\base\Tags;
  5. $this->title="Главная страница";
  6. $newsDataProvider = new \yii\data\ActiveDataProvider(
  7. [
  8. "query"=>\app\models\Design::find()->orderBy(["order"=>SORT_ASC]),
  9. "pagination" => false
  10. ]
  11. );
  12. ?>
  13. <div class="table-responsive-sm custom-range-badge">
  14. <table class="table table-hover table-Light" id="sortable" data-ajax="sort">
  15. <thead class="bg-gray table-sm">
  16. <tr class="tr-state-disabled">
  17. <th scope="col" class="col-md-1 col-sm-2 col-xs-5">#</th>
  18. <th scope="col">заголовок</th>
  19. <th scope="col">статусы</th>
  20. <th scope="col" class="col-sm-1">управление</th>
  21. </tr>
  22. </thead>
  23. <tbody>
  24. <?
  25. foreach( $newsDataProvider->getModels() as $item ){
  26. // print_r($item);
  27. //return;
  28. $strbage = '';
  29. switch($item->type){
  30. case 'story':
  31. $model = Story::findOne($item->parent_id);
  32. break;
  33. case 'topic':
  34. $model = NewsTopic::findOne($item->parent_id);
  35. break;
  36. case 'tag':
  37. $model = Tags::findOne($item->parent_id);
  38. break;
  39. default:
  40. $title = $item->title;
  41. $model = null;
  42. break;
  43. }
  44. if( $model ){
  45. $title = (trim($item->title) == '')?$model->title:$item->title;
  46. }else{
  47. $strbage .= '<span class="badge badge-danger">Дохлый элемент</span><br>';
  48. }
  49. $mark = '';
  50. if( $item->active == 'N' ){
  51. $mark = ' class="table-dark"';
  52. $strbage .= '<span class="badge badge-dark">Спрятано</span><br>';
  53. }
  54. switch($item->design){
  55. case 1:
  56. $strbage .= '<i class="fa fa-image"></i> <i class="fa fa-dollar-sign"></i>';
  57. break;
  58. case 2:
  59. $strbage .= '<i class="fas fa-stream"></i><i class="fas fa-stream"></i><i class="fas fa-stream"></i><i class="fas fa-stream"></i>';
  60. break;
  61. case 3:
  62. $strbage .= '<i class="fa fa-map"></i>';
  63. break;
  64. case 4:
  65. $strbage .= '<i class="fa fa-image"></i><i class="fa fa-image"></i><i class="fa fa-image"></i>';
  66. break;
  67. case 5:
  68. $strbage .= '<i class="fa fa-image bg-warning"></i><i class="fa fa-image bg-primary"></i><i class="fa fa-image bg-warning"></i>';
  69. break;
  70. case 6:
  71. $strbage .= '<i class="fa fa-image"></i> <i class="fa fa-image"></i>';
  72. break;
  73. default:
  74. $strbage .= 'неопределён дизайн';
  75. break;
  76. }
  77. ?>
  78. <tr<?=$mark?> class="ui-sortable" id="item_<?=$item->id?>">
  79. <th scope="row" class="text-nowrap"><?=$item->id?></th>
  80. <td><?=$title?><br><small><?=($model && $model->description)?$model->description:''?><small></td>
  81. <td><?=$strbage?></td>
  82. <td><div class="btn-group btn-group-toggle" data-toggle="a" role="group">
  83. <a href="update?id=<?=$item->id?>" title="Править" role="button" class="btn btn-secondary btn-sm"><i class="far fa-edit"></i></a>
  84. <a href="active?id=<?=$item->id?>" title="не видно ни кому" role="button" class="btn btn-secondary btn-sm"><i class="fa <?=($item->active == 'Y')?'fa-play':'fa fa-stop'?>"></i></a>
  85. <?
  86. if( Yii::$app->user->can('admin') ){
  87. ?>
  88. <a href="del?id=<?=$item->id?>" role="button" class="btn btn-secondary btn-sm" onClick="return confirm('Удалить?')" title="удалить"><i class="fa fa-trash"></i></a>
  89. <?
  90. }
  91. ?>
  92. </tr>
  93. <?
  94. // <pre>
  95. // print_r($item);
  96. // </pre>
  97. ?>
  98. <?
  99. }
  100. ?>
  101. </tbody>
  102. </table>
  103. </div>
  104. <script>
  105. </script>
  106. <?php
  107. //print_r($newsDataProvider->getModels());