<?php
/**
-
The followings are the available columns in table ‘fd_cargos’:
-
@property integer $id
-
@property string $cargo
-
@property integer $fd_niveis_id
-
@property integer $protegido
-
@property string $status
-
@property string $data_cadastro
*/
class Cargos extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @return Cargos 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 'fd_cargos';
}
/**
* @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('protegido', 'numerical', 'integerOnly'=>true),
array('fd_niveis_id','required'),
array('cargo', 'length', 'max'=>255),
array('status', 'length', 'max'=>7),
array('data_cadastro', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, cargo, fd_niveis_id, protegido, status, data_cadastro', '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(
'fd_niveis' => array(self::BELONGS_TO, 'Niveis', 'fd_niveis_id'),
'fd_operadores' => array(self::HAS_MANY, 'Operadores', 'fd_cargos_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'Id',
'cargo' => 'Cargo',
'fd_niveis_id' => 'Fd Niveis',
'protegido' => 'Protegido',
'status' => 'Status',
'data_cadastro' => 'Data Cadastro',
);
}
public function scopes(){
return array(
'ativo' => array('condition'=>'status = "ativo"'),
'nao_protegido' => array('condition'=>'protegido = false'),
'asc_cargo' => array('order'=>'cargo ASC'),
);
}
public function addCargo($model){
if( !$model->save() ){
throw new CDbException("Error");
}else{
return false;
}
}
/**
* 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',$this->id);
$criteria->compare('cargo',$this->cargo,true);
$criteria->compare('fd_niveis_id',$this->fd_niveis_id);
$criteria->compare('protegido',$this->protegido);
$criteria->compare('status',$this->status,true);
$criteria->compare('data_cadastro',$this->data_cadastro,true);
return new CActiveDataProvider('Cargos', array(
'criteria'=>$criteria,
));
}
}