<?php

use app\base\Common;
use yii\helpers\Html;
use kartik\grid\GridView;
use rmrevin\yii\fontawesome\FA;
use yii\helpers\ArrayHelper;
use app\models\Visitmaster;

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

$this->title = Yii::t('app', Common::getMenuname());
$this->params['breadcrumbs'][] = $this->title;
$this->params['menu'] = [
	['label' => FA::icon('align-justify fa-fw'), 'linkOptions' => ['class'=>'btn btn-default', 'title'=>'List'], 'url' => ['/'.Yii::$app->controller->id]],
];
?>
<div class="visitschedule-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'],

			// 'sch_id',
			'participant_id:ntext',
			'date_of_screening',
			/*
			[
				'attribute' => 'visit_code',
				// 'attribute' => 'visit.visit_name',
				'value' => 'visit.visit_name'
			],
			*/
			[
					'attribute' => 'visit_code',
		            'label' => 'Visit',
		            'contentOptions' => ['class' => 'col-md-2'],
					'noWrap' => true,					
		            'filterType'=>GridView::FILTER_SELECT2,
		            'filter'=>ArrayHelper::map(Visitmaster::find()->where(['NOT', ['visit_interval' => null]])->andWhere(["status" => 1])->orderBy(['visit_code'=> SORT_DESC])->asArray()->all(), 'visit_code', 'visit_name'), 
		            'filterInputOptions'=>['placeholder'=>''],
	                'value' => function($data) {
                    return $data->getVisits($data->visit_code);
                },
				],
				
			// 'no_of_days',
			'actual_date',
			'visit_date',
			'window_start',
			'window_end',
			//'status',
			// 'create_time:datetime',
			// 'create_user',
			// 'update_time:datetime',
			// 'update_user',
			// 'record_date',

             ['class' => 'app\behaviours\ActionColumns',
			  'contentOptions' => ['class' => 'col-md-1'],
			 'template'=> '{view} {update}',
			 'buttons'=> [
                'update'=> function($url,$model) {
                    return Html::a( '<span class="glyphicon glyphicon-pencil"></span>', $url); 
                },              
            ],
           
        ],
        ],
    ]); ?>
</div>
