estado == self::ESTADO_ACTIVO); } /** * Returns the static model of the specified AR class. * @param string $className active record class name. * @return Usuario 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 'tbl_usuarios'; } /** * @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('email, nombre, apellidos, titulo, localidad, telefono', 'length', 'max' => 255), array('email', 'required'), array('email', 'email'), array('email', 'unique'), array('password', 'required', 'on' => 'insert'), array('id, id_empresa, email, nombre, apellidos, titulo, localidad, telefono', '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( 'empresa' => array(self::HAS_ONE, 'Empresa', 'id'), ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'email' => 'Email', 'estado' => 'Estado', 'password' => 'Contraseña', 'password_repeat' => 'Confirmar contraseña', 'last_login_time' => 'Último acceso', 'nombre' => 'Nombre', 'apellidos' => 'Apellidos', 'titulo' => 'Titulo', 'localidad' => 'Localidad', 'telefono' => 'Teléfono', 'descripcion' => 'Descripción', ); } public function scopes() { return array( 'activo' => array( 'condition' => 'estado=' . self::ESTADO_ACTIVO ), 'noactivo' => array( 'condition' => 'estado=' . self::ESTADO_NOACTIVO ), 'denegado' => array( 'condition' => 'estado=' . self::ESTADO_DENEGADO ) ); } /** * 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->with = array('empresa'); //$criteria->together = true; $criteria->compare('t.email', $this->email, true); $criteria->compare('t.id_empresa', $this->id_empresa, true); $criteria->compare('t.nombre', $this->nombre, true); $criteria->compare('t.apellidos', $this->apellidos, true); $criteria->compare('t.last_login_time', $this->last_login_time, true); $sort = new CSort; $sort->defaultOrder = 't.apellidos, t.nombre ASC'; return new CActiveDataProvider($this, array( 'criteria' => $criteria, 'sort' => $sort, )); } public function encrypt($value) { return md5($value); } }