<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%ostvisit}}".
 *
 * @property integer $ost_visit_id
 * @property string $ost_visit_survey
 * @property string $ost_visit_part_id
 * @property string $ost_visit_q1
 * @property integer $ost_visit_q2
 * @property integer $ost_visit_q3
 * @property integer $ost_visit_q4
 * @property string $ost_visit_q5
 * @property string $ost_visit_q6
 * @property integer $ost_visit_q7
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 */
class Ostvisit extends \yii\db\ActiveRecord
{
	public $orgq2, $orgq3, $orgq4, $ischange;
	public $q3 = [1 => 'Client is traveling'];
	
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%ostvisit}}';
	}

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

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['ost_visit_survey', 'ost_visit_part_id', 'ost_visit_q1', 'ost_visit_q2', 'ost_visit_q3', 'ost_visit_q4', 'ost_visit_q5'], 'required', 'message' => 'Cannot be blank.'],
			[['ost_visit_q2', 'ost_visit_q3', 'ost_visit_q4', 'create_time', 'create_user', 'update_time', 'update_user'], 'integer', 'message' => 'Must be an integer'],
			[['ost_visit_part_id', 'ost_visit_q1', 'ost_visit_q2', 'ost_visit_q3', 'ost_visit_q4', 'ost_visit_q5'],  'safe'],
			[['ost_visit_q6'], 'required', 'message' => 'Cannot be blank.', 'when' => function ($model) {
				return $model->ischange == 1;
			}, 'whenClient' => "function (attribute, value) {
				return $('#ostvisit-ischange').val() == '1';
			}"],
			[['ost_visit_q5'], 'number', 'message' => 'Must be a Numeric'],
			[['ost_visit_survey', 'ost_visit_part_id'], 'string', 'max' => 11],
			[['ost_visit_q1'], 'string', 'max' => 25],
			[['ost_visit_q2', 'ost_visit_q3', 'ost_visit_q4'], 'string', 'max' => 3],
			[['ost_visit_q6'], 'string', 'max' => 100],
			[['ost_visit_q7'], 'safe'],
			[['status'], 'string', 'max' => 1],
			[['record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
		];
	}

	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
			'ost_visit_id' => Yii::t('app', 'Ost Visit ID'),
			'ost_visit_survey' => Yii::t('app', 'Survey'),
			'ost_visit_part_id' => Yii::t('app', 'ICC Client ID'),
			'ost_visit_q1' => Yii::t('app', '1. OST ID'),
			'ost_visit_q2' => Yii::t('app', '2. Quantity of 2mg pills'),
			'ost_visit_q3' => Yii::t('app', '3. Quantity of 0.4mg pills'),
			'ost_visit_q4' => Yii::t('app', '4. Quantity of 0.2mg pills'),
			'ost_visit_q5' => Yii::t('app', '5. Total daily dose, mg'),
			'ost_visit_q6' => Yii::t('app', '6. Reason for excess doses dispensed?'),
			'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'),
		];
	}
}
