<?php

/**
 * This is the model class for table "atas_aprovacoes_historico".
 *
 * The followings are the available columns in table 'atas_aprovacoes_historico':
 * @property integer $ATH_ID
 * @property integer $ATH_APROVACAO
 * @property integer $ATH_SITUACAO
 * @property string $ATH_DATA
 */
class AtasAprovacoesHistorico extends GxActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function beforeSave() {
		parent::beforeSave();

		if (strpos($this->ATH_DATA, '/') !== false) {
			$this->ATH_DATA = Util::formatDataHoraMysql($this->ATH_DATA);
		}
		return true;
	}

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

	public function behaviors() {
		return array('datetimeI18NBehavior' => array('class' => 'ext.DateTimeI18NBehavior'));
	}

	public static function label($n = 1) {
		return Yii::t('app', 'Aprovações de Atas', $n);
	}

	public static function representingColumn() {
		return 'ATH_ID';
	}

	public function rules()
	{
		return array(
			array('ATH_APROVACAO, ATH_SITUACAO, ATH_DATA', 'required'),
			array('ATH_APROVACAO, ATH_SITUACAO', 'numerical', 'integerOnly'=>true),

			array('ATH_ID, ATH_APROVACAO, ATH_SITUACAO, ATH_DATA', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
			'AtasAprovacoes'     => array(self::BELONGS_TO, 'AtasAprovacoes', 'ATH_APROVACAO'),
		);
	}

	public function attributeLabels()
	{
		return array(
			'ATH_ID' => 'Código',
			'ATH_APROVACAO' => 'Aprovação',
			'ATH_SITUACAO' => 'Situação',
			'ATH_DATA' => 'Data',
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('ATH_ID',$this->ATH_ID);
		$criteria->compare('ATH_APROVACAO',$this->ATH_APROVACAO);
		$criteria->compare('ATH_SITUACAO',$this->ATH_SITUACAO);
		$criteria->compare('ATH_DATA',$this->ATH_DATA,true);

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