<?php

namespace modules\forms\models;

use Yii;
use Yii\base\Model;

use modules\activities\models\Activities;
use modules\users\models\User;
use modules\custom\models\Accounts;


/**
 * This is the model class For table "notes".
 *
 * @property integer $id
 * @property integer $actid
 * @property string $note
 * @property integer $createdby
 * @property string $created
 * @property integer $updatedby
 * @property string $updated
 */
class Dt143 extends Model{
	
	public $question1;
	public $question2;
	public $question3;
	public $question4;
	public $question5;
	public $question6;
	public $question7;
	public $question8;
	public $question9;
	public $question10;
	public $question11;
	public $question12;
	public $question13;
	public $question14;
	public $question15;
	public $question16;
	public $question17;
	public $question18;
	public $question19;
	public $question20;
	public $employee;
	public $signature;
	public $date;
	public $created_by;
	public $updated_by;
	public $created_at;
	public $updated_at;
	public $deleted_at;
	public $deleted_by;
	public $created_by2;
	public $updated_by2;
	public $actid;
	public $id;
	public $padno;
	public $jobno;
	public $jcn;
	public $relatedid;
	public $status;
	public $deleted;
	
	public $form = 'dt143';
	public $printlayout = 'Portrait';
	public $formname = 'MEDICAL SELF CERTIFICATION (DT143)';
	public $formType = 'Medical';
	public $createpath = '/forms/dt143/create';
	
    public $formLayout = '/dt143/_form.php';
    public $viewLayout = '@modules/forms/views/dt143/_view.php';public function rules()
	{
		return [
			[['question1', 'question2',
			'question3', 'question4',
			'question5', 'question6',
			'question7', 'question8',
			'question9', 'question10',
			'question11', 'question12',
			'question13', 'question14',
			'question15', 'question16',
			'question17', 'question18',
			'question19', 'question20',
			'employee', 'signature',
			'padno','jobno', 'jcn', 'relatedid', 'status', 'deleted',
			],'string'],
			[['date'], 'safe'],			
			[['created_by', 'updated_by', 'deleted_by', 'actid', 'id',], 'string'],
			[['created_at', 'updated_at', 'deleted_at'], 'safe']
			
			
		];	
	}

/*
public function attributes()
{
	return [
		'question1' => 'question1',
		'question2' => 'question2',
		'question3' => 'question3',
		'question4' => 'question4',
		'question5' => 'question5',
		'question6' => 'question6',
		'question7' => 'question7',
		'question8' => 'question8',
		'question9' => 'question9',
		'question10' => 'question10',
		'question11' => 'question11',
		'question12' => 'question12',
		'question13' => 'question13',
		'question14' => 'question14',
		'question15' => 'question15',
		'question16' => 'question16',
		'question17' => 'question17',
		'question18' => 'question18',
		'question19' => 'question19',
		'question20' => 'question20',
		'employee' => 'employee',
		'signature' => 'signature',
		'date' => 'date',
		'created_by' => 'created_by',
		'updated_by' => 'updated_by',
		'created_at' => 'created_at',
		'updated_at' => 'updated_at',
		'deleted_at' => 'deleted_at',
		'deleted_by' => 'deleted_by',
		'created_by2' => 'created_by2',
		'updated_by2' => 'updated_by2',
		'actid' => 'actid',
		'id' => 'id',
		'padno' => 'padno',
		'jobno' => 'jobno',
	];	
}*/

public function attributeLabels()
{
	return [
		'question1' => '1. Do you have Diabetes needing medication?',
		'question2' => '2. Do you suffer from Epilepsy or fits?',
		'question3' => '3. Do you suffer from Asthma ?',
		'question4' => '4. Have you ever had any heart related problems?',
		'question5' => '5. Have you ever had blackouts, recurrent dizziness or any condition which may cause sudden collaspe or
		incapacity?',
		'question6' => '6. Do you suffer from discomfort or pain in the chest or shortness of breath on exercise i.e. climbing a
		single flight of stairs?',
		'question7' => '7. Do you have difficulty in moving rapidly over short distances including slopes, steps or rough ground?',
		'question8' => '8. Would you have difficulty looking over either shoulder?',
		'question9' => '9. Do you have any difficulty with your eyesight? (simple problems needing glasses need not be included)',
		'question10' => '10. Do you have trouble identifying colours correctly?',
		'question11' => '11. Do you wear contact lenses at any time?',
		'question12' => '12. Do you have any difficulty hearing normal conversations?',
		'question13' => '13. Have you used drugs of abuse within the last 12 months?',
		'question14' => '14. Have you had any alcohol related illnesses during the last 12 months?',
		'question15' => 'question15',
		'question16' => 'question16',
		'question17' => 'question17',
		'question18' => 'question18',
		'question19' => 'question19',
		'question20' => 'question20',
		'employee' => 'Employee',
		'signature' => 'Signature',
		'date' => 'Date',
		'created_by' => 'created_by',
		'updated_by' => 'updated_by',
		'created_at' => 'created_at',
		'updated_at' => 'updated_at',
		'deleted_at' => 'deleted_at',
		'deleted_by' => 'deleted_by',
		'created_by2' => 'created_by2',
		'updated_by2' => 'updated_by2',
		'actid' => 'actid',
		'id' => 'id',
		'padno' => 'padno',
		'jobno' => 'jobno',
	];	
}
	public function getEmployeel(){
		return User::findOne(['username' => $this->employee]);
	}
    public function beforeValidate(){
        $this->padno = $this->padno == null ? User::Padno() : $this->padno;
        return parent::beforeValidate();
    }

	public static function findOne($id)
	{
		if(($form = Forms::find()->where(['id' => $id, 'form' => 'dt143'])->one())){
			return $form->data;
		}
		return false;
	}

	    public static function adminFormButtons($buttons, $model){
      $_this = new self();
        $buttons[$_this->formType]['items'][] = [
            'label' => $_this->formname,
            'url' => [$_this->createpath, 'actid' => $model->id],
            'linkOptions' =>  ['target'=>'_blank'],
        ];
        return $buttons;
    }
}
