<?php
/**
 * This is the model class for table "{{documentos}}".
 *
 * The followings are the available columns in table '{{documentos}}':
 * @property integer $id_documento
 * @property integer $id_tipo
 * @property string $titulo
 * @property string $autor
 * @property string $descripcion
 * @property string $url_issuu
 * @property string $archivo
 * @property integer $activo
 *
 * The followings are the available model relations:
 * @property TiposDocumentos $idTipo
 */
class Documentos extends CActiveRecord{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Documentos the static model class
	 */
	//$colaboradores = [];
	public static function model($className=__CLASS__){
		return parent::model($className);
	}
	/**
	 * @return string the associated database table name
	 */
	public function tableName(){
		return '{{documentos}}';
	}
	/**
	 * @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('id_tipo, titulo', 'required'),
			array('id_tipo, serie, vistas, descargas, activo', 'numerical', 'integerOnly'=>true),
			array('titulo, autor, descripcion_tw, url_issuu, url_issuu_img, url_youtube, archivo', 'length', 'max'=>300),
			array('descripcion, log, last_update', 'safe'),
			array('colaboradores', 'length', 'max'=>5000),
			//array('colaboradores', 'each', 'rule' => ['exist', 'targetClass' => Category::className(), 'targetAttribute' => 'id']),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_documento, id_tipo, titulo, autor, descripcion, url_issuu, url_youtube, archivo, log, vistas, descargas, activo', '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(
			'idTipo' => array(self::BELONGS_TO, 'TiposDocumentos', 'id_tipo'),
		);
	}
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels(){
		return array(
			'id_documento' => 'Documento',
			'id_tipo' => 'Tipo de documento',
			'titulo' => 'Título',
			'autor' => 'Autor',
			'descripcion' => 'Descripción',
			'url_issuu' => 'Url Issuu',
			'url_youtube' => 'Url Youtube',
			'archivo' => 'Archivo',
			'log' => 'Log',
			'last_update' => 'Last Update',
			'serie' => 'Orden en la serie',
			'vistas' => 'Visitas',
			'descargas' => 'Descargas',
			'activo' => 'Activo',
			'colaboradores' => 'Colaboradores',
			'url_issuu_img' => 'Enlace de la Imagen en Ussuu',
			'descripcion_tw' => 'Descripción en 150 Caracteres',
		);
	}
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search(){
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$criteria=new CDbCriteria;
		$criteria->compare('id_documento',$this->id_documento);
		$criteria->compare('id_tipo',$this->id_tipo);
		$criteria->compare('serie',$this->serie);
		$criteria->compare('titulo',$this->titulo,true);
		$criteria->compare('autor',$this->autor,true);
		$criteria->compare('descripcion',$this->descripcion,true);
		$criteria->compare('url_issuu',$this->url_issuu,true);
		$criteria->compare('archivo',$this->archivo,true);
		$criteria->compare('activo',$this->activo);
		$criteria->compare('colaboradores',$this->archivo,true);

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