<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%labmaster}}".
 *
 * @property integer $lab_id
 * @property string $lab_dept_code
 * @property string $lab_test_code
 * @property string $lab_test_name
 * @property string $lab_spot_test
 * @property string $status
 * @property string $del_status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 */
class Labmaster extends \yii\db\ActiveRecord
{
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%labmaster}}';
	}

	/**
	 * @inheritdoc
	 */
	public function behaviors()
	{
		return [
			[
				'class' => TimestampBehavior::className(),
				'createdAtAttribute' => 'create_time',
				'updatedAtAttribute' => 'update_time',
				'value' => date('U'),
			]
		];
	}

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['lab_dept_code', 'lab_test_code', 'lab_test_name'], 'required'],
			[['lab_test_code', 'lab_test_name'], 'string'],
			[['create_time', 'create_user', 'update_time', 'update_user', 'del_status'], 'integer'],
			[['lab_dept_code'], 'string', 'max' => 11],
			[['lab_spot_test','lab_subsequent_result', 'status'], 'string', 'max' => 1],			
			[['record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
		];
	}

	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
			'lab_id' => Yii::t('app', 'Lab ID'),
			'lab_dept_code' => Yii::t('app', 'Lab Department'),
			'lab_test_code' => Yii::t('app', 'Test Code'),
			'lab_test_name' => Yii::t('app', 'Test Name'),
			'lab_spot_test' => Yii::t('app', 'Spot Test'),
			'lab_subsequent_result' => Yii::t('app', 'Test should have subsequent result?'),
			'status' => Yii::t('app', 'Status'),
			'del_status' => Yii::t('app', 'Delete Status'),
            'create_time' => Yii::t('app', 'Last Updated Time'),
            'create_user' => Yii::t('app', 'Last Updated By'),
            'update_time' => Yii::t('app', 'Last Updated Time'),
            'update_user' => Yii::t('app', 'Last Updated By'),
		];
	}

    public function getDepartment()
    {
        $query = $this->hasOne(Departments::className(), ['lab_dept_code' => 'lab_dept_code']);
        return $query;
    }
}
