git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Web/trunk@80 3fe1ab16-cfe0-e34b-8c9f-7d8c168d430d
515 lines
20 KiB
PHP
515 lines
20 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @class Candidato
|
|
* @brief Modelo de la tabla "tbl_candidatos".
|
|
*
|
|
* @property integer $id
|
|
* @property integer $id_estado
|
|
* @property string $n_identificacion
|
|
* @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 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
|
|
* @property datetime $created_time
|
|
* @property datetime $modified_time
|
|
* @property datetime $deleted_time
|
|
*
|
|
* @property string $ficheroFotografia
|
|
* @property FotografiaPerfil $fotografia
|
|
*
|
|
* @property EstadoCandidato $estado
|
|
* @property CandidatoIdioma[] $idiomas
|
|
* @property CandidatoTitulacion[] $titulaciones
|
|
* @property CandidatoAreaFuncional[] $areasFuncionales
|
|
* @property CandidatoCapacidadProfesional[] $capacidadesProfesionales
|
|
* @property CandidatoDocumento[] $documentos
|
|
*
|
|
* @package application.models
|
|
*
|
|
*/
|
|
class Candidato extends CActiveRecord {
|
|
|
|
const GENERO_HOMBRE = 'Hombre';
|
|
const GENERO_MUJER = 'Mujer';
|
|
|
|
public $ficheroFotografia;
|
|
public $fotografia;
|
|
public $descripcionEstado;
|
|
public $salario_ini_search;
|
|
public $salario_fin_search;
|
|
public $idiomas_search;
|
|
public $titulaciones_search;
|
|
public $perfiles_search;
|
|
public $desarrollos_search;
|
|
public $pruebas_search;
|
|
public $sistemas_search;
|
|
public $consultorias_search;
|
|
public $tipos_search;
|
|
|
|
private $_nombreCompleto;
|
|
|
|
|
|
|
|
/**
|
|
* @brief Devuelve el nombre completo de un candidato.
|
|
* @return string $nombreCompleto
|
|
*/
|
|
public function getNombreCompleto() {
|
|
|
|
if (isset($this->_nombreCompleto)) {
|
|
return $this->_nombreCompleto;
|
|
}
|
|
$this->_nombreCompleto = $this->nombre . ' ' . $this->apellidos;
|
|
return $this->_nombreCompleto;
|
|
}
|
|
|
|
public function setNombreCompleto($value) {
|
|
$this->_nombreCompleto = $value;
|
|
}
|
|
|
|
/**
|
|
* 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'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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, email', 'required'),
|
|
array('email', 'unique'),
|
|
array('email', 'email'),
|
|
|
|
array('id_estado', 'numerical', 'integerOnly' => true),
|
|
array('id_estado', 'default', 'value' => Candidato::darIdEstadoInicial()),
|
|
|
|
array('ficheroFotografia', 'file',
|
|
'types' => 'jpg',
|
|
'maxSize' => 1024 * 1024 * 1, // 1MB como máximo
|
|
'tooLarge' => Yii::t('profind', 'La imagen es demasiado pesada. Elija otra fotografía más pequeña.'),
|
|
'wrongType' => Yii::t('profind', 'Sólo se permiten imágenes en formato JPG.'),
|
|
'allowEmpty' => 'true',
|
|
),
|
|
|
|
array('salario_minimo, salario_maximo', 'numerical', 'allowEmpty' => 'true'),
|
|
array('salario_minimo', 'default', 'value' => Yii::app()->params['salarios_candidatos']['salario_minimo']),
|
|
array('salario_maximo', 'default', 'value' => Yii::app()->params['salarios_candidatos']['salario_maximo']),
|
|
|
|
array('n_identificacion, 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('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, estado, descripcionEstado, nombre, apellidos, nombreCompleto,
|
|
n_identificacion, email, telefono_fijo,
|
|
salario_ini_search, salario_fin_search, idiomas_search, titulaciones_search,
|
|
|
|
perfiles_search, desarrollos_search, pruebas_search, sistemas_search, consultorias_search, tipos_search;
|
|
|
|
telefono_movil, sexo, fecha_nacimiento, lugar_nacimiento,
|
|
localidad, 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() {
|
|
return array(
|
|
'estado' => array(self::BELONGS_TO, 'EstadoCandidato', 'id_estado'),
|
|
|
|
'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'),
|
|
|
|
'areasFuncionales' => array(self::HAS_MANY, 'CandidatoAreaFuncional', 'id_candidato'),
|
|
'areasFuncionalesCount' => array(self::STAT, 'CandidatoAreaFuncional', 'id_candidato'),
|
|
|
|
'capacidadesProfesionales' => array(self::HAS_MANY, 'CandidatoCapacidadProfesional', 'id_candidato'),
|
|
'capacidadesProfesionalesCount' => array(self::STAT, 'CandidatoCapacidadProfesional', 'id_candidato'),
|
|
|
|
'documentos' => array(self::HAS_MANY, 'CandidatoDocumento', 'id_candidato'),
|
|
'documentosCount' => array(self::STAT, 'CandidatoDocumento', 'id_candidato'),
|
|
);
|
|
}
|
|
|
|
public function scopes() {
|
|
return array(
|
|
'disponibles' => array(
|
|
'condition' => 'id_estado = 1',
|
|
),
|
|
'no_disponibles' => array(
|
|
'condition' => 'id_estado = 2',
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @brief Busca el ID del estado inicial de un candidato.
|
|
* @return integer
|
|
*/
|
|
public static function darIdEstadoInicial() {
|
|
$estado = EstadoCandidato::model()->predeterminado()->find();
|
|
if ($estado === null) {
|
|
Yii::log('No se ha encontrado un estado inicial para el candidato', CLogger::LEVEL_ERROR, 'application.controller.CandidatoController');
|
|
throw new CHttpException(500, Yii::t('profind', 'Error interno. No se ha encontrado un estado inicial para el candidato'));
|
|
}
|
|
return $estado->id;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return array customized attribute labels (name=>label)
|
|
*/
|
|
public function attributeLabels() {
|
|
return array(
|
|
'id' => 'ID',
|
|
'id_estado' => 'Estado',
|
|
'descripcionEstado' => 'Estado',
|
|
'n_identificacion' => 'DNI/Pasaporte',
|
|
'nombre' => 'Nombre',
|
|
'apellidos' => 'Apellidos',
|
|
'sexo' => 'Sexo',
|
|
'localidad' => 'Localidad',
|
|
'email' => 'Email',
|
|
'telefono_fijo' => 'Teléfono fijo',
|
|
'telefono_movil' => 'Teléfono móvil',
|
|
'fecha_nacimiento' => 'Fecha de nacimiento',
|
|
'lugar_nacimiento' => 'Lugar de nacimiento',
|
|
'carnet_conducir' => 'Carnet de conducir',
|
|
'vehiculo_propio' => 'Vehículo propio',
|
|
'procedencia' => 'Procedencia',
|
|
'observaciones' => 'Observaciones',
|
|
'salario_minimo' => 'Salario mínimo',
|
|
'salario_maximo' => 'Salario máximo',
|
|
'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',
|
|
'observaciones' => 'Observaciones',
|
|
'modified_time' => 'Modificación',
|
|
'idiomas_search' => 'Idiomas',
|
|
'titulaciones_search' => 'Titulaciones',
|
|
'perfiles_search' => 'Perfil',
|
|
'desarrollos_search' => 'Desarrollo',
|
|
'pruebas_search' => 'Pruebas e integración',
|
|
'sistemas_search' => 'Sistemas',
|
|
'consultorias_search' => 'Consultoría',
|
|
'tipos_search' => 'Tipos de aplicación',
|
|
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
|
|
if ($this->descripcionEstado) {
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'estado');
|
|
$criteria->compare('estado.id', $this->id_estado, true);
|
|
$criteria->compare('estado.descripcion', $this->descripcionEstado, true);
|
|
}
|
|
|
|
$criteria->compare('t.id', $this->id);
|
|
|
|
$criteria->compare('t.id_estado', $this->id_estado);
|
|
|
|
$criteria->compare('t.n_identificacion', $this->n_identificacion, true);
|
|
$criteria->compare('t.nombre', $this->nombre, true);
|
|
$criteria->compare('t.apellidos', $this->apellidos, true);
|
|
$criteria->compare( 'concat(t.nombre, " ", t.apellidos)', $this->_nombreCompleto, true );
|
|
$criteria->compare('t.sexo', $this->sexo, true);
|
|
$criteria->compare('t.localidad', $this->localidad, true);
|
|
|
|
$criteria->compare( 'concat(t.nombre, " ", t.apellidos)', $this->_nombreCompleto, 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('t.fecha_nacimiento', $this->fecha_nacimiento, true);
|
|
$criteria->compare('t.lugar_nacimiento', $this->lugar_nacimiento, true);
|
|
|
|
$criteria->compare('t.carnet_conducir', $this->carnet_conducir, true);
|
|
$criteria->compare('t.vehiculo_propio', $this->vehiculo_propio);
|
|
|
|
$criteria->compare('t.observaciones', $this->observaciones, true);
|
|
|
|
$criteria->compare('t.salario_minimo', $this->salario_minimo);
|
|
$criteria->compare('t.salario_maximo', $this->salario_maximo);
|
|
|
|
$criteria->compare('t.procedencia', $this->procedencia, true);
|
|
|
|
$criteria->compare('t.disponibilidad_incorporacion', $this->disponibilidad_incorporacion, true);
|
|
$criteria->compare('t.disponibilidad_entrevistas', $this->disponibilidad_entrevistas, true);
|
|
$criteria->compare('t.disponibilidad_guardias', $this->disponibilidad_guardias, true);
|
|
$criteria->compare('t.disponibilidad_viajar', $this->disponibilidad_viajar, true);
|
|
$criteria->compare('t.disponibilidad_proyectos_internacionales', $this->disponibilidad_proyectos_internacionales, true);
|
|
|
|
$criteria->compare('t.created_time', $this->created_time, true);
|
|
$criteria->compare('t.modified_time', $this->modified_time, true);
|
|
$criteria->compare('t.deleted_time', $this->deleted_time, true);
|
|
|
|
if ($this->salario_ini_search != '')
|
|
$criteria->addCondition(('t.salario_minimo >='. $this->salario_ini_search));
|
|
if ($this->salario_fin_search != '')
|
|
$criteria->addCondition(('t.salario_minimo <='. $this->salario_fin_search));
|
|
|
|
if (($this->idiomas_search != '') && ($this->idiomas_search[0] != '')){
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'idiomas');
|
|
$cadena = '';
|
|
foreach ($this->idiomas_search as $idioma_search){
|
|
if ($cadena != '')
|
|
$cadena = $cadena . ',';
|
|
$cadena = $cadena . "'" . $idioma_search . "'";
|
|
}
|
|
$criteria->addCondition(('idiomas.idioma in ('. $cadena . ')'));
|
|
}
|
|
|
|
if (($this->titulaciones_search != '') && ($this->titulaciones_search[0] != '')){
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'titulaciones');
|
|
$cadena = '';
|
|
foreach ($this->titulaciones_search as $titulacion_search){
|
|
if ($cadena != '')
|
|
$cadena = $cadena . ',';
|
|
$cadena = $cadena . "'" . $titulacion_search . "'";
|
|
}
|
|
$criteria->addCondition(('titulaciones.titulacion in ('. $cadena . ')'));
|
|
}
|
|
|
|
$cadena = '';
|
|
if (($this->perfiles_search != '') && ($this->perfiles_search[0] != '')){
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'capacidadesProfesionales');
|
|
foreach ($this->perfiles_search as $perfil_search){
|
|
if ($cadena != '')
|
|
$cadena = $cadena . ',';
|
|
$cadena = $cadena . "'" . $perfil_search . "'";
|
|
}
|
|
}
|
|
if (($this->desarrollos_search != '') && ($this->desarrollos_search[0] != '')){
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'capacidadesProfesionales');
|
|
foreach ($this->desarrollos_search as $desarrollo_search){
|
|
if ($cadena != '')
|
|
$cadena = $cadena . ',';
|
|
$cadena = $cadena . "'" . $desarrollo_search . "'";
|
|
}
|
|
}
|
|
if (($this->pruebas_search != '') && ($this->pruebas_search[0] != '')){
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'capacidadesProfesionales');
|
|
foreach ($this->pruebas_search as $prueba_search){
|
|
if ($cadena != '')
|
|
$cadena = $cadena . ',';
|
|
$cadena = $cadena . "'" . $prueba_search . "'";
|
|
}
|
|
}
|
|
if (($this->sistemas_search != '') && ($this->sistemas_search[0] != '')){
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'capacidadesProfesionales');
|
|
foreach ($this->sistemas_search as $sistema_search){
|
|
if ($cadena != '')
|
|
$cadena = $cadena . ',';
|
|
$cadena = $cadena . "'" . $sistema_search . "'";
|
|
}
|
|
}
|
|
if (($this->consultorias_search != '') && ($this->consultorias_search[0] != '')){
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'capacidadesProfesionales');
|
|
foreach ($this->consultorias_search as $consultoria_search){
|
|
if ($cadena != '')
|
|
$cadena = $cadena . ',';
|
|
$cadena = $cadena . "'" . $consultoria_search . "'";
|
|
}
|
|
}
|
|
if (($this->tipos_search != '') && ($this->tipos_search[0] != '')){
|
|
$criteria->together = true;
|
|
array_push($criteria->with, 'capacidadesProfesionales');
|
|
foreach ($this->tipos_search as $tipo_search){
|
|
if ($cadena != '')
|
|
$cadena = $cadena . ',';
|
|
$cadena = $cadena . "'" . $tipo_search . "'";
|
|
}
|
|
}
|
|
|
|
if ($cadena != '')
|
|
$criteria->addCondition(('capacidadesProfesionales.id_capacidad in ('. $cadena . ')'));
|
|
|
|
|
|
$sort = new CSort();
|
|
$sort->modelClass = 'Candidato';
|
|
$sort->attributes = array(
|
|
'*',
|
|
'defaultOrder' => 'id',
|
|
'descripcionEstado' => array(
|
|
'asc' => 'estado.descripcion',
|
|
'desc' => 'estado.descripcion desc',
|
|
),
|
|
'nombreCompleto' => array(
|
|
'asc' => 'concat(t.nombre, " ", t.apellidos)',
|
|
'desc' => 'concat(t.nombre, " ", t.apellidos) desc',
|
|
),
|
|
);
|
|
|
|
return new CActiveDataProvider($this, array(
|
|
'criteria' => $criteria,
|
|
'sort' => $sort,
|
|
));
|
|
}
|
|
|
|
protected function beforeSave() {
|
|
$this->fecha_nacimiento = date('Y-m-d', CDateTimeParser::parse($this->fecha_nacimiento, Yii::app()->locale->dateFormat));
|
|
|
|
if ($this->isNewRecord)
|
|
$this->created_time = date("Y-m-d H:i:s");
|
|
else
|
|
$this->modified_time = date("Y-m-d H:i:s");
|
|
|
|
return parent::beforeSave();
|
|
}
|
|
|
|
protected function afterFind() {
|
|
$this->fotografia = new FotografiaPerfil();
|
|
$this->fotografia->modelo = $this;
|
|
$this->fecha_nacimiento = Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($this->fecha_nacimiento, 'yyyy-MM-dd'), 'medium', null);
|
|
return parent::afterFind();
|
|
}
|
|
|
|
protected function afterConstruct() {
|
|
parent::afterConstruct();
|
|
$this->fotografia = new FotografiaPerfil();
|
|
$this->fotografia->modelo = $this;
|
|
}
|
|
|
|
protected function afterValidate() {
|
|
parent::afterValidate();
|
|
}
|
|
|
|
protected function afterSave() {
|
|
parent::afterSave();
|
|
$this->fecha_nacimiento = Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($this->fecha_nacimiento, 'yyyy-MM-dd'), 'medium', null);
|
|
if ($this->isNewRecord)
|
|
$this->createUploadDir();
|
|
}
|
|
|
|
protected function afterDelete() {
|
|
parent::afterDelete();
|
|
$this->deleteUploadDir();
|
|
}
|
|
|
|
/**
|
|
* @brief Devuelve el nombre del fichero por defecto cuando no se tiene imagen
|
|
* @return string ruta
|
|
*/
|
|
public function getImagenDefault() {
|
|
return 'candidate_photo.jpg';
|
|
}
|
|
|
|
/**
|
|
* @brief Devuelve la ruta con los ficheros del usuario.
|
|
* Incluye el separador de directorios al final de la ruta.
|
|
* @return string ruta
|
|
*/
|
|
public function getUploadPath() {
|
|
return Yii::getPathOfAlias('application.uploads.candidatos') . DIRECTORY_SEPARATOR . $this->id . DIRECTORY_SEPARATOR;
|
|
}
|
|
|
|
/**
|
|
* @brief Crea un directorio para almacenar ficheros del usuario
|
|
* @return boolean
|
|
*/
|
|
private function createUploadDir() {
|
|
$upload = $this->getUploadPath();
|
|
|
|
if (!is_dir($upload)) {
|
|
return mkdir($upload);
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @brief Elimina el directorio del usuario y todos sus ficheros
|
|
* @return boolean
|
|
*/
|
|
private function deleteUploadDir() {
|
|
$upload = $this->getUploadPath();
|
|
|
|
if (is_dir($upload))
|
|
return GHelper::recursiveRemoveDirectory($upload);
|
|
else
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|