<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%visitmaster}}".
 *
 * @property integer $id
 * @property string $visit_code
 * @property string $visit_name
 * @property integer $visit_interval
 * @property integer $visit_order
 * @property integer $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 * @property integer $record_date
 */
class Visitmaster extends \yii\db\ActiveRecord
{
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%visitmaster}}';
	}

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

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['visit_code', 'visit_name', 'visit_order'], 'required'],
			[['visit_interval', 'visit_order', 'status', 'create_time', 'create_user', 'update_time', 'update_user', 'record_date'], 'integer'],
			[['visit_code'], 'string', 'max' => 20],
			[['visit_name'], 'string', 'max' => 255],
			[['record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
		];
	}

	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
			'id' => Yii::t('app', 'ID'),
			'visit_code' => Yii::t('app', 'Visit Code'),
			'visit_name' => Yii::t('app', 'Visit Name'),
			'visit_interval' => Yii::t('app', 'Visit Interval'),
			'visit_order' => Yii::t('app', 'Visit Order'),
			'status' => Yii::t('app', 'Status'),
			'create_time' => Yii::t('app', 'Create Time'),
			'create_user' => Yii::t('app', 'Create User'),
			'update_time' => Yii::t('app', 'Update Time'),
			'update_user' => Yii::t('app', 'Update User'),
			'record_date' => Yii::t('app', 'Record Date'),
		];
	}
	
	public function getVisitname()
    {
        $query = $this->hasOne(Visitschedule::className(), ['visit_code' => 'visit_code']);
        return $query;
    }
}
