<?php

use yii\helpers\Html;
use yii\grid\GridView;


/* @var $this yii\web\View */
/* @var $searchModel backend\models\ChapterSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
//echo $id;exit;
$this->title = 'Chapters';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="chapter-index">

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

    <p>
        <?= Html::a('Create Chapter', Yii::$app->urlManager->createUrl(array("chapter/create", "bookid"=>$_GET["bookid"])), ['class' => 'btn btn-success']) ?>
        <?= Html::a('Back', ['back'], ['class' => 'btn btn-danger']) ?>
    </p>

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

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

                'attribute' => 'bookId',
                'format' => 'html',
                'value' => function($data) {
                        $book= \backend\models\Book::find()->where('id ='.$data->bookId)->one();
                        return $book->title;
                    },
                'contentOptions'=>['style'=>'width: 200px;'],
                'filter'=>false,
            ],
            'title',
            'chapterIndex',
            //'bookMarkIndex',

            [
                'label'=>'Manage Pages',
                'format' => 'html',
                'value' =>function($data){
                        if($data->type == 0)
                        {
                            //echo 123;exit;
                            return '<a style="text_align:center;" data-toggle="tooltip" data-placement="top" data-original-title="'.'Chapters'.'" href="'. Yii::$app->urlManager->createUrl(array('quote/index','QuoteSearch[chapterId]'=>$data->id,'bookid'=>$_GET["bookid"],'chapid'=>$data->id)).'" class="glyphicon glyphicon-edit"></a>';
                        }
                        else
                        {
                            //echo 456;exit;
                            return '';
                        }
                    },
                'contentOptions'=>['style'=>'width: 20px;']
            ],

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

</div>
