<?php

use yii\helpers\Html;
use common\widgets\GridView;

/* @var $this yii\web\View */
/* @var $searchModel frontend\models\DT142Search */
/* @var $dataProvider yii\data\ActiveDataProvider */
    $this->title = $searchModel->formname;
    
    $welder = 
        [
        'label' => 'Employee',
        'format' => 'HTML',
        'attribute' => 'employee',
        'value' => function($model) {
                if( strtolower(Yii::$app->request->get('form')) == 'dt130' || strtolower(Yii::$app->request->get('form')) == 'dt142'){
                    return is_object($model->data) ? $model->data->welders_name : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt213' || strtolower(Yii::$app->request->get('form')) == 'wel233' || strtolower(Yii::$app->request->get('form')) == 'dt192' || strtolower(Yii::$app->request->get('form')) == 'dt129' || strtolower(Yii::$app->request->get('form')) == 'dt128' || strtolower(Yii::$app->request->get('form')) == 'dt123' || strtolower(Yii::$app->request->get('form')) == 'dt125' || strtolower(Yii::$app->request->get('form')) == 'dt126' ){
                    $out = '';
                    if(is_array($model->data->weldersname) == true) {
                        $out = implode(',', $model->data->weldersname);
                    }
                    return is_object($model->data) && is_array($model->data->weldersname) == true ?  $out   : $model->data->weldersname;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt022' ){
                    return is_object($model->data) ? $model->data->welder : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt035' ){
                    return is_object($model->data) ? $model->data->employee : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt058' ){
                    return is_object($model->data) ? ($model->data->emp1 ? $model->data->emp1->fullname : null) : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt122' ){
                    return is_object($model->data) ? $model->data->insepectorid : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt135' ){
                    return is_object($model->data) ? $model->data->operatorname : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt195' || strtolower(Yii::$app->request->get('form')) == 'dt131' || strtolower(Yii::$app->request->get('form')) == 'dt188' ){
                    return is_object($model->data) ? $model->data->name : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt132' ){
                    return is_object($model->data) ? $model->data->witnessname : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt194' ){
                    return is_object($model->data) ? $model->data->assessorname1 : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt197' ){
                    return is_object($model->data) ? $model->data->signprint : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt198' ){
                    return is_object($model->data) ? $model->data->seniorwelder : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt203' ){
                    return is_object($model->data) ? $model->data->inspectedbyname : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt204' ){
                    return is_object($model->data) ? $model->data->icinspectorname : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt205' ){
                    return is_object($model->data) ? $model->data->grindingsupervisorname : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt134' ){
                    return is_object($model->data) ? ($model->data->driverl ? $model->data->driverl->fullname : null) : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt133' ){
                    $out = '';
                    if(is_array($model->data->detailsname) == true) {
                        $out = implode(',', $model->data->detailsname);
                    }
                    return is_object($model->data) ? (is_array($model->data->detailsname) == true ? $out : $model->data->detailsname) : null;	
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt179' ){
                    $out = '';
                    if(is_array($model->data->rowname) == true) {
                        foreach($model->data->rowname as $name){
                            empty($name) == false ? $out .= $name.'<br />' : false;
                        }
                    }
                    return is_object($model->data) ? (is_array($model->data->rowname) == true ? $out : $model->data->rowname) : null;	
                
                }elseif(strtolower(Yii::$app->request->get('form')) == 'dt005' ){
                    return is_object($model->data) ? ($model->data->driverl ? $model->data->driverl->fullname : null) : null;	
                } 
            }
        ];

        $subject =  strtolower(Yii::$app->request->get('form')) == 'dt127' 
        ? [
            'label' => 'Subject',
            'format' => 'HTML',
            'attribute' => 'data.subject',
            'value' => function($model) {
					return $model->data ? $model->data->subjects : null;	
				}
            ]
        
        : [
            'label' => 'Location',
            'format' => 'HTML',
            'attribute' => 'jobno',
            'value' => function($model) {
					return $model->activity ? $model->activity->location : null;	
				}
            ]

?>
<div class="<?=$searchModel->form ?>-index">

    <?= GridView::widget([
        'new' => '&nbsp;', //Html::a('New', ['/forms/'.$searchModel->form.'/create'], ['class' => 'btn btn-success']),
        'title' => $this->title,
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
           // 'id',
                  [
            'label' => 'Job',
            'format' => 'HTML',
            'attribute' => 'jobno',
            'value' => function($model) {
					return $model->activity ? HTML::A($model->activity->jobno, ['/activities/view','id' => $model->activity->id]) : $model->jobno;	
					}
            ],
                  [
            'label' => 'Client',
            'format' => 'HTML',
            'attribute' => 'jobno',
            'value' => function($model) {
					return $model->activity && $model->activity->account ? $model->activity->account->account_name : 'Inline Track Welding';	
				}
            ],
            $subject,
            $welder,
            
            
           	'createdby_name',
           	'created_at',
           	'updatedby_name',
           	'updated_at',
            [
                'class' => 'common\widgets\ActionColumn',
                'template' => '{view} {update} {delete}',
  			    'buttons' => [
                    'update' => function ($url, $model, $key) {
                        return Html::a('<i class="fa fa-pencil"></i>', $url);
                    },
                    'view' => function ($url, $model, $key) use ($searchModel){
                        return Html::a('<i class="fa fa-eye"></i>', ['/forms/'. $searchModel->form.'/view', 'id' => $model->id]);
                    },
                    'delete' => function ($url, $model, $key) use ($searchModel) {
                        return Html::a('<i class="fa fa-trash"></i>', ['/forms/'. $searchModel->form.'/delete', 'id' => $model->id], ['data-method' => 'POST']);
                    },
				],
            ]
        ],
    ]); ?>

</div>
