git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_IntranetNueva/trunk@78 77cfc57b-8ef4-1849-9df6-4a38aa5da120
348 lines
14 KiB
PHP
348 lines
14 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This is the model class for table "tbl_candidatos".
|
|
*
|
|
* The followings are the available columns in table 'tbl_candidatos':
|
|
* @property integer $id
|
|
* @property integer $id_estado
|
|
* @property string $estado
|
|
* @property string $dni
|
|
* @property string $nombre
|
|
* @property string $apellidos
|
|
* @property string $email
|
|
* @property string $telefono_fijo
|
|
* @property string $telefono_movil
|
|
* @property string $sexo
|
|
* @property date $fecha_nacimiento
|
|
* @property string $lugar_nacimiento
|
|
* @property datetime $fecha_alta
|
|
* @property datetime $fecha_modificacion
|
|
* @property integer $usuario_alta
|
|
* @property integer $usuario_modificacion
|
|
* @property string $carnet_conducir
|
|
* @property string $vehiculo_propio
|
|
* @property text $observaciones
|
|
* @property integer $salario_minimo
|
|
* @property integer $salario_maximo
|
|
* @property string $procedencia
|
|
* @property string $disponibilidad_incorporacion
|
|
* @property string $disponibilidad_entrevistas
|
|
* @property string $disponibilidad_guardias
|
|
* @property string $disponibilidad_viajar
|
|
* @property string $disponibilidad_proyectos_internacionales
|
|
*
|
|
* The followings are the available model relations:
|
|
* @property CandidatoCapacidad[] $capacidades
|
|
* @property CandidatoIdioma[] $idiomas
|
|
* @property CandidatoTitulacion[] $titulaciones
|
|
* @property CandidatoDocumento[] $documentos
|
|
*/
|
|
class Candidato extends CActiveRecord
|
|
{
|
|
const GENERO_HOMBRE='Hombre';
|
|
const GENERO_MUJER='Mujer';
|
|
|
|
public $foto;
|
|
|
|
public $capacidad_tecnica_search;
|
|
public $nombre_estado_search;
|
|
public $nombreCompleto_search;
|
|
|
|
/**
|
|
* Devuelve el nombre completo de un candidato.
|
|
* @return string $nombreCompleto
|
|
*/
|
|
public function getNombreCompleto()
|
|
{
|
|
if(isset($this->nombreCompleto_search)) {
|
|
return $this->nombreCompleto_search;
|
|
}
|
|
|
|
$this->nombreCompleto_search = $this->nombre . ' ' . $this->apellidos;
|
|
return $this->nombreCompleto_search;
|
|
}
|
|
|
|
public function getRangoSalarial() {
|
|
return Yii::app()->numberFormatter->formatCurrency($this->salario_minimo,'EUR') . ' - ' .
|
|
Yii::app()->numberFormatter->formatCurrency($this->salario_maximo,'EUR');
|
|
}
|
|
|
|
public function getTieneVehiculoPropio() {
|
|
return Yii::app()->format->boolean($this->vehiculo_propio);
|
|
}
|
|
|
|
public function getNombreLocalidad() {
|
|
return Poblacion::model()->findByPk($this->localidad)->poblacion;
|
|
}
|
|
|
|
public function getNombreCompletoLocalidad() {
|
|
$nombre = '';
|
|
$poblacion = Poblacion::model()->with('provincia')->findByPk($this->localidad);
|
|
if (isset($poblacion)) {
|
|
$nombre = $poblacion->poblacion;
|
|
if (isset($poblacion->provincia)) {
|
|
$nombre .= ' (' . $poblacion->provincia->provincia . ')';
|
|
}
|
|
}
|
|
return $nombre;
|
|
}
|
|
|
|
/**
|
|
* Devuelve la lista de géneros de un candidato.
|
|
* @return array lista de géneros permitidos
|
|
*/
|
|
public function getOpcionesGenero() {
|
|
return array(
|
|
self::GENERO_HOMBRE => 'Hombre',
|
|
self::GENERO_MUJER => 'Mujer'
|
|
);
|
|
}
|
|
|
|
public function getCssClassEstado() {
|
|
return "estado" . array_search($this->id_estado, $this->opcionesEstado);
|
|
}
|
|
|
|
/**
|
|
* Devuelve la lista de estados permitidos para un candidato.
|
|
* @return array lista de estados permitidos
|
|
*/
|
|
public function getOpcionesEstado() {
|
|
return array(
|
|
0 => '510',
|
|
1 => '511',
|
|
2 => '520',
|
|
3 => '530',
|
|
4 => '540',
|
|
5 => '560',
|
|
6 => '600',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns the static model of the specified AR class.
|
|
* @param string $className active record class name.
|
|
* @return Candidato 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_candidatos';
|
|
}
|
|
|
|
/**
|
|
* @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('nombre, apellidos', 'required'),
|
|
array('email', 'unique'),
|
|
array('email', 'email'),
|
|
array('foto', 'file',
|
|
'types'=>'jpg',
|
|
'maxSize'=>1024 * 1024 * 1, // 1MB como máximo
|
|
'tooLarge'=>'The file was larger than 1MB. Please upload a smaller file.',
|
|
'wrongType'=>'Please upload only images in the format JPG.',
|
|
'tooMany'=>'You can upload only 1 user photo.',
|
|
'allowEmpty'=>'true',
|
|
),
|
|
array('salario_minimo, salario_maximo', 'numerical',
|
|
'allowEmpty'=>'true'),
|
|
|
|
array('dni, nombre, apellidos, email, telefono_fijo,
|
|
telefono_movil, sexo, lugar_nacimiento, localidad,
|
|
carnet_conducir, procedencia, disponibilidad_incorporacion,
|
|
disponibilidad_entrevistas, disponibilidad_guardias,
|
|
disponibilidad_viajar,
|
|
disponibilidad_proyectos_internacionales',
|
|
'length', 'max'=>255),
|
|
|
|
array('id_estado', 'numerical', 'integerOnly'=>true),
|
|
|
|
array('fecha_nacimiento, observaciones', 'safe'),
|
|
|
|
array('fecha_nacimiento', 'date', 'format'=>'dd/MM/yyyy'),
|
|
|
|
// The following rule is used by search().
|
|
// Please remove those attributes that should not be searched.
|
|
array('id, id_estado,
|
|
nombre_estado_search, nombreCompleto_search, capacidad_tecnica_search,
|
|
dni, email, telefono_fijo,
|
|
telefono_movil, sexo, fecha_nacimiento, lugar_nacimiento,
|
|
localidad, fecha_alta, usuario_alta,
|
|
usuario_modificacion, carnet_conducir, vehiculo_propio,
|
|
observaciones, salario_minimo, salario_maximo, procedencia,
|
|
disponibilidad_incorporacion, disponibilidad_entrevistas,
|
|
disponibilidad_guardias, disponibilidad_viajar,
|
|
disponibilidad_proyectos_internacionales',
|
|
'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(
|
|
'capacidades' => array(self::HAS_MANY, 'CandidatoCapacidad', 'candidato_id'),
|
|
'capacidadesCount' => array(self::STAT, 'CandidatoCapacidad', 'candidato_id'),
|
|
'idiomas' => array(self::HAS_MANY, 'CandidatoIdioma', 'candidato_id'),
|
|
'idiomasCount' => array(self::STAT, 'CandidatoIdioma', 'candidato_id'),
|
|
'titulaciones' => array(self::HAS_MANY, 'CandidatoTitulacion', 'candidato_id'),
|
|
'titulacionesCount' => array(self::STAT, 'CandidatoTitulacion', 'candidato_id'),
|
|
'documentos' => array(self::HAS_MANY, 'CandidatoDocumento', 'candidato_id'),
|
|
'documentosCount' => array(self::STAT, 'CandidatoDocumento', 'candidato_id'),
|
|
'estados'=>array( self::BELONGS_TO, 'EstadoCandidato', 'id_estado' ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array customized attribute labels (name=>label)
|
|
*/
|
|
public function attributeLabels()
|
|
{
|
|
return array(
|
|
'id' => 'ID',
|
|
'id_estado' => 'ID estado',
|
|
'nombre_estado_search' => 'Estado',
|
|
'nombreApellidos' => 'Candidato',
|
|
'foto' => 'Foto',
|
|
'dni' => 'DNI/Pasaporte',
|
|
'nombre' => 'Nombre',
|
|
'apellidos' => 'Apellidos',
|
|
'email' => 'Email',
|
|
'telefono_fijo' => 'Telefono fijo',
|
|
'telefono_movil' => 'Telefono móvil',
|
|
'sexo' => 'Sexo',
|
|
'fecha_nacimiento' => 'Fecha de nacimiento',
|
|
'lugar_nacimiento' => 'Lugar de nacimiento',
|
|
'localidad' => 'Localidad',
|
|
'fecha_modificacion' => 'Último cambio',
|
|
|
|
'carnet_conducir' => 'Carnet de conducir',
|
|
'vehiculo_propio' => 'Vehículo propio',
|
|
'observaciones' => 'Observaciones',
|
|
'salario_minimo' => 'Salario mínimo',
|
|
'salario_maximo' => 'Salario máximo',
|
|
'procedencia' => 'Procedencia',
|
|
'disponibilidad_incorporacion' => 'Disponibilidad de incorportación',
|
|
'disponibilidad_entrevistas' => 'Disponibilidad para entrevistas',
|
|
'disponibilidad_guardias' => 'Disponibilidad para guardias',
|
|
'disponibilidad_viajar' => 'Disponibilidad para viajar',
|
|
'disponibilidad_proyectos_internacionales' => 'Disponibilidad para proyectos internacionales',
|
|
|
|
'nombreCompleto_search' => 'Candidato',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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('capacidades', 'estados');//, 'capacidades.capacidadesFuncionales');
|
|
$criteria->together = true;
|
|
|
|
$criteria->compare('t.id',$this->id);
|
|
$criteria->compare('t.id_estado',$this->id_estado);
|
|
$criteria->compare( 'estados.descripcion', $this->nombre_estado_search, true );
|
|
|
|
$criteria->compare('t.dni',$this->dni,true);
|
|
$criteria->compare('t.email',$this->email,true);
|
|
$criteria->compare('t.telefono_fijo',$this->telefono_fijo,true);
|
|
$criteria->compare('t.telefono_movil',$this->telefono_movil,true);
|
|
|
|
$criteria->compare( 'concat(t.nombre, " ", t.apellidos)', $this->nombreCompleto_search, true );
|
|
$criteria->compare( 'capacidades.perfil_tecnico_id', $this->capacidad_tecnica_search, true );
|
|
|
|
$sort = new CSort();
|
|
$sort->attributes = array(
|
|
'defaultOrder' => '',
|
|
'nombre_estado_search'=>array(
|
|
'asc'=>'estados.descripcion',
|
|
'desc'=>'estados.descripcion DESC',
|
|
),
|
|
'fecha_modificacion' => array(
|
|
'asc' => 't.fecha_modificacion',
|
|
'desc' => 't.fecha_modificacion desc',
|
|
),
|
|
'nombreCompleto_search' => array(
|
|
'asc' => 'concat(t.nombre, " ", t.apellidos)',
|
|
'desc' => 'concat(t.nombre, " ", t.apellidos) desc',
|
|
),
|
|
'capacidad_tecnica_search' => array(
|
|
'asc' => 'capacidades.perfil_tecnico_id',
|
|
'desc' => 'capacidades.perfil_tecnico_id desc',
|
|
),
|
|
);
|
|
|
|
return new CActiveDataProvider($this, array(
|
|
'criteria' => $criteria,
|
|
'sort' => $sort,
|
|
));
|
|
}
|
|
|
|
protected function beforeValidate() {
|
|
if ($this->isNewRecord) {
|
|
$this->id_estado = 510;
|
|
$this->fecha_alta = date('Y-m-d H:i:s', time());
|
|
$this->fecha_modificacion = $this->fecha_alta;
|
|
$this->usuario_alta = Yii::app()->user->id;
|
|
$this->usuario_modificacion = Yii::app()->user->id;
|
|
}
|
|
else {
|
|
$this->fecha_modificacion = date('Y-m-d H:i:s', time());
|
|
$this->usuario_modificacion = Yii::app()->user->id;
|
|
}
|
|
|
|
return parent::beforeValidate();
|
|
}
|
|
|
|
protected function beforeSave()
|
|
{
|
|
//PHP dates are displayed as dd/mm/yyyy
|
|
//MYSQL dates are stored as yyyy-mm-dd
|
|
if ($this->fecha_nacimiento != '') {
|
|
$dateToMySQL=date('Y-m-d', CDateTimeParser::parse($this->fecha_nacimiento, Yii::app()->locale->dateFormat));
|
|
$this->fecha_nacimiento = $dateToMySQL;
|
|
}
|
|
|
|
parent::beforeSave();
|
|
return true;
|
|
}
|
|
|
|
protected function afterFind() {
|
|
//PHP dates are displayed as dd/mm/yyyy
|
|
//MYSQL dates are stored as yyyy-mm-dd
|
|
|
|
$dateToLocale=Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($this->fecha_nacimiento, 'yyyy-MM-dd'),'medium',null);
|
|
$this->fecha_nacimiento = $dateToLocale;
|
|
|
|
parent::afterFind();
|
|
return true;
|
|
}
|
|
|
|
public function behaviors() {
|
|
return array(
|
|
'LoggableBehavior'=> 'application.modules.auditTrail.behaviors.LoggableBehavior',
|
|
);
|
|
}
|
|
} |