= Bar::widget([
'template' => "{refresh} {delete}",
]) ?>
= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'class' => CheckboxColumn::className(),
],
[
'attribute' => 'id',
],
[
'attribute' => 'aid',
],
[
'attribute' => 'article_title',
'label' => Yii::t('app', 'Article Title'),
'value' => function ($model) {
return $model->article->title;
}
],
[
'attribute' => 'nickname',
],
[
'attribute' => 'content',
'format' => 'html',
],
[
'attribute' => 'status',
'format' => 'html',
'value' => function ($model, $key, $index, $column) {
$text = Constants::getCommentStatusItems($model->status);
if ($model->status == Comment::STATUS_INIT) {
$class = 'btn-default';
} else {
if ($model->status == Comment::STATUS_PASSED) {
$class = 'btn-info';
} else {
$class = 'btn-danger';
}
}
return "
{$text}";
},
'filter' => Constants::getCommentStatusItems(),
],
[
'class' => DateColumn::className(),
'attribute' => 'created_at',
],
[
'class' => DateColumn::className(),
'attribute' => 'updated_at',
],
[
'class' => ActionColumn::className(),
'width' => '135',
'buttons' => [
'status_init' => function($url, $model, $key){
$comment = new Comment();
if( $model->status != Comment::STATUS_INIT ) return '';
return Html::a('
', ['update', 'id' => $model['id']], [
'class' => 'btn-sm',
'data-confirm' => Yii::t('app', 'Are you sure you want to enable this item?'),
'data-method' => 'post',
'data-pjax' => '0',
'data-params' => [
$comment->formName() . '[status]' => Comment::STATUS_PASSED
]
]) . Html::a('
', ['update', 'id' => $model['id']], [
'class' => 'btn-sm',
'data-confirm' => Yii::t('app', 'Are you sure you want to disable this item?'),
'data-method' => 'post',
'data-pjax' => '0',
'data-params' => [
$comment->formName() . '[status]' => Comment::STATUS_NOT_PASS
]
]);
},
'status_operated' => function ($url, $model, $key) {
if( $model->status == Comment::STATUS_INIT ) return '';
$comment = new Comment();
if ($model->status == Comment::STATUS_PASSED ) {
return Html::a('
', ['update', 'id' => $model['id']], [
'class' => 'btn-sm',
'data-confirm' => Yii::t('app', 'Are you sure you want to enable this item?'),
'data-method' => 'post',
'data-pjax' => '0',
'data-params' => [
$comment->formName() . '[status]' => Comment::STATUS_NOT_PASS
]
]);
} else if( $model->status == Comment::STATUS_NOT_PASS ) {
return Html::a('
', ['update', 'id' => $model['id']], [
'class' => 'btn-sm',
'data-confirm' => Yii::t('app', 'Are you sure you want to disable this item?'),
'data-method' => 'post',
'data-pjax' => '0',
'data-params' => [
$comment->formName() . '[status]' => Comment::STATUS_PASSED
]
]);
}
},
],
'template' => '{view-layer} {status_init} {status_operated} {update} {delete}',
],
]
]); ?>