git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Web/trunk@64 3fe1ab16-cfe0-e34b-8c9f-7d8c168d430d
437 lines
16 KiB
PHP
437 lines
16 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 CandidatoCapacidad[] $capacidades
|
|
* @property CandidatoIdioma[] $idiomas
|
|
* @property CandidatoTitulacion[] $titulaciones
|
|
* @property CandidatoDocumento[] $documentos
|
|
*
|
|
* @package application.models
|
|
*
|
|
*/
|
|
|
|
class Candidato extends CActiveRecord {
|
|
|
|
const GENERO_HOMBRE = 'Hombre';
|
|
const GENERO_MUJER = 'Mujer';
|
|
|
|
public $ficheroFotografia;
|
|
public $fotografia;
|
|
|
|
public $capacidad_tecnica_search;
|
|
public $idiomas_search;
|
|
public $tecnologias_search;
|
|
public $funciones_search;
|
|
public $salario_ini_search;
|
|
public $salario_fin_search;
|
|
public $nombre_estado_search;
|
|
public $nombreCompleto_search;
|
|
|
|
/**
|
|
* @brief 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, email', 'required'),
|
|
array('email', 'unique'),
|
|
array('email', 'email'),
|
|
|
|
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('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,
|
|
idiomas_search, salario_ini_search, salario_fin_search,
|
|
tecnologias_search, funciones_search,
|
|
n_identificacion, 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() {
|
|
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',
|
|
'idiomas_search' => 'Idioma',
|
|
'nombreApellidos' => 'Candidato',
|
|
'foto' => 'Foto',
|
|
'n_identificacion' => 'DNI/Pasaporte',
|
|
'nombre' => 'Nombre',
|
|
'apellidos' => 'Apellidos',
|
|
'email' => 'Email',
|
|
'telefono_fijo' => 'Teléfono fijo',
|
|
'telefono_movil' => 'Teléfono móvil',
|
|
'sexo' => 'Sexo',
|
|
'fecha_nacimiento' => 'Fecha de nacimiento',
|
|
'lugar_nacimiento' => 'Lugar de nacimiento',
|
|
'localidad' => 'Localidad',
|
|
'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',
|
|
'observaciones' => 'Observaciones',
|
|
'tecnologias_search' => 'Tecnologías',
|
|
'funciones_search' => 'Perfiles funcionales',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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('id_estado', $this->id_estado);
|
|
$criteria->compare('n_identificacion', $this->n_identificacion, true);
|
|
$criteria->compare('nombre', $this->nombre, true);
|
|
$criteria->compare('apellidos', $this->apellidos, true);
|
|
$criteria->compare('email', $this->email, true);
|
|
$criteria->compare('telefono_fijo', $this->telefono_fijo, true);
|
|
$criteria->compare('telefono_movil', $this->telefono_movil, true);
|
|
$criteria->compare('sexo', $this->sexo, true);
|
|
$criteria->compare('localidad', $this->localidad, true);
|
|
$criteria->compare('fecha_nacimiento', $this->fecha_nacimiento, true);
|
|
$criteria->compare('lugar_nacimiento', $this->lugar_nacimiento, true);
|
|
$criteria->compare('created_time', $this->created_time, true);
|
|
$criteria->compare('modified_time', $this->modified_time, true);
|
|
$criteria->compare('deleted_time', $this->deleted_time, true);
|
|
$criteria->compare('carnet_conducir', $this->carnet_conducir, true);
|
|
$criteria->compare('vehiculo_propio', $this->vehiculo_propio);
|
|
$criteria->compare('observaciones', $this->observaciones, true);
|
|
$criteria->compare('salario_minimo', $this->salario_minimo);
|
|
$criteria->compare('salario_maximo', $this->salario_maximo);
|
|
$criteria->compare('procedencia', $this->procedencia, true);
|
|
$criteria->compare('disponibilidad_incorporacion', $this->disponibilidad_incorporacion, true);
|
|
$criteria->compare('disponibilidad_entrevistas', $this->disponibilidad_entrevistas, true);
|
|
$criteria->compare('disponibilidad_guardias', $this->disponibilidad_guardias, true);
|
|
$criteria->compare('disponibilidad_viajar', $this->disponibilidad_viajar, true);
|
|
$criteria->compare('disponibilidad_proyectos_internacionales', $this->disponibilidad_proyectos_internacionales, true);
|
|
|
|
$sort = new CSort();
|
|
$sort->attributes = array(
|
|
'defaultOrder' => 'id',
|
|
'nombreCompleto' => array(
|
|
'asc' => 'concat(t.nombre, " ", t.apellidos)',
|
|
'desc' => 'concat(t.nombre, " ", t.apellidos) desc',
|
|
),
|
|
);
|
|
return new CActiveDataProvider($this, array(
|
|
'criteria'=>$criteria,
|
|
//'sort' => $sort,
|
|
));
|
|
|
|
// $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',
|
|
// ),
|
|
// );
|
|
// echo $criteria->condition;
|
|
// return new CActiveDataProvider($this, array(
|
|
// 'criteria' => $criteria,
|
|
// 'sort' => $sort,
|
|
// ));
|
|
}
|
|
|
|
protected function beforeValidate() {
|
|
if ($this->isNewRecord) {
|
|
$this->id_estado = 510;
|
|
$this->created_time = date('Y-m-d H:i:s', time());
|
|
} else {
|
|
$this->modified_time = date('Y-m-d H:i:s', time());
|
|
}
|
|
|
|
return parent::beforeValidate();
|
|
}
|
|
|
|
protected function beforeSave() {
|
|
if ($this->isNewRecord)
|
|
$this->created_time = date("Y-m-d H:i:s");
|
|
|
|
/*if (($this->estado === self::ESTADO_BORRADO) && ($this->deleted_time === NULL))
|
|
$this->deleted_time = date("Y-m-d H:i:s");*/
|
|
|
|
//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;
|
|
}
|
|
|
|
return parent::beforeSave();
|
|
}
|
|
|
|
protected function afterFind() {
|
|
$this->fotografia = new FotografiaPerfil();
|
|
$this->fotografia->modelo = $this;
|
|
|
|
//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();
|
|
}
|
|
|
|
protected function afterSave() {
|
|
parent::afterSave();
|
|
if ($this->isNewRecord)
|
|
$this->createUploadDir();
|
|
}
|
|
|
|
protected function afterDelete() {
|
|
parent::afterDelete();
|
|
$this->deleteUploadDir();
|
|
}
|
|
|
|
protected function afterConstruct() {
|
|
parent::afterConstruct();
|
|
|
|
$this->fotografia = new FotografiaPerfil();
|
|
$this->fotografia->modelo = $this;
|
|
}
|
|
|
|
/**
|
|
* @brief Devuelve el nombre del fichero por defecto cuando no se tiene imagen
|
|
* @return string ruta
|
|
*/
|
|
public function getImagenDefault() {
|
|
return 'user_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;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|