<?php

use app\models\ReportTopic;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;

/** @var yii\web\View $this */
/** @var yii\data\ActiveDataProvider $dataProvider */

$this->title = 'Старые фоторепортажи';
$this->params['breadcrumbs'][] = $this->title;

$dataProvider->getPagination()->pageSize = 50;


?>
<div class="report-topic-index">

    <p>
        <?= Html::a('Create Report Topic', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            'id',
			[
				'class' => 'yii\grid\DataColumn',
				'format' => 'raw',
				'value' => function ($data) {
						return Html::a(Html::encode(strip_tags($data->title)),["/photo/".$data->id]);
				},
				'attribute' => 'Заголовок',
			],
			[
				'class' => 'yii\grid\DataColumn',
				'format' => 'raw',
				'value' => function ($data) {
						$imgFileShort = "/images/report_photo/";
						return '<div class="attachment-block clearfix" style="max-width: 92px;"><img src="'.$imgFileShort.$data->folder.'/0.160.jpg'.'" width="80px" class="attachment-img"></div>';
				},
				'attribute' => 'img',
			],
			[
				'class' => 'yii\grid\DataColumn',
				'value' => function ($data) {
						return $data->parent_id?'Вложенная папка в: '.$data->parent_id:'';
				},
				'attribute' => 'Вложенные',
			],
			[
				'class' => 'yii\grid\DataColumn',
				'format' => 'raw',
				'value' => function ($data, $key, $index, $column) {
						return $data->active?'<small class="badge badge-success"><i class="fas fa-exclamation-triangle"></i> Вкл.</small>':'<small class="badge badge-secondary"><i class="fas fa-exclamation-triangle"></i> Выкл.</small>';
				},
				'attribute' => 'Статус',
			],
            [
                'class' => ActionColumn::className(),
				'header' => 'Управление',
				'template' => '{view} {update}',
				'buttonOptions' => ['class' => 'btn btn-default'],
                'urlCreator' => function ($action, $model, $key, $index, $column) {
                    return Url::toRoute([$action, 'id' => $model->id]);
                 },
            ],
        ],
		'layout' => "{errors}\n{pager}\n{items}\n{pager}\n{summary}",
		'pager' => [
			'prevPageCssClass' => 'page-item',
			'firstPageLabel' => 'Начало',
			'lastPageLabel' => 'Конец',
			'linkOptions' => [ 'class'=>'page-link'],
			'pageCssClass' => 'page-item',
			'disabledListItemSubTagOptions' => ['tag' => 'a', 'class' => 'page-link'],
		],
    ]); ?>

</div>
