<?php

/**
 * This is the model class for table "aprobar_doc".
 *
 * The followings are the available columns in table 'aprobar_doc':
 * @property integer $aprobar_codigo
 * @property string $aprobar_estado
 * @property string $aprobar_fecha
 * @property integer $doc_codigo
 * @property integer $obs_codigo
 * @property string $fun_rut
 */
class AprobarDoc extends CActiveRecord
{
	
	public $fun_rut2;

	public function tableName()
	{
		return 'aprobar_doc';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('fun_rut', 'required'),
			array('doc_codigo, obs_codigo', 'numerical', 'integerOnly'=>true),
			array('aprobar_estado', 'length', 'max'=>100),
			array('fun_rut', 'length', 'max'=>12),
			array('aprobar_fecha', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('aprobar_codigo, aprobar_estado, aprobar_fecha, doc_codigo, obs_codigo, fun_rut', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array(
			'funcionario' => array(self::BELONGS_TO, 'Funcionario', 'fun_rut'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'aprobar_codigo' => 'Aprobar Codigo',
			'aprobar_estado' => 'Aprobar Estado',
			'aprobar_fecha' => 'Aprobar Fecha',
			'doc_codigo' => 'Doc Codigo',
			'obs_codigo' => 'Obs Codigo',
			'fun_rut' => 'Aprobador',
			'fun_rut2' => 'Aprobador',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('aprobar_codigo',$this->aprobar_codigo);
		$criteria->compare('aprobar_estado',$this->aprobar_estado,true);
		$criteria->compare('aprobar_fecha',$this->aprobar_fecha,true);
		$criteria->compare('doc_codigo',$this->doc_codigo);
		$criteria->compare('obs_codigo',$this->obs_codigo);
		$criteria->compare('fun_rut',$this->fun_rut,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public function getDbConnection()
	{
		return Yii::app()->db_gd;
	}
	
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
