index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2016-03-23 17:51
  7. */
  8. /**
  9. * @var $this yii\web\View
  10. * @var $dataProvider common\models\Comment
  11. * @var $searchModel backend\models\search\CommentSearch
  12. */
  13. use backend\grid\DateColumn;
  14. use backend\grid\GridView;
  15. use common\libs\Constants;
  16. use yii\helpers\Html;
  17. use backend\widgets\Bar;
  18. use common\models\Comment;
  19. use backend\grid\CheckboxColumn;
  20. use backend\grid\ActionColumn;
  21. $this->title = 'Comments';
  22. $this->params['breadcrumbs'][] = Yii::t('app', 'Comments');
  23. ?>
  24. <div class="row">
  25. <div class="col-sm-12">
  26. <div class="ibox">
  27. <?= $this->render('/widgets/_ibox-title') ?>
  28. <div class="ibox-content">
  29. <?= Bar::widget([
  30. 'template' => "{refresh} {delete}",
  31. ]) ?>
  32. <?= GridView::widget([
  33. 'dataProvider' => $dataProvider,
  34. 'filterModel' => $searchModel,
  35. 'columns' => [
  36. [
  37. 'class' => CheckboxColumn::className(),
  38. ],
  39. [
  40. 'attribute' => 'id',
  41. ],
  42. [
  43. 'attribute' => 'aid',
  44. ],
  45. [
  46. 'attribute' => 'article_title',
  47. 'label' => Yii::t('app', 'Article Title'),
  48. 'value' => function ($model) {
  49. return $model->article->title;
  50. }
  51. ],
  52. [
  53. 'attribute' => 'nickname',
  54. ],
  55. [
  56. 'attribute' => 'content',
  57. 'format' => 'html',
  58. ],
  59. [
  60. 'attribute' => 'status',
  61. 'format' => 'html',
  62. 'value' => function ($model, $key, $index, $column) {
  63. $text = Constants::getCommentStatusItems($model->status);
  64. if ($model->status == Comment::STATUS_INIT) {
  65. $class = 'btn-default';
  66. } else {
  67. if ($model->status == Comment::STATUS_PASSED) {
  68. $class = 'btn-info';
  69. } else {
  70. $class = 'btn-danger';
  71. }
  72. }
  73. return "<a class='btn {$class} btn-xs btn-rounded'>{$text}</a>";
  74. },
  75. 'filter' => Constants::getCommentStatusItems(),
  76. ],
  77. [
  78. 'class' => DateColumn::className(),
  79. 'attribute' => 'created_at',
  80. ],
  81. [
  82. 'class' => DateColumn::className(),
  83. 'attribute' => 'updated_at',
  84. ],
  85. [
  86. 'class' => ActionColumn::className(),
  87. 'width' => '135',
  88. 'buttons' => [
  89. 'status_init' => function($url, $model, $key){
  90. $comment = new Comment();
  91. if( $model->status != Comment::STATUS_INIT ) return '';
  92. return Html::a('<i class="fa fa-check"></i> ', ['update', 'id' => $model['id']], [
  93. 'class' => 'btn-sm',
  94. 'data-confirm' => Yii::t('app', 'Are you sure you want to enable this item?'),
  95. 'data-method' => 'post',
  96. 'data-pjax' => '0',
  97. 'data-params' => [
  98. $comment->formName() . '[status]' => Comment::STATUS_PASSED
  99. ]
  100. ]) . Html::a('<i class="fa fa-remove"></i> ', ['update', 'id' => $model['id']], [
  101. 'class' => 'btn-sm',
  102. 'data-confirm' => Yii::t('app', 'Are you sure you want to disable this item?'),
  103. 'data-method' => 'post',
  104. 'data-pjax' => '0',
  105. 'data-params' => [
  106. $comment->formName() . '[status]' => Comment::STATUS_NOT_PASS
  107. ]
  108. ]);
  109. },
  110. 'status_operated' => function ($url, $model, $key) {
  111. if( $model->status == Comment::STATUS_INIT ) return '';
  112. $comment = new Comment();
  113. if ($model->status == Comment::STATUS_PASSED ) {
  114. return Html::a('<i class="fa fa-remove"></i> ', ['update', 'id' => $model['id']], [
  115. 'class' => 'btn-sm',
  116. 'data-confirm' => Yii::t('app', 'Are you sure you want to enable this item?'),
  117. 'data-method' => 'post',
  118. 'data-pjax' => '0',
  119. 'data-params' => [
  120. $comment->formName() . '[status]' => Comment::STATUS_NOT_PASS
  121. ]
  122. ]);
  123. } else if( $model->status == Comment::STATUS_NOT_PASS ) {
  124. return Html::a('<i class="fa fa-check"></i> ', ['update', 'id' => $model['id']], [
  125. 'class' => 'btn-sm',
  126. 'data-confirm' => Yii::t('app', 'Are you sure you want to disable this item?'),
  127. 'data-method' => 'post',
  128. 'data-pjax' => '0',
  129. 'data-params' => [
  130. $comment->formName() . '[status]' => Comment::STATUS_PASSED
  131. ]
  132. ]);
  133. }
  134. },
  135. ],
  136. 'template' => '{view-layer} {status_init} {status_operated} {update} {delete}',
  137. ],
  138. ]
  139. ]); ?>
  140. </div>
  141. </div>
  142. </div>
  143. </div>