<?php

namespace app\models;

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

/**
 * This is the model class for table "cms_demographics".
 *
 * The followings are the available columns in table 'cms_demographics':
 * @property integer $demographics_id
 * @property string $demographics_survey
 * @property string $demographics_part_id
 * @property string $demographics_loc
 * @property integer $demographics_q1
 * @property integer $demographics_q2
 * @property integer $demographics_q3
 * @property integer $demographics_q4
 * @property integer $demographics_q5
 * @property integer $demographics_q6
 * @property string $demographics_q7
 * @property integer $demographics_q8
 * @property integer $demographics_q9
 * @property integer $demographics_q10
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 */
 
class Demographicsfup extends \yii\db\ActiveRecord
{
	//public $yes_no = [0 => "No", 1 => "Yes"];
	//public $yes_no_dk = [0 => "No", 1 => "Yes", 997 => "Don't Know", 998 => "Refused"];
	public $q1 = [1 => "Male", 2 => "Female", 3 => "Hijra/Transgender"];
	public $q2 = [1 => 'Never Married', 2 => 'Currently Married', 3 => 'Widowed', 4 => 'Divorced', 5 => 'Separated'];
	public $q4 = [1 => 'No Schooling', 2 => 'Primary School (1 - 5)', 3 => 'Secondary school (6 - 11)', 4 => 'High School Graduate(12)', 5 => 'Vocational or trade school', 6 => 'College (not complete)', 7 => 'College (complete)', 8 => 'Post-graduate'];
	public $q5 = [1 => 'Unemployed', 2 => 'Daily wages', 3 => 'Weekly wages', 4 => 'Monthly wages', 997 => 'Don’t know', 998 => 'Refused'];
	Public $q7 = [1 => 'Own house / condominium / apartment / flat', 2 => 'Rent house / condominium / apartment / flat', 3 => 'Rent room in someone else’s house', 4 => 'Staying with family member(s)/parents', 5 => 'Stay with friend(s)/others', 6 => 'Staff quarters', 7 => 'Hostel/Dormitory', 8 => 'On the street, in a park, in a bus station, etc.', 9 => 'In a slum', 996 => 'Other'];
	public $q8 = [1 => '1 month or less', 2 => 'More than 1 month to 3 months', 3 => 'More than 3 months to 6 months', 4 => 'More than 6 months to 1 year', 5 => 'More than 1 year'];
	Public $q10 = [1 => 'Straight (heterosexual)', 2 => 'Kothi', 3 => 'Panthi', 4 => 'DD', 5 => 'Gay', 6 => 'Bisexual', 7 => 'Hijra', 8 => 'MSM', 9 => 'Lesbian', 996 => 'Other'];
    Public $visit;
	
	/**
	 * @inheritdoc
	 */
    public static function tableName()
	{
		return '{{%baseline_demographics}}';
	}

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

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			[['demographics_survey', 'demographics_loc','demographics_part_id',  'demographics_q2', 'demographics_q5','demographics_q6', 'demographics_q7', 'demographics_q8', 'demographics_q9', 'visit_code'], 'required', 'message' => 'Cannot be blank.'],
			[['demographics_q3', 'demographics_q6',  'demographics_q9', 'create_time', 'create_user', 'update_time', 'update_user'], 'integer', 'message' => 'Must be an integer'],		
			[['demographics_q3'], 'string', 'max' => 2],
			[['demographics_q9'], 'string', 'max' => 3],
			[['demographics_q3', 'demographics_q6',  'demographics_q9'], 'number', 'min' => 0, 'tooSmall' => 'Negative value not allowed'], 
			[['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 [
			'demographics_id' => Yii::t('app', 'Demographics ID'),
			'demographics_survey' => Yii::t('app', 'Survey'),
			'demographics_loc' => Yii::t('app', 'Location'),
			'demographics_part_id' => Yii::t('app', 'ICC Client ID'),
			
'visit_code' => Yii::t('app', 'Visit'),			
			'demographics_q2' => Yii::t('app', '1. What is your marital status?'),			
			'demographics_q5' => Yii::t('app', '2. What is your current employment status?'),
			'demographics_q6' => Yii::t('app', '3. What is your personal monthly income in rupees?'),
			'demographics_q7' => Yii::t('app', '4. In what type of place do you currently live?'),
			'demographics_q8' => Yii::t('app', '5. How long have you been living where you currently live?'),
			'demographics_q9' => Yii::t('app', '6. How many individuals live in your household, not counting yourself? By household, I mean children or adults (not including yourself) who sleep in the household at least two nights or more every week.'),			
			'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'),
		];
	}

 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 "-";
	}	
}