<?php

class ClienteAlteracoesExternas extends GxActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return GxActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

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

	/**
	 * @return string label for item/items from model
	 */
	public static function label($n = 1) {
        return Yii::t('app', 'Alteração|Alterações', $n);
    }

    /**
	 * @return string the columns that represents this class
	 */
	public static function representingColumn() {
        return 'CAE_DESC';
    }

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('CAE_ID,CAE_IDCLIENTE,Clietne,CAE_MODEL,CAE_FOREIGN_KEY,CAE_FROM,CAE_TO,CAE_DATA,CAE_IDUSUARIO,Usuario,CAE_DESC,CAE_TITULO', 'safe')
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array(
			'Cliente' => array(self::BELONGS_TO, 'Clientes', 'CAE_IDCLIENTE', 'joinType' => 'LEFT JOIN'),
			'Usuario' => array(self::BELONGS_TO, 'FUncionarios', 'CAE_IDUSUARIO', 'joinType' => 'LEFT JOIN'),
		);
	}

	/**
	 * @return array customized attribute labels (name=&gt;label)
	 */
	public function attributeLabels()
	{
		return array(
			'CAE_ID' => 'Código',
			'CAE_IDCLIENTE' => 'Cliente',
			'Clietne' => 'Cliente',
			'CAE_MODEL' => 'Modelo',
			'CAE_FOREIGN_KEY' => 'Chave estranjeira',
			'CAE_FROM' => 'De',
			'CAE_TO' => 'Para',
			'CAE_DATA' => 'Data',
			'CAE_IDUSUARIO' => 'Usuário',
			'Usuario' => 'Usuário',
			'CAE_TITULO' => 'Título',
			'CAE_DESC' => 'Descrição',
			'CAE_UNDONE' => 'Desfeita?',
		);
	}

	public function getUndone() {
		return $this->CAR_UNDONE ? "Sim" : "Não";
	}

	public function setUndone() {
		$this->CAE_UNDONE = 1;
		$this->save(false, array('CAE_UNDONE'));
	}
}