<?php

namespace modules\custom\models;


use Yii;
use yii\helpers\Json;
use modules\users\models\User;
/**
 * This is the model class For table "dt134".
 *
 * @property string $id
 * @property integer $created_at
 * @property integer $updated_at
 * @property string $created_by
 * @property string $updated_by
 * @property string $deleted_by
 * @property integer $deleted_at
 * @property integer $deleted
 * @property string $actid
 * @property string $status
 * @property string $driver
 * @property string $vehiclereg
 * @property string $vehicleid
 * @property integer $startmileage
 * @property integer $finishmileage
 * @property string $question1
 * @property string $question2
 * @property string $question3
 * @property string $question4
 * @property string $question5
 * @property string $question6
 * @property string $question7
 * @property string $question8
 * @property string $question9
 * @property string $question10
 * @property string $question11
 * @property string $question12
 * @property string $question13
 * @property string $question14
 * @property string $question15
 * @property string $question16
 * @property string $question17
 * @property string $question18
 * @property string $question19
 * @property string $question20
 * @property string $question21
 * @property string $question22
 * @property string $tyredepthin1
 * @property string $tyredepthin2
 * @property string $tyredepthin3
 * @property string $tyredepthin4
 * @property string $tyredepthin5
 * @property string $tyredepthout1
 * @property string $tyredepthout2
 * @property string $tyredepthout3
 * @property string $tyredepthout4
 * @property string $tyredepthout5
 * @property string $tyrepressure1
 * @property string $tyrepressure2
 * @property string $tyrepressure3
 * @property string $tyrepressure4
 * @property string $tyrepressure5
 * @property string $image
 * @property string $signature1
 * @property string $signature2
 * @property string $comments
 */
class Dt134 extends \common\models\Base {

	public $uniqueidentifiers = ['actid'];
	public $dates = ['created_at','updated_at', 'deleted_at'];
    public $securefields = [];
   
       /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'forms';
    }

/**
     * @inheritdoc
     */
    public function rules(): array
    {
        $rules = [
            [['data'], 'safe'],
            [['padno', 'form', 'status', 'actid'], 'string'],
            [['form'], 'default', 'value' => 'dt134'],

        ];
        return array_merge(parent::rules(), $rules);
    }
    
    /**
     * @inheritdoc
     */
    public function attributeLabels(): array
    {
        $attributeLabels = [
            'actid' => yii::t('app', 'Activity ID'),
            'data' => yii::t('app', 'DT134 Data'),
            'jobno' => yii::t('app', 'Jobno'),
            'form' => yii::t('app', 'Form'),
            'padno' => yii::t('app', 'Pad Number'),
            'status' => yii::t('app', 'Status'),
        ];
        return array_merge(parent::attributeLabels(), $attributeLabels);
    }

    public function afterFind(){
        $dt134 = new Dt134a();
        $dt134->attributes = Json::decode($this->data);
        $this->data = $dt134;
        return parent::afterFind();
    }

    public function beforeSave($insert){
        $this->data = json_encode($this->data);
        return parent::beforeSave($insert);
    }
    
    public function init(){
        $dt134 = new Dt134a();
        $this->data = $dt134;
        return parent::init();
    }


    public function getActivity() {
		return $this->hasOne(\modules\activities\models\Activities::class, ['id' => 'actid']);
	}
    
    public function getDriverl() {
		return $this->hasOne(User::class, ['id' => 'driver']);
	}    
	public function getVehiclel() {
		return $this->hasOne(\modules\cors\models\Vehicle::class, ['id' => 'vehicleid']);
	}
	public function getNoncom() {
		return $this->hasMany(\modules\forms\models\Dt188::class, ['relatedid' => 'id']);
	}

    public static function find(){
        return parent::find()
        ->onCondition(['form'=> 'dt134']);
    }
}
