<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use app\base\Converter;

/**
 * This is the model class for table "cms_baseline_preartbeliefs".
 *
 * The followings are the available columns in table 'cms_baseline_preartbeliefs':
 * @property integer $pre_art_beliefs_id
 * @property string $pre_art_beliefs_survey
 * @property string $pre_art_beliefs_part_id
 * @property integer $pre_art_beliefs_q1
 * @property integer $pre_art_beliefs_q2
 * @property integer $pre_art_beliefs_q3
 * @property integer $pre_art_beliefs_q4
 * @property integer $pre_art_beliefs_q5
 * @property integer $pre_art_beliefs_q6
 * @property integer $pre_art_beliefs_q7
 * @property integer $pre_art_beliefs_q8
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 */
 
class Preartbeliefs extends \yii\db\ActiveRecord
{
	public $agree = [1 => "Strongly Disagree", 2 => "Disagree", 3 => "Neither Agree Nor Disagree", 4 => "Agree", 5 => "Strongly Agree"];
	Public $visit;
	
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%baseline_preartbeliefs}}';
	}

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

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['pre_art_beliefs_survey', 'pre_art_beliefs_loc','pre_art_beliefs_part_id', 'pre_art_beliefs_q1', 'pre_art_beliefs_q2', 'pre_art_beliefs_q3', 'pre_art_beliefs_q4', 'pre_art_beliefs_q5','pre_art_beliefs_q6','pre_art_beliefs_q7','pre_art_beliefs_q8','visit_code'], 'required', 'message' => 'Cannot be blank.'],
			[['create_time', 'create_user', 'update_time', 'update_user'], 'integer', 'message' => 'Must be an integer'],	
            [['visit_code'], 'integer', 'message' => 'Must be an integer'],			
			[['status'], 'string', 'max' => 1],
			[['record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
			
				];
	}

	
	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
			'pre_art_beliefs_id' => Yii::t('app', 'Preartbeliefs ID'),
			'pre_art_beliefs_survey' => Yii::t('app', 'Survey'),
			'pre_art_beliefs_loc' => Yii::t('app', 'Location'),
			'pre_art_beliefs_part_id' => Yii::t('app', 'ICC Client ID'),
			
'visit_code' => Yii::t('app', 'Visit'),
			'pre_art_beliefs_q1' => Yii::t('app', '1. People with HIV only need to take HIV medicines after they get sick.'),
			'pre_art_beliefs_q2' => Yii::t('app', '2. HIV medicines help people to live longer.'),
			'pre_art_beliefs_q3' => Yii::t('app', '3. When you start HIV medications, you need to take them for the rest of your life.'),
			'pre_art_beliefs_q4' => Yii::t('app', '4. HIV medicines have side effects and make people sick.'),
			'pre_art_beliefs_q5' => Yii::t('app', '5. Many people with HIV can do fine without taking medicines.'),
			'pre_art_beliefs_q6' => Yii::t('app', '6. I don’t want to go to the HIV clinic or take HIV medicines because then people may find out that I have HIV.'),
			'pre_art_beliefs_q7' => Yii::t('app', '7. Treating my HIV infection is a very high priority for me.'),
			'pre_art_beliefs_q8' => Yii::t('app', '8. When the time comes to take HIV medicine, I know I will get a lot of support from family or friends.'),
			
			'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 getVisits($id)
	{
		$Gmodel = \app\models\Visitmaster::find()->where(['NOT', ['visit_interval' => null]])->andWhere(["status" => 1])->andWhere(["visit_code" => $id])->one();
		if($Gmodel !== null) {			
				return $Gmodel->visit_name;
		} else
			return "-";
	}	
}