<?php

/**
 * This is the model class for table "funcionario_fiscalia".
 *
 * The followings are the available columns in table 'funcionario_fiscalia':
 * @property integer $funfis_codigo
 * @property string $fif_fun_fecha_ini
 * @property string $fif_fun_fecha_ter
 * @property string $fun_rut
 * @property string $fis_codigo
 */
class FuncionarioFiscalia extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'funcionario_fiscalia';
	}

	/**
	 * @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, fis_codigo', 'required'),
			array('fun_rut', 'length', 'max'=>12),
			array('fis_codigo', 'length', 'max'=>3),
			array('fif_fun_fecha_ini, fif_fun_fecha_ter', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('funfis_codigo, fif_fun_fecha_ini, fif_fun_fecha_ter, fun_rut, fis_codigo', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'fisNombre' => array(self::BELONGS_TO, 'Fiscalia', 'fis_codigo'),
			'funcionario' => array(self::BELONGS_TO, 'Funcionario', 'fun_rut'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'funfis_codigo' => 'Funfis Codigo',
			'fif_fun_fecha_ini' => 'Fif Fun Fecha Ini',
			'fif_fun_fecha_ter' => 'Fif Fun Fecha Ter',
			'fun_rut' => 'Fun Rut',
			'fis_codigo' => 'Fis Codigo',
		);
	}

	/**
	 * 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('funfis_codigo',$this->funfis_codigo);
		$criteria->compare('fif_fun_fecha_ini',$this->fif_fun_fecha_ini,true);
		$criteria->compare('fif_fun_fecha_ter',$this->fif_fun_fecha_ter,true);
		$criteria->compare('fun_rut',$this->fun_rut,true);
		$criteria->compare('fis_codigo',$this->fis_codigo,true);

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

	/**
	 * @return CDbConnection the database connection used for this class
	 */
	public function getDbConnection()
	{
		return Yii::app()->db_fr;
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return FuncionarioFiscalia the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
