<?php

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

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

$this->title = 'Pages';
$this->params['breadcrumbs'][] = $this->title;
//echo $_REQUEST['QuoteSearch["chapterId"]'];exit;

?>
<div class="quote-index">

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

    <p>
        <?= Html::a('Create Pages', Yii::$app->urlManager->createUrl(array("quote/create", "bookid"=>$_GET["bookid"],"chapid"=>$_GET["chapid"])), ['class' => 'btn btn-success']) ?>

        <a href="<?php echo  Yii::$app->urlManager->createUrl(array('chapter/index','bookid'=> $_GET["bookid"], 'ChapterSearch[bookId]'=> $_GET["bookid"]))?>" class="btn btn-danger">Back</a>

    </p>

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

            //'id',
            /*[
                'attribute'=>'id',
                'format' => 'html',
                'value' => 'id',
                'contentOptions'=>['style'=>'width: 20px;']
            ],*/
            'quoteIndex',
            //'content:ntext',
            [
                'attribute' => 'content',
                'format' => 'text',
                'value' => function($data) {
                        $content= substr($data->content,0,100);
                        return $content.'...';
                    },
            ],
            //'chapterId',
            [
                'attribute' => 'chapterId',
                'format' => 'html',
                'value' => function($data) {
                        $chapter= \backend\models\Chapter::find()->where('id ='.$data->chapterId)->one();
                        return $chapter->title;
                    },
                'filter'=>false,
            ],
            [
                'attribute'=>'image',
                'value'=>function($data)
                    {
                        return Yii::$app->urlManager->baseUrl . '/images/quote/'.$data->image;
                    },
                'format' => ['image',['width'=>'100']],
            ],

            //['class' => 'yii\grid\ActionColumn'],
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view} {update} {delete}',
                'buttons' => [
                    'view' => function ($url) {
                            return Html::a(
                                '<span class="glyphicon glyphicon-eye-open"</span>',
                                $url.'&QuoteSearch[chapterId]='.$_REQUEST['chapid'].'&bookid='.$_GET["bookid"].'&chapid='.$_GET['chapid'],
                                [
                                    'title' => 'View',
                                    'data-pjax' => '0',
                                ]
                            );
                        },
                    'update' => function ($url) {
                            return Html::a(
                                '<span class="glyphicon glyphicon-pencil"</span>',
                                $url."&bookid=".$_GET["bookid"]."&chapid=".$_GET["chapid"],
                                [
                                    'title' => 'Update',
                                    'data-pjax' => '0',
                                ]
                            );
                        },
                    /*'delete' => function ($url) {
                            return Html::a(
                                '<span class="glyphicon glyphicon-trash"</span>',
                                $url,
                                [
                                    'title' => 'Delete',
                                    'data-pjax' => '0',
                                ]
                            );
                        },*/
                ],
            ],
        ],
    ]); ?>

</div>
