- Idiomas de candidatos

git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Web/trunk@66 3fe1ab16-cfe0-e34b-8c9f-7d8c168d430d
This commit is contained in:
David Arranz 2012-10-23 19:02:18 +00:00
parent 79ca66d885
commit 8933c75317
10 changed files with 389 additions and 33 deletions

View File

@ -74,20 +74,85 @@ class CandidatoController extends Controller {
// $this->performAjaxValidation($candidato);
if (isset($_POST['Candidato'])) {
$candidato->attributes = $_POST['Candidato'];
$ficheroFotografia = CUploadedFile::getInstance($candidato, 'ficheroFotografia');
Yii::trace(CVarDumper::dumpAsString($_POST));
// Candidato
$candidato->attributes = $_POST['Candidato'];
$ficheroFotografia = CUploadedFile::getInstance($candidato, 'ficheroFotografia');
$quitarFotografia = Yii::app()->request->getParam('quitar_fotografia', '0');
// Idiomas del candidato
$listaIdiomas = array();
$listaIdiomasBorrar = 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;
Yii::trace('Idioma ' . $key);
Yii::trace(CVarDumper::dumpAsString($candidatoIdioma->attributes));
}
$candidato->idiomas = $listaIdiomas;
Yii::trace('Idiomas a borrar');
Yii::trace(CVarDumper::dumpAsString($listaIdiomasBorrar));
// Guardar los datos
$transaccion = Yii::app()->db->beginTransaction();
try {
Yii::trace('Guardando el candidato', 'application.controllers.CandidatoController');
if (!$candidato->save())
throw new CException('Error al guardar el candidato');
if ($candidato->save()) {
if (($quitarFotografia == '1') && ($candidato->fotografia->tieneFotografia()))
if (($quitarFotografia == '1') && ($candidato->fotografia->tieneFotografia())) {
Yii::trace('Eliminando la fotografía del candidato', 'application.controllers.CandidatoController');
$candidato->fotografia->eliminarFotografia();
if ($ficheroFotografia)
}
if ($ficheroFotografia) {
Yii::trace('Guardando la fotografía del candidato', 'application.controllers.CandidatoController');
$candidato->fotografia->guardarFotografia($ficheroFotografia);
}
if (!empty($listaIdiomasBorrar)) {
Yii::trace('Eliminando idiomas marcados para borrar', 'application.controllers.CandidatoController');
foreach ($listaIdiomasBorrar as $candidatoIdioma) {
if (!$candidatoIdioma->delete())
throw new CException('Error al eliminar un idioma del candidato');
}
}
if (!empty($candidato->idiomas)) {
Yii::trace('Guardando la lista de idiomas', 'application.controllers.CandidatoController');
foreach ($candidato->idiomas as $candidatoIdioma) {
if (!$candidatoIdioma->save())
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'));
$this->redirect(array('index'));
} catch (Exception $e) {
Yii::trace($e->getMessage(), 'application.controllers.CandidatoController');
$transaccion->rollBack();
$errores = array_merge($candidato->getErrors() /*, $nueva_empresa->getErrors(), $nueva_subscripcion->getErrors()*/);
foreach ($errores as $campo => $mensaje) $resultado[$campo] = $mensaje;
Yii::trace(CVarDumper::dumpAsString($resultado), 'application.controllers.CandidatoController');
Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al actualizar el candidato'));
}
}

View File

@ -0,0 +1,112 @@
<?php
/**
* @class CandidatoIdioma
* @brief Modelo de la tabla "tbl_candidatos_idiomas".
*
* The followings are the available columns in table 'tbl_candidatos_idiomas':
* @property integer $id
* @property integer $candidato_id
* @property string $idioma
* @property string $conversacion
* @property string $lectura_traduccion
*
* The followings are the available model relations:
* @property Candidato $candidato
*/
class CandidatoIdioma extends CActiveRecord {
const NIVEL_BAJO = 0;
const NIVEL_MEDIO = 1;
const NIVEL_ALTO = 2;
/**
* @brief Devuelve la lista de niveles de idioma.
* @return array lista de niveles permitidos
*/
public static function getOpcionesNivel() {
return array(
self::NIVEL_BAJO => 'Bajo',
self::NIVEL_MEDIO => 'Medio',
self::NIVEL_ALTO => 'Alto',
);
}
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return CandidatoIdioma 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_idiomas';
}
/**
* @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('candidato_id, idioma', 'required'),
array('candidato_id', 'numerical', 'integerOnly' => true),
array('idioma, conversacion, lectura_traduccion', 'length', 'max' => 255),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, candidato_id, idioma, conversacion, lectura_traduccion', '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(
'candidato' => array(self::BELONGS_TO, 'Candidato', 'candidato_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'id' => 'ID',
'candidato_id' => 'Candidato',
'idioma' => 'Idioma',
'conversacion' => 'Nivel en conversación',
'lectura_traduccion' => 'Nivel en lectura/traducció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->compare('id', $this->id);
$criteria->compare('candidato_id', $this->candidato_id);
$criteria->compare('idioma', $this->idioma, true);
$criteria->compare('conversacion', $this->conversacion, true);
$criteria->compare('lectura_traduccion', $this->lectura_traduccion, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
}

View File

@ -30,7 +30,6 @@ class Idioma extends CActiveRecord {
return array(
array('descripcion', 'required'),
array('descripcion', 'length', 'max' => 255),
array('id, descripcion', 'safe', 'on' => 'search'),
);
}
@ -45,6 +44,15 @@ class Idioma extends CActiveRecord {
);
}
/**
* @return array Default scope for this model.
*/
public function defaultScope() {
return array(
'order' => '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.
@ -67,4 +75,5 @@ class Idioma extends CActiveRecord {
}
}
?>

View File

@ -0,0 +1,14 @@
/*
* jQuery Calculation Plug-in
*
* Copyright (c) 2007 Dan G. Switzer, II
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Revision: 12
* Version: 0.4.08
*
*/
(function($){var defaults={reNumbers:/(-|-\$)?(\d+(,\d{3})*(\.\d{1,})?|\.\d{1,})/g,cleanseNumber:function(v){return v.replace(/[^0-9.\-]/g,"")},useFieldPlugin:(!!$.fn.getValue),onParseError:null,onParseClear:null};$.Calculation={version:"0.4.08",setDefaults:function(options){$.extend(defaults,options)}};$.fn.parseNumber=function(options){var aValues=[];options=$.extend(options,defaults);this.each(function(){var $el=$(this),sMethod=($el.is(":input")?(defaults.useFieldPlugin?"getValue":"val"):"text"),v=$.trim($el[sMethod]()).match(defaults.reNumbers,"");if(v==null){v=0;if(jQuery.isFunction(options.onParseError))options.onParseError.apply($el,[sMethod]);$.data($el[0],"calcParseError",true)}else{v=options.cleanseNumber.apply(this,[v[0]]);if($.data($el[0],"calcParseError")&&jQuery.isFunction(options.onParseClear)){options.onParseClear.apply($el,[sMethod]);$.data($el[0],"calcParseError",false)}}aValues.push(parseFloat(v,10))});return aValues};$.fn.calc=function(expr,vars,cbFormat,cbDone){var $this=this,exprValue="",precision=0,$el,parsedVars={},tmp,sMethod,_,bIsError=false;for(var k in vars){expr=expr.replace((new RegExp("("+k+")","g")),"_.$1");if(!!vars[k]&&!!vars[k].jquery){parsedVars[k]=vars[k].parseNumber()}else{parsedVars[k]=vars[k]}}this.each(function(i,el){var p,len;$el=$(this);sMethod=($el.is(":input")?(defaults.useFieldPlugin?"setValue":"val"):"text");_={};for(var k in parsedVars){if(typeof parsedVars[k]=="number"){_[k]=parsedVars[k]}else if(typeof parsedVars[k]=="string"){_[k]=parseFloat(parsedVars[k],10)}else if(!!parsedVars[k]&&(parsedVars[k]instanceof Array)){tmp=(parsedVars[k].length==$this.length)?i:0;_[k]=parsedVars[k][tmp]}if(isNaN(_[k]))_[k]=0;p=_[k].toString().match(/\.\d+$/gi);len=(p)?p[0].length-1:0;if(len>precision)precision=len}try{exprValue=eval(expr);if(precision)exprValue=Number(exprValue.toFixed(Math.max(precision,4)));if(jQuery.isFunction(cbFormat)){var tmp=cbFormat.apply(this,[exprValue]);if(!!tmp)exprValue=tmp}}catch(e){exprValue=e;bIsError=true}$el[sMethod](exprValue.toString())});if(jQuery.isFunction(cbDone))cbDone.apply(this,[this]);return this};$.each(["sum","avg","min","max"],function(i,method){$.fn[method]=function(bind,selector){if(arguments.length==0)return math[method](this.parseNumber());var bSelOpt=selector&&(selector.constructor==Object)&&!(selector instanceof jQuery);var opt=bind&&bind.constructor==Object?bind:{bind:bind||"keyup",selector:(!bSelOpt)?selector:null,oncalc:null};if(bSelOpt)opt=jQuery.extend(opt,selector);if(!!opt.selector)opt.selector=$(opt.selector);var self=this,sMethod,doCalc=function(){var value=math[method](self.parseNumber(opt));if(!!opt.selector){sMethod=(opt.selector.is(":input")?(defaults.useFieldPlugin?"setValue":"val"):"text");opt.selector[sMethod](value.toString())}if(jQuery.isFunction(opt.oncalc))opt.oncalc.apply(self,[value,opt])};doCalc();return self.bind(opt.bind,doCalc)}});var math={sum:function(a){var total=0,precision=0;$.each(a,function(i,v){var p=v.toString().match(/\.\d+$/gi),len=(p)?p[0].length-1:0;if(len>precision)precision=len;total+=v});if(precision)total=Number(total.toFixed(precision));return total},avg:function(a){return math.sum(a)/a.length},min:function(a){return Math.min.apply(Math,a)},max:function(a){return Math.max.apply(Math,a)}}})(jQuery);

View File

@ -0,0 +1,21 @@
/*
* jQuery extensions for xForm
*/
$.format = function(source, params) {
if ( arguments.length == 1 )
return function() {
var args = $.makeArray(arguments);
args.unshift(source);
return $.format.apply( this, args );
};
if ( arguments.length > 2 && params.constructor != Array ) {
params = $.makeArray(arguments).slice(1);
}
if ( params.constructor != Array ) {
params = [ params ];
}
$.each(params, function(i, n) {
source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
});
return source;
};

View File

@ -41,11 +41,17 @@ $(document).ready(function() {
prettyPrint();
}
//* external links
profind_external_links.init();
//profind_external_links.init();
/* Chosen */
//profind_chosen.init();
//* accordion icons
profind_acc_icons.init();
//* main menu mouseover
profind_nav_mouseover.init();
//* top submenu
profind_submenu.init();
@ -61,7 +67,18 @@ profind_external_links = {
})
}
};
//* external links
profind_chosen = {
init: function() {
$('.chosen').chosen({
allow_single_deselect: true,
no_results_text: 'No existe'
});
}
};
profind_sidebar = {
init: function() {
// sidebar onload state

View File

@ -0,0 +1,45 @@
/**
* * This script depends on jquery.format.js
*/
$(document).ready(function() {
profind_template.init();
});
profind_template = {
init: function() {
profind_template.hideHeaderIfEmpty();
$(".add").click(function(){
var template = jQuery.format(jQuery.trim($(this).siblings(".template").val()));
var place = $(this).parents(".templateFrame:first").children(".templateTarget");
var i = place.find(".rowIndex").length>0 ? place.find(".rowIndex").max()+1 : 0;
$(template(i)).appendTo(place);
profind_template.showHeader(this);
return false;
});
$(".remove").live("click", function() {
if ($(this).siblings(".pk").val() === '') {
$(this).parents(".templateContent:first").remove();
} else {
$(this).siblings(".to_remove").val(1);
$(this).parents(".templateContent:first").hide();
}
profind_template.hideHeaderIfEmpty();
return false;
});
},
hideHeaderIfEmpty: function() {
var place = $('.templateTarget').filter(function(){return $.trim($(this).text())===''});
$(place).siblings('.templateHead').hide();
$(place).parents(".templateFrame:first").removeClass('table');
},
showHeader: function(element) {
var place = $(element).parents(".templateFrame:first");
$(place).children('.templateHead').show();
$(place).addClass('table');
}
};

View File

@ -0,0 +1,88 @@
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery.format.js', CClientScript::POS_END); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery.calculation.min.js', CClientScript::POS_END); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/profind-template.js', CClientScript::POS_END); ?>
<fieldset>
<div class="row-fluid formSep">
<div class="span12">
<legend class="control-label" style="text-align: left;"><?php echo Yii::t('profind', 'Idiomas'); ?></legend>
<div class="controls">
<table class="table templateFrame">
<thead class="templateHead">
<tr>
<th style="width: 50%;"><?php echo Yii::t('profind', 'Idioma'); ?></th>
<th style="width: 20%;"><?php echo Yii::t('profind', 'Conversación'); ?></th>
<th style="width: 20%;"><?php echo Yii::t('profind', 'Lectura / traducción'); ?></th>
<th style="width: 10%;"></th>
</tr>
</thead>
<tbody class="templateTarget">
<?php foreach($candidato->idiomas as $i=>$idioma): ?>
<tr class="templateContent">
<td>
<?php echo CHtml::activeDropDownList($idioma,
"[$i]idioma",
CHtml::listData(Idioma::model()->findAll(), 'descripcion', 'descripcion'),
array('class' => 'span12')
);
?>
</td>
<td>
<?php echo CHtml::activeDropDownList($idioma,
"[$i]conversacion",
$idioma->opcionesNivel,
array('class' => 'span12')
);
?>
</td>
<td>
<?php echo CHtml::activeDropDownList($idioma,
"[$i]lectura_traduccion",
$idioma->opcionesNivel,
array('class' => 'span12')
);
?>
</td>
<td>
<?php echo CHtml::activeHiddenField($idioma, "[$i]id", array('class' => 'pk')); ?>
<?php echo CHtml::activeHiddenField($idioma, "[$i]candidato_id"); ?>
<?php echo CHtml::hiddenField("CandidatoIdioma[$i][_borrar]", '0', array('class' => 'to_remove')); ?>
<input type="hidden" class="rowIndex" value="<?php echo $i;?>" />
<a class="btn btn-small remove" href="#"><i class="icon-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<a class="btn btn-small add" href="#"><i class="icon-plus"></i> <?php echo Yii::t('profind', 'Añadir un idioma');?></a>
<textarea class="hide template">
<tr class="templateContent">
<td>
<?php echo CHtml::dropDownList('CandidatoIdioma[{0}][idioma]', '', CHtml::listData(Idioma::model()->findAll(), 'descripcion', 'descripcion'), array('class' => 'span12')); ?>
</td>
<td>
<?php echo CHtml::dropDownList('CandidatoIdioma[{0}][conversacion]', '', CandidatoIdioma::model()->opcionesNivel, array('class' => 'span12')); ?>
</td>
<td>
<?php echo CHtml::dropDownList('CandidatoIdioma[{0}][lectura_traduccion]', '', CandidatoIdioma::model()->opcionesNivel, array('class' => 'span12')); ?>
</td>
<td>
<?php echo CHtml::hiddenField('CandidatoIdioma[{0}][id]', '', array('class' => 'pk')); ?>
<?php echo CHtml::hiddenField('CandidatoIdioma[{0}][candidato_id]'); ?>
<?php echo CHtml::hiddenField('CandidatoIdioma[{0}][_borrar]', '0', array('class' => 'to_remove')); ?>
<input type="hidden" class="rowIndex" value="{0}" />
<a class="btn btn-small remove" href="#"><i class="icon-trash"></i></a>
</td>
</tr>
</textarea>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</fieldset>

View File

@ -1,12 +1,12 @@
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-inputmask.js'); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-fileupload.js'); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/lib/chosen/chosen.jquery.min.js'); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-inputmask.js', CClientScript::POS_END); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-fileupload.js', CClientScript::POS_END); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/lib/chosen/chosen.jquery.min.js', CClientScript::POS_END); ?>
<?php Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/lib/chosen/chosen.css'); ?>
<?php
$js_chosen = <<<JS
profind_chosen = {
profind_localidad_chosen = {
init: function() {
$('.localidad').chosen({
allow_single_deselect: true,
@ -32,7 +32,7 @@ Yii::app()->clientScript->registerScript('js_quitar_foto', $js_quitar_foto, CCli
$js_init = <<<JS
$(document).ready(function(){
profind_chosen.init();
profind_localidad_chosen.init();
profind_fotografia.init();
});
JS;
@ -249,7 +249,7 @@ $form = $this->beginWidget('CActiveForm', array(
</fieldset>
<fieldset>
<div class="row-fluid sepH_b">
<div class="row-fluid formSep">
<div class="span6">
<div class="sepH_b">
<?php echo $form->labelEx($candidato, 'carnet_conducir', array('class' => 'control-label')); ?>
@ -267,6 +267,8 @@ $form = $this->beginWidget('CActiveForm', array(
</div>
</fieldset>
<?php echo $this->renderPartial('__idiomas', array('candidato' => $candidato)); ?>
<fieldset>
<div class="row-fluid formSep">
<div class="span12">

View File

@ -177,23 +177,6 @@
</div>
<div class="push"></div>
</div>
<div class="sidebar_info">
<ul class="unstyled">
<li>
<span class="act act-warning">65</span>
<strong>New comments</strong>
</li>
<li>
<span class="act act-success">10</span>
<strong>New articles</strong>
</li>
<li>
<span class="act act-danger">85</span>
<strong>New registrations</strong>
</li>
</ul>
</div>
</div>
</div>
</div>
@ -202,7 +185,7 @@
<!-- Bootstrap JS -->
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/bootstrap/js/bootstrap.min.js"></script>
<!-- Eventos en el redimensionado -->
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/lib/actual/jquery.debouncedresize.js"></script>
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/lib/smartresize/jquery.debouncedresize.js"></script>
<!-- width/height -->
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/lib/actual/jquery.actual.min.js"></script>
<!-- js cookie plugin -->