<?php

use yii\helpers\Html;
use yii\grid\GridView;
use backend\models\Book;
use backend\models\Comment;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\CommentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Comments';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comment-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            /*[
                'attribute'=>'id',
                'format' => 'html',
                'value' => 'id',
                'contentOptions'=>['style'=>'width: 20px;']
            ],*/
            [

                'attribute' => 'bookId',
                'format' => 'html',
                'value' => function($data) {
                        $book = Comment::bookName($data->bookId);
                        return $book;
                    },
                'contentOptions'=>['style'=>'width: 200px;'],
                'filter'=>false,
            ],
//            'chapterId',
            [

                'attribute' => 'chapterId',
                'format' => 'html',
                'value' => function($data) {
                        $chap = Comment::chapterName($data->chapterId);
                        return $chap;
                    },
                'contentOptions'=>['style'=>'width: 200px;'],
                'filter'=>false,
            ],
//            'name',
            [
                'attribute'=>'name',
                'format' => 'html',
                'value' => 'name',
                'contentOptions'=>['style'=>'width: 150px;']
            ],
            'content',
//            'datetime',
            [
                'attribute'=>'datetime',
                'format' => 'html',
                'value' => 'datetime',
                'contentOptions'=>['style'=>'width: 160px;']
            ],
            // 'status',
            [
                'attribute' => 'status',
                'format' => 'text',
                'value' => function($data) {
                        if($data->status == 1)
                            return 'Active';
                        else
                            return 'Inactive';
                    },
                'contentOptions'=>['style'=>'text-align: center;'],
                'filter'=>\backend\models\Comment::itemAlias("status"),
            ],

            ['class' => 'yii\grid\ActionColumn','template' => '{view} {update} {delete}',
                'buttons' => [
                    'delete' => function ($url) {
                            return Html::a(
                                '<span class="glyphicon glyphicon-trash"</span>',
                                $url,
                                [
                                    'title' => 'Delete',
                                    'data-confirm' => 'Delete this book will delete its comment, Do you want to continue?',
                                    'data-method'=>'post',
                                    'data-pjax' => '0',
                                ]
                            );
                        },
                ],
                'contentOptions'=>array('style'=>'width: 80px;')]
        ],
    ]); ?>

</div>
