<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Files;
use app\models\FilesSearch;
use kartik\daterange\DateRangePicker;
use yii\helpers\ArrayHelper;
use app\models\User;



/* @var $this yii\web\View */
/* @var $searchModel app\models\FilesSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Files');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="files-index">


   <!-- --><?php /*echo $this->render('_search', ['model' => $searchModel]); */?>


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

           // 'id',
          //  'path',
            ['attribute' =>'name',
             'header' => Yii::t('app', 'FileName ID'),
                ],
            [
               // delete from files where user_id not in (select id from user) // in SQL
                // 'attribute' => 'user_id.username', for debug
                    'attribute' => 'user_id',
                 'header' => Yii::t('app','UserName ID'),

                 'filter' => ArrayHelper::map(User::find()->all(), 'id', 'username'),

                'value'=> function(Files $e)
                {

                    return isset($e->user->username) ? $e->user->username : 'no user';
                }

            ],
            [
                    'attribute' => 'date',
                    'header' => Yii::t('app', 'Date'),
                    'filter' => DateRangePicker::widget([
                        'name'=>'date_range_2',
                        'presetDropdown'=>true,
                        'hideInput'=>true
                    ])
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view} {delete} {maintenance} ',
                'buttons' => [
                    'maintenance' => function ($url, $model, $key)
                    {
                        return Html::a('<span class="glyphicon glyphicon-download"></span>', ['/files/download', 'id' => $model->id], [
                            'title' => 'download files',
                            'data-pjax' => '0',

                        ]);
                    }

                ]
            ],

            //'user_id',
           // 'auction_id',
            // 'lot_id',

           // ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>

