<?php

/**
 * This is the model class for table "sidcai_certificado_error".
 *
 * The followings are the available columns in table 'sidcai_certificado_error':
 * @property integer $cert_erro_pk
 * @property string $cert_erro_descripcion
 * @property boolean $cert_habilitado
 *
 * The followings are the available model relations:
 * @property SidcaiCertificado[] $sidcaiCertificados
 */
class SidcaiCertificadoError extends CActiveRecord{
	public $motivo_rechazo;

	/**
	 * @return string the associated database table name
	 */
	public function tableName(){
		return 'sidcai_certificado_error';
	}

	/**
	 * @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(
				'motivo_rechazo', 'required', 'on' => 'cancelar_certificado'
			),
			array('cert_erro_descripcion', 'length', 'max'=>255),
			array('cert_habilitado', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('cert_erro_pk, cert_erro_descripcion, cert_habilitado', '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(
			'sidcaiCertificados' => array(self::HAS_MANY, 'SidcaiCertificado', 'cert_erro_fk'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels(){
		return array(
			'cert_erro_pk' => 'Código',
			'cert_erro_descripcion' => 'Descripción',
			'cert_habilitado' => 'Habilitado',
		);
	}

	/**
	 * 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 SidcaiCertificadoError the static model class
	 */
	public static function model($className=__CLASS__){
		return parent::model($className);
	}

	public static function obtenerErrores(){
		$errores = SidcaiCertificadoError::model()->findAll(
			array(
				'condition' => 'cert_habilitado = :cert_habilitado',
				'params' => array(':cert_habilitado' => true),
				'order' => 'cert_erro_descripcion'
			));
		return CHtml::listData($errores, 'cert_erro_pk', 'cert_erro_descripcion');
	}
}
