Source

eqsupport / protected / models / TrazaIncidencia.php

Full commit
<?php

class TrazaIncidencia extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'eqsupport_trazaincidencia':
	 * @var integer $id
	 * @var string $fecha_ingreso
	 * @var integer $usuario_id
	 * @var integer $incidencia_id
	 * @var string $observacion
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord 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 'eqsupport_trazaincidencia';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('usuario_id, incidencia_id, observacion', 'required'),
		);
	}

	/**
	 * @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(
            'incidencia' =>array(self::BELONGS_TO, 'Incidencia', 'incidencia_id'),
            'usuario' =>array(self::BELONGS_TO, 'Usuario', 'usuario_id'),
		);
	}

    /**
     * Adding current date when an observation is created.
     **/

    protected function beforeSave()
    {
        if(parent::beforeSave())
        {
            if($this->isNewRecord)
                $this->fecha_ingreso=date('Y-m-d H:i:s');
            return true;
        }
        else
            return false;
    }

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id'=>'Id',
			'fecha_ingreso'=>'Fecha Ingreso',
			'usuario_id'=>'Usuario',
			'incidencia_id'=>'Incidencia',
			'observacion'=>'Observacion',
			'estado'=>'Estado',
		);
	}
}