<?php

namespace app\models;

use Yii;
use app\behaviours\ActiveRecordLogableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use app\models\Vll;

/**
 * This is the model class for table "{{%labdeptmaster}}".
 *
 * @property integer $artc_id
 * @property string $dept_code
 * @property string $occu_name
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 */
class Artcentre extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
	
	public $statusdum = [1 => "Y", 0 => "N", ""=>""];
		
    public static function tableName()
    {
        return 'artc_master';
    }
		
    /**
     * @inheritdoc
     */
	public function behaviors()
	{
		return [
			
			[
				'class' => TimestampBehavior::className(),
				'createdAtAttribute' => 'create_time',
				'updatedAtAttribute' => 'update_time',
				'value' => date('U'),
			],
		];
	}

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['district','artcname','artccode','vllcode','kms_from_vll','sample_collection_frequency','days_of_collection_month'], 'required'],
            		
			[['artccode'], 'unique', 'message' => '{attribute} Already Exists'],
			[['artcname'], 'unique', 'message' => '{attribute} Already Exists'],
			
			[['artccode'], 'string', 'max' =>50],			
			//[['artccode'], 'string', 'length' => 7, 'notEqual' => 'Must be {length} digits'],			
		
            [['kms_from_vll','sample_collection_frequency','days_of_collection_month','create_time', 'create_user', 'update_time', 'update_user'], 'integer'],		
          
        	[['status'], 'string', 'max' => 1],
			[['record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
        ];
    }
	
	
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [		   
            'district' => Yii::t('app', 'District'),
			'artcname'=> Yii::t('app', 'Name of the ART Centre'),
			'artccode'=> Yii::t('app', 'ART Centre Code'),
			'vllcode' => Yii::t('app', 'VL Lab Linked Code'),
			'kms_from_vll' => Yii::t('app', 'Kms from VL Lab'),
			'sample_collection_frequency' => Yii::t('app', 'Sample Collection Frequency'),
			'days_of_collection_month' => Yii::t('app', 'Days of collection per month'),
			
            'status' => Yii::t('app', 'Status'),
            'create_time' => Yii::t('app', 'Created Time'),
            'create_user' => Yii::t('app', 'Created By'),
            'update_time' => Yii::t('app', 'Last Updated Time'),
            'update_user' => Yii::t('app', 'Last Updated By'),
        ];
    }
	
	
	 public function getStatusdum()
	 {
		return $this->statusdum[$this->status];
		
	 }
	
	public function getDistrictmaster($id)
	{
		$Gmodel = \app\models\District::find()->where(["district" => $id])->one();
		if($Gmodel !== null) 
		    return $Gmodel->district;
		 else
			return "-";
	}	
	
}
