diff --git a/www/images/candidate_photo.jpg b/www/images/candidate_photo.jpg new file mode 100644 index 0000000..af73630 Binary files /dev/null and b/www/images/candidate_photo.jpg differ diff --git a/www/protected/config/mode_development.php b/www/protected/config/mode_development.php index 3bc54b2..ac55eda 100644 --- a/www/protected/config/mode_development.php +++ b/www/protected/config/mode_development.php @@ -35,6 +35,8 @@ $configSpecific = array( 'password' => '', 'charset' => 'utf8', 'tablePrefix' => '', + 'emulatePrepare' => true, + 'enableProfiling' => true, 'enableParamLogging' => true, ), 'mail' => array( diff --git a/www/protected/controllers/CandidatoController.php b/www/protected/controllers/CandidatoController.php index 3bd1ddd..5f6d405 100644 --- a/www/protected/controllers/CandidatoController.php +++ b/www/protected/controllers/CandidatoController.php @@ -55,8 +55,7 @@ class CandidatoController extends Controller { // $this->performAjaxValidation($model); if (isset($_POST['Candidato'])) { - $candidato->attributes = $_POST['Candidato']; - if ($candidato->save()) + if ($this->saveModel($candidato)) $this->redirect(array('index')); } @@ -76,128 +75,8 @@ class CandidatoController extends Controller { // $this->performAjaxValidation($candidato); if (isset($_POST['Candidato'])) { - Yii::trace(CVarDumper::dumpAsString($_POST)); - - // Candidato - $candidato->attributes = $_POST['Candidato']; - $ficheroFotografia = CUploadedFile::getInstance($candidato, 'ficheroFotografia'); - $quitarFotografia = Yii::app()->request->getParam('quitar_fotografia', '0'); - - // Titulaciones del candidato - $listaTitulacionesBorrar = $candidato->titulaciones; - if (isset($_POST['CandidatoTitulacion'])) { - $listaTitulaciones = array(); - foreach ($_POST['CandidatoTitulacion'] as $titulacion) { - $candidatoTitulacion = new CandidatoTitulacion(); - $candidatoTitulacion->titulacion = $titulacion; - $candidatoTitulacion->candidato_id = $candidato->id; - $listaTitulaciones[] = $candidatoTitulacion; - } - $candidato->titulaciones = $listaTitulaciones; - } - - // Idiomas del candidato - $listaIdiomasBorrar = array(); - if (isset($_POST['CandidatoIdioma'])) { - $listaIdiomas = array(); - foreach ($_POST['CandidatoIdioma'] as $key => $idioma) { - if ($idioma['id']) - $candidatoIdioma = CandidatoIdioma::model()->findByPk($idioma['id']); - else - $candidatoIdioma = new CandidatoIdioma(); - $candidatoIdioma->attributes = $idioma; - $candidatoIdioma->candidato_id = $candidato->id; - - if ($idioma['_borrar']) - $listaIdiomasBorrar[] = $candidatoIdioma; - else - $listaIdiomas[] = $candidatoIdioma; - } - $candidato->idiomas = $listaIdiomas; - } - - // Guardar los datos - $errores = array(); - $transaccion = Yii::app()->db->beginTransaction(); - try { - Yii::trace('Guardando el candidato', 'application.controllers.CandidatoController'); - if (!$candidato->save()) { - $errores = array_merge($errores, $candidato->getErrors()); - throw new CException('Error al guardar el candidato'); - } - - if (($quitarFotografia == '1') && ($candidato->fotografia->tieneFotografia())) { - Yii::trace('Eliminando la fotografía del candidato', 'application.controllers.CandidatoController'); - $candidato->fotografia->eliminarFotografia(); - } - - if ($ficheroFotografia) { - Yii::trace('Guardando la fotografía del candidato', 'application.controllers.CandidatoController'); - $candidato->fotografia->guardarFotografia($ficheroFotografia); - } - - // Titulaciones - if (!empty($listaTitulacionesBorrar)) { - Yii::trace('Eliminando titulaciones marcadas para borrar', 'application.controllers.CandidatoController'); - foreach ($listaTitulacionesBorrar as $candidatoTitulacion) { - if (!$candidatoTitulacion->delete()) { - $errores = array_merge($errores, $candidatoTitulacion->getErrors()); - throw new CException('Error al eliminar una titulación del candidato'); - } - } - $listaTitulacionesBorrar = NULL; - } - if (!empty($candidato->titulaciones)) { - Yii::trace('Guardando la lista de titulaciones', 'application.controllers.CandidatoController'); - foreach ($candidato->titulaciones as $candidatoTitulacion) { - if (!$candidatoTitulacion->save()) { - $errores = array_merge($errores, $candidatoTitulacion->getErrors()); - throw new CException('Error al guardar una titulación del candidato'); - } - } - } - - // Idiomas - if (!empty($listaIdiomasBorrar)) { - Yii::trace('Eliminando idiomas marcados para borrar', 'application.controllers.CandidatoController'); - foreach ($listaIdiomasBorrar as $candidatoIdioma) { - Yii::trace('Eliminando idioma... ', 'application.controllers.CandidatoController'); - Yii::trace(CVarDumper::dumpAsString($candidatoIdioma->attributes), 'application.controllers.CandidatoController'); - if (!$candidatoIdioma->delete()) { - $errores = array_merge($errores, $candidatoIdioma->getErrors()); - throw new CException('Error al eliminar un idioma del candidato'); - } - } - $listaIdiomasBorrar = NULL; - } - if (!empty($candidato->idiomas)) { - Yii::trace('Guardando la lista de idiomas', 'application.controllers.CandidatoController'); - foreach ($candidato->idiomas as $candidatoIdioma) { - if (!$candidatoIdioma->save()) { - $errores = array_merge($errores, $candidatoIdioma->getErrors()); - throw new CException('Error al guardar un idioma del candidato'); - } - } - } - - $transaccion->commit(); - - Yii::trace('Candidato guardado', 'application.controllers.CandidatoController'); - Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha actualizado el candidato')); + if ($this->saveModel($candidato)) $this->redirect(array('index')); - } catch (Exception $e) { - Yii::trace($e->getMessage(), 'application.controllers.CandidatoController'); - - $transaccion->rollBack(); - Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al actualizar el candidato')); - - if (YII_DEBUG) { - $resultado = array(); - foreach ($errores as $campo => $mensaje) - $resultado[$campo] = $mensaje; - Yii::trace(CVarDumper::dumpAsString($resultado), 'application.controllers.CandidatoController'); - } - } } $this->render('update', array( @@ -229,24 +108,25 @@ class CandidatoController extends Controller { } /** - * Deletes a particular model. - * If deletion is successful, the browser will be redirected to the 'admin' page. - * @param integer $id the ID of the model to be deleted + * @brief Elimina un candidato. + * @param integer $id el ID del candidato a eliminar */ public function actionDelete($id) { if (Yii::app()->request->isPostRequest) { - // we only allow deletion via POST request + Yii::trace('Eliminar el candidato', 'application.controllers.CandidatoController'); + $this->loadModel($id)->delete(); - $this->borrarFoto($id); - Yii::app()->user->setFlash('success', "Candidato eliminardo correctamente."); + Yii::app()->user->setFlash('success', "Candidato eliminado correctamente."); + // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); } else - throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); + throw new CHttpException(400, Yii::t('profind', 'Petición no válida')); } - + + /** * @brief Lista todos los candidatos * @@ -262,27 +142,6 @@ class CandidatoController extends Controller { 'candidatos' => $candidatos)); } - public function actionHistorial($id) { - $this->layout = '//layouts/candidato'; - $this->render('historial', array( - 'model' => $this->loadModel($id), - )); - } - - /** - * Manages all models. - */ - public function actionAdmin() { - $model = new Candidato('search'); - $model->unsetAttributes(); // clear any default values - if (isset($_GET['Candidato'])) - $model->attributes = $_GET['Candidato']; - - $this->render('admin', array( - 'model' => $model, - )); - } - /** * @brief Devuelve los datos del candidato con id $id. * Si el candidato no existe, se lanza una excepción HTTP 404 @@ -297,6 +156,138 @@ class CandidatoController extends Controller { return $model; } + /** + * @brief Guarda los datos de un candidato $candidato a partir de $_POST + * @param Candidato $candidato instancia del candidato + * @return bool + */ + private function saveModel($candidato) { + if (!isset($_POST['Candidato'])) { + throw new CHttpException(405, Yii::t('profind', 'Método no permitido.')); + } + Yii::trace(CVarDumper::dumpAsString($_POST)); + + // Candidato + $candidato->attributes = $_POST['Candidato']; + $ficheroFotografia = CUploadedFile::getInstance($candidato, 'ficheroFotografia'); + $quitarFotografia = Yii::app()->request->getParam('quitar_fotografia', '0'); + + // Titulaciones del candidato + $listaTitulacionesBorrar = $candidato->titulaciones; + if (isset($_POST['CandidatoTitulacion'])) { + $listaTitulaciones = array(); + foreach ($_POST['CandidatoTitulacion'] as $titulacion) { + $candidatoTitulacion = new CandidatoTitulacion(); + $candidatoTitulacion->titulacion = $titulacion; + $candidatoTitulacion->candidato_id = $candidato->id; + $listaTitulaciones[] = $candidatoTitulacion; + } + $candidato->titulaciones = $listaTitulaciones; + } + + // Idiomas del candidato + $listaIdiomasBorrar = array(); + if (isset($_POST['CandidatoIdioma'])) { + $listaIdiomas = array(); + foreach ($_POST['CandidatoIdioma'] as $key => $idioma) { + if ($idioma['id']) + $candidatoIdioma = CandidatoIdioma::model()->findByPk($idioma['id']); + else + $candidatoIdioma = new CandidatoIdioma(); + $candidatoIdioma->attributes = $idioma; + $candidatoIdioma->candidato_id = $candidato->id; + + if ($idioma['_borrar']) + $listaIdiomasBorrar[] = $candidatoIdioma; + else + $listaIdiomas[] = $candidatoIdioma; + } + $candidato->idiomas = $listaIdiomas; + } + + // Guardar los datos + $errores = array(); + $transaccion = Yii::app()->db->beginTransaction(); + try { + Yii::trace('Guardando el candidato', 'application.controllers.CandidatoController'); + if (!$candidato->save()) { + $errores = array_merge($errores, $candidato->getErrors()); + throw new CException('Error al guardar el candidato'); + } + + if (($quitarFotografia == '1') && ($candidato->fotografia->tieneFotografia())) { + Yii::trace('Eliminando la fotografía del candidato', 'application.controllers.CandidatoController'); + $candidato->fotografia->eliminarFotografia(); + } + + if ($ficheroFotografia) { + Yii::trace('Guardando la fotografía del candidato', 'application.controllers.CandidatoController'); + $candidato->fotografia->guardarFotografia($ficheroFotografia); + } + + // Titulaciones + if (!empty($listaTitulacionesBorrar)) { + Yii::trace('Eliminando titulaciones marcadas para borrar', 'application.controllers.CandidatoController'); + foreach ($listaTitulacionesBorrar as $candidatoTitulacion) { + if (!$candidatoTitulacion->delete()) { + $errores = array_merge($errores, $candidatoTitulacion->getErrors()); + throw new CException('Error al eliminar una titulación del candidato'); + } + } + $listaTitulacionesBorrar = NULL; + } + if (!empty($candidato->titulaciones)) { + Yii::trace('Guardando la lista de titulaciones', 'application.controllers.CandidatoController'); + foreach ($candidato->titulaciones as $candidatoTitulacion) { + if (!$candidatoTitulacion->save()) { + $errores = array_merge($errores, $candidatoTitulacion->getErrors()); + throw new CException('Error al guardar una titulación del candidato'); + } + } + } + + // Idiomas + if (!empty($listaIdiomasBorrar)) { + Yii::trace('Eliminando idiomas marcados para borrar', 'application.controllers.CandidatoController'); + foreach ($listaIdiomasBorrar as $candidatoIdioma) { + Yii::trace('Eliminando idioma... ', 'application.controllers.CandidatoController'); + Yii::trace(CVarDumper::dumpAsString($candidatoIdioma->attributes), 'application.controllers.CandidatoController'); + if (!$candidatoIdioma->delete()) { + $errores = array_merge($errores, $candidatoIdioma->getErrors()); + throw new CException('Error al eliminar un idioma del candidato'); + } + } + $listaIdiomasBorrar = NULL; + } + if (!empty($candidato->idiomas)) { + Yii::trace('Guardando la lista de idiomas', 'application.controllers.CandidatoController'); + foreach ($candidato->idiomas as $candidatoIdioma) { + if (!$candidatoIdioma->save()) { + $errores = array_merge($errores, $candidatoIdioma->getErrors()); + throw new CException('Error al guardar un idioma del candidato'); + } + } + } + + $transaccion->commit(); + Yii::trace('Candidato guardado', 'application.controllers.CandidatoController'); + Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha actualizado el candidato')); + return TRUE; + } catch (Exception $e) { + Yii::trace($e->getMessage(), 'application.controllers.CandidatoController'); + $transaccion->rollBack(); + Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al actualizar el candidato')); + + if (YII_DEBUG) { + $resultado = array(); + foreach ($errores as $campo => $mensaje) + $resultado[$campo] = $mensaje; + Yii::trace(CVarDumper::dumpAsString($resultado), 'application.controllers.CandidatoController'); + } + return FALSE; + } + } + } ?> \ No newline at end of file diff --git a/www/protected/helpers/TimeHelper.php b/www/protected/helpers/TimeHelper.php new file mode 100644 index 0000000..e0c0d55 --- /dev/null +++ b/www/protected/helpers/TimeHelper.php @@ -0,0 +1,274 @@ +strtotime-parsable format, like MySQL's datetime datatype. + * + * Options: + * 'format' => a fall back format if the relative time is longer than the duration specified by end + * 'end' => The end of relative time telling + * + * Relative dates look something like this: + * 3 weeks, 4 days ago + * 15 seconds ago + * Formatted dates look like this: + * on 02/18/2004 + * + * The returned string includes 'ago' or 'on' and assumes you'll properly add a word + * like 'Posted ' before the function output. + * + * @param string $dateString Datetime string + * @param array $options Default format if timestamp is used in $dateString + * @return string Relative time string. + */ + function timeAgoInWords($dateTime, $options = array()) { + $now = time(); + + $inSeconds = strtotime($dateTime); + $backwards = ($inSeconds > $now); + + $format = 'j/n/y'; + $end = '+1 month'; + + if (is_array($options)) { + if (isset($options['format'])) { + $format = $options['format']; + unset($options['format']); + } + if (isset($options['end'])) { + $end = $options['end']; + unset($options['end']); + } + } else { + $format = $options; + } + + if ($backwards) { + $futureTime = $inSeconds; + $pastTime = $now; + } else { + $futureTime = $now; + $pastTime = $inSeconds; + } + $diff = $futureTime - $pastTime; + + // If more than a week, then take into account the length of months + if ($diff >= 604800) { + $current = array(); + $date = array(); + + list($future['H'], $future['i'], $future['s'], $future['d'], $future['m'], $future['Y']) = explode('/', date('H/i/s/d/m/Y', $futureTime)); + + list($past['H'], $past['i'], $past['s'], $past['d'], $past['m'], $past['Y']) = explode('/', date('H/i/s/d/m/Y', $pastTime)); + $years = $months = $weeks = $days = $hours = $minutes = $seconds = 0; + + if ($future['Y'] == $past['Y'] && $future['m'] == $past['m']) { + $months = 0; + $years = 0; + } else { + if ($future['Y'] == $past['Y']) { + $months = $future['m'] - $past['m']; + } else { + $years = $future['Y'] - $past['Y']; + $months = $future['m'] + ((12 * $years) - $past['m']); + + if ($months >= 12) { + $years = floor($months / 12); + $months = $months - ($years * 12); + } + + if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] == 1) { + $years--; + } + } + } + + if ($future['d'] >= $past['d']) { + $days = $future['d'] - $past['d']; + } else { + $daysInPastMonth = date('t', $pastTime); + $daysInFutureMonth = date('t', mktime(0, 0, 0, $future['m'] - 1, 1, $future['Y'])); + + if (!$backwards) { + $days = ($daysInPastMonth - $past['d']) + $future['d']; + } else { + $days = ($daysInFutureMonth - $past['d']) + $future['d']; + } + + if ($future['m'] != $past['m']) { + $months--; + } + } + + if ($months == 0 && $years >= 1 && $diff < ($years * 31536000)) { + $months = 11; + $years--; + } + + if ($months >= 12) { + $years = $years + 1; + $months = $months - 12; + } + + if ($days >= 7) { + $weeks = floor($days / 7); + $days = $days - ($weeks * 7); + } + } else { + $years = $months = $weeks = 0; + $days = floor($diff / 86400); + + $diff = $diff - ($days * 86400); + + $hours = floor($diff / 3600); + $diff = $diff - ($hours * 3600); + + $minutes = floor($diff / 60); + $diff = $diff - ($minutes * 60); + $seconds = $diff; + } + $relativeDate = ''; + $diff = $futureTime - $pastTime; + + if ($diff > abs($now - strtotime($end))) { + $relativeDate = sprintf('el %s', date($format, $inSeconds)); + } else { + if ($years > 0) { + // years and months and days + $relativeDate .= ($relativeDate ? ', ' : '') . $years . ' ' . ($years == 1 ? 'año' : 'años'); + $relativeDate .= $months > 0 ? ($relativeDate ? ', ' : '') . $months . ' ' . ($months == 1 ? 'mes' : 'meses') : ''; + $relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . $weeks . ' ' . ($weeks == 1 ? 'semana' : 'semanas') : ''; + $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . ($days == 1 ? 'día' : 'días') : ''; + } elseif (abs($months) > 0) { + // months, weeks and days + $relativeDate .= ($relativeDate ? ', ' : '') . $months . ' ' . ($months == 1 ? 'mes' : 'meses'); + $relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . $weeks . ' ' . ($weeks == 1 ? 'semana' : 'semanas') : ''; + $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . ($days == 1 ? 'día' : 'días') : ''; + } elseif (abs($weeks) > 0) { + // weeks and days + $relativeDate .= ($relativeDate ? ', ' : '') . $weeks . ' ' . ($weeks == 1 ? 'semana' : 'semanas'); + $relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . ($days == 1 ? 'día' : 'días') : ''; + } elseif (abs($days) > 0) { + // days and hours + $relativeDate .= ($relativeDate ? ', ' : '') . $days . ' ' . ($days == 1 ? 'día' : 'días'); + $relativeDate .= $hours > 0 ? ($relativeDate ? ', ' : '') . $hours . ' ' . ($hours == 1 ? 'hora' : 'horas') : ''; + } elseif (abs($hours) > 0) { + // hours and minutes + $relativeDate .= ($relativeDate ? ', ' : '') . $hours . ' ' . ($hours == 1 ? 'hora' : 'horas'); + $relativeDate .= $minutes > 0 ? ($relativeDate ? ', ' : '') . $minutes . ' ' . ($minutes == 1 ? 'minuto' : 'minutos') : ''; + } elseif (abs($minutes) > 0) { + // minutes only + $relativeDate .= ($relativeDate ? ', ' : '') . $minutes . ' ' . ($minutes == 1 ? 'minuto' : 'minutos'); + } else { + // seconds only + $relativeDate .= ($relativeDate ? ', ' : '') . $seconds . ' ' . ($seconds == 1 ? 'segundo' : 'segundos'); + } + + if (!$backwards) { + $relativeDate = sprintf('hace %s', $relativeDate); + } + } + return $relativeDate; + } + +} \ No newline at end of file diff --git a/www/protected/migrations/m121014_170834_tbl_estados_candidatos.php b/www/protected/migrations/m121014_170834_tbl_estados_candidatos.php index d78934a..e2cd172 100644 --- a/www/protected/migrations/m121014_170834_tbl_estados_candidatos.php +++ b/www/protected/migrations/m121014_170834_tbl_estados_candidatos.php @@ -4,6 +4,7 @@ class m121014_170834_tbl_estados_candidatos extends CDbMigration { $this->createTable('tbl_estados_candidatos', array( 'id' => 'pk', 'descripcion' => 'string NOT NULL', + 'predeterminado' => 'boolean NOT NULL DEFAULT "0"' // tinyint(1) ), 'ENGINE=InnoDB CHARSET=utf8'); } diff --git a/www/protected/models/Candidato.php b/www/protected/models/Candidato.php index bb6ed14..4d8e1e2 100644 --- a/www/protected/models/Candidato.php +++ b/www/protected/models/Candidato.php @@ -5,7 +5,7 @@ * @brief Modelo de la tabla "tbl_candidatos". * * @property integer $id - * @property integer $id_estado + * @property integer $id_estado * @property string $n_identificacion * @property string $nombre * @property string $apellidos @@ -33,15 +33,13 @@ * @property string $ficheroFotografia * @property FotografiaPerfil $fotografia * - * @property CandidatoCapacidad[] $capacidades + * @property EstadoCandidato $estado * @property CandidatoIdioma[] $idiomas * @property CandidatoTitulacion[] $titulaciones - * @property CandidatoDocumento[] $documentos * * @package application.models * */ - class Candidato extends CActiveRecord { const GENERO_HOMBRE = 'Hombre'; @@ -50,51 +48,18 @@ class Candidato extends CActiveRecord { 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; + private $_nombreCompleto; /** * @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; + return $this->nombre . ' ' . $this->apellidos; } - - 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; + + public function setNombreCompleto($value) { + $this->_nombreCompleto = $value; } /** @@ -155,6 +120,9 @@ class Candidato extends CActiveRecord { 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 @@ -163,8 +131,7 @@ class Candidato extends CActiveRecord { 'allowEmpty' => 'true', ), - array('salario_minimo, salario_maximo', 'numerical','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']), @@ -176,20 +143,16 @@ class Candidato extends CActiveRecord { 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, + array('id, id_estado, estado, nombre, apellidos, nombreCompleto, n_identificacion, email, telefono_fijo, telefono_movil, sexo, fecha_nacimiento, lugar_nacimiento, - localidad, fecha_alta, usuario_alta, - usuario_modificacion, carnet_conducir, vehiculo_propio, + localidad, carnet_conducir, vehiculo_propio, observaciones, salario_minimo, salario_maximo, procedencia, disponibilidad_incorporacion, disponibilidad_entrevistas, disponibilidad_guardias, disponibilidad_viajar, @@ -203,54 +166,59 @@ class Candidato extends CActiveRecord { */ 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'), + 'estado' => array(self::BELONGS_TO, 'EstadoCandidato', 'id_estado'), ); } + /** + * @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' => 'ID estado', - 'nombre_estado_search' => 'Estado', - 'idiomas_search' => 'Idioma', - 'nombreApellidos' => 'Candidato', - 'foto' => 'Foto', + 'id_estado' => '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', - 'sexo' => 'Sexo', 'fecha_nacimiento' => 'Fecha de nacimiento', 'lugar_nacimiento' => 'Lugar de nacimiento', - 'localidad' => 'Localidad', 'carnet_conducir' => 'Carnet de conducir', 'vehiculo_propio' => 'Vehículo propio', + 'procedencia' => 'Procedencia', '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', + 'modified_time' => 'Modificación', ); } @@ -262,116 +230,88 @@ class Candidato extends CActiveRecord { // Warning: Please modify the following code to remove attributes that // should not be searched. - $criteria=new CDbCriteria; + $criteria = new CDbCriteria; + + $criteria->with = array('estado'); + $criteria->together = true; + + $criteria->compare('t.id', $this->id); + + $criteria->compare('t.id_estado', $this->id_estado); + //$criteria->compare('estado.descripcion', $this->estado, true); + + $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('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); - $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->modelClass = 'Candidato'; $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(); + 'criteria' => $criteria, + 'sort' => $sort, + )); } 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)) + /*if (($this->id_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() { + parent::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 afterConstruct() { + parent::afterConstruct(); + $this->fotografia = new FotografiaPerfil(); + $this->fotografia->modelo = $this; + } + protected function afterSave() { parent::afterSave(); if ($this->isNewRecord) @@ -383,21 +323,14 @@ class Candidato extends CActiveRecord { $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'; + return 'candidate_photo.jpg'; } - + /** * @brief Devuelve la ruta con los ficheros del usuario. * Incluye el separador de directorios al final de la ruta. @@ -406,7 +339,7 @@ class Candidato extends CActiveRecord { 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 @@ -414,24 +347,26 @@ class Candidato extends CActiveRecord { private function createUploadDir() { $upload = $this->getUploadPath(); - if(!is_dir($upload)) { + if (!is_dir($upload)) { return mkdir($upload); } - else return false; + 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)) + + if (is_dir($upload)) return GHelper::recursiveRemoveDirectory($upload); - else return false; + else + return false; } - + } ?> \ No newline at end of file diff --git a/www/protected/models/EstadoCandidato.php b/www/protected/models/EstadoCandidato.php new file mode 100644 index 0000000..507428b --- /dev/null +++ b/www/protected/models/EstadoCandidato.php @@ -0,0 +1,90 @@ + 255), + // The following rule is used by search(). + // Please remove those attributes that should not be searched. + array('id, descripcion', 'safe', 'on' => 'search'), + ); + } + + public function scopes() { + return array( + 'predeterminado' => array( + 'condition' => 'predeterminado = 1', + 'limit' => 1, + ), + ); + } + + /** + * @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( + ); + } + + /** + * @return array customized attribute labels (name=>label) + */ + public function attributeLabels() { + return array( + 'id' => 'ID', + 'descripcion' => 'Descripcion', + ); + } + + /** + * 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('descripcion', $this->descripcion, true); + + return new CActiveDataProvider($this, array( + 'criteria' => $criteria, + )); + } + +} \ No newline at end of file diff --git a/www/themes/profind/css/azul.css b/www/themes/profind/css/azul.css index d86b1b8..1f69e79 100644 --- a/www/themes/profind/css/azul.css +++ b/www/themes/profind/css/azul.css @@ -34,7 +34,6 @@ background: #48a6d2 !important; } -html body.sidebar_right div#maincontainer.clearfix header div.navbar div.navbar-inner div.container-fluid nav div.nav-collapse ul#yw0.nav li.active a i.icon-briefcase - .table thead th {background-color:#ebf2f6 !important} -.dataTables_wrapper th.sorting_asc,.dataTables_wrapper th.sorting_desc {background-color:#d4e3eb !important} + +.table thead th.sorting_asc, .table thead th.sorting_desc {background-color:#d4e3eb !important} diff --git a/www/themes/profind/css/profind.css b/www/themes/profind/css/profind.css index 4c98d43..51afece 100644 --- a/www/themes/profind/css/profind.css +++ b/www/themes/profind/css/profind.css @@ -102,7 +102,7 @@ h3 + .label { .ov_boxes .ov_text, .dshb_icoNav li a, .table th, .fc thead th { text-shadow: 1px 1px 0 #fff } -.dataTables_wrapper .sorting_asc, .dataTables_wrapper .sorting_desc { +.table thead th.sorting_asc, .table thead th.sorting_desc { text-shadow: 1px 1px 0 #eee } /* Bootstrap adjustments */ diff --git a/www/themes/profind/views/candidato/_grid.php b/www/themes/profind/views/candidato/_grid.php index 98223af..a217702 100644 --- a/www/themes/profind/views/candidato/_grid.php +++ b/www/themes/profind/views/candidato/_grid.php @@ -1,56 +1,60 @@ -clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/lib/datatables/js/jquery.dataTables.min.js', CClientScript::POS_END); ?> -clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/lib/datatables/extras/Scroller/media/js/Scroller.min.js', CClientScript::POS_END); ?> - clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/grid.css'); ?> -clientScript->registerScript('init_grid', ' - $(document).ready(function() { - - $row = $("
| Image | Name | Size | Date | Actions | |
|---|---|---|---|---|---|
| - |
-
-
-
- |
- Lorem ipsum dolor sit Image10.jpg |
- 200 KB | -28/06/2012 | -- - - - | -
| - |
-
-
-
- |
- Lorem ipsum dolor sit Image11.jpg |
- 210 KB | -27/06/2012 | -- - - - | -
| - |
-
-
-
- |
- Lorem ipsum dolor sit Image12.jpg |
- 360 KB | -25/06/2012 | -- - - - | -
| - |
-
-
-
- |
- Lorem ipsum dolor sit Image13.jpg |
- 215 KB | -24/06/2012 | -- - - - | -
| - |
-
-
-
- |
- Lorem ipsum dolor sit Image14.jpg |
- 650 KB | -24/06/2012 | -- - - - | -
| - |
-
-
-
- |
- Lorem ipsum dolor sit Image15.jpg |
- 428 KB | -23/06/2012 | -- - - - | -