Descarga del documento (CV) de un candidato

git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Web/trunk@75 3fe1ab16-cfe0-e34b-8c9f-7d8c168d430d
This commit is contained in:
David Arranz 2012-12-10 18:58:20 +00:00
parent b4eedbc7ee
commit 70c8f2fd01
3 changed files with 31 additions and 9 deletions

View File

@ -25,7 +25,7 @@ class CandidatoController extends Controller {
public function accessRules() {
return array(
array('allow',
'actions' => array('index', 'view', 'create', 'update', 'delete', 'admin', 'updateEstado'),
'actions' => array('index', 'view', 'create', 'update', 'delete', 'admin', 'updateEstado', 'download'),
'users' => array('@'),
),
array('deny', // deny all users
@ -126,6 +126,17 @@ class CandidatoController extends Controller {
throw new CHttpException(400, Yii::t('profind', 'Petición no válida'));
}
/**
* Descarga el documento
* @param integer $id el ID del documento
*/
public function actionDownload($id) {
$documento = CandidatoDocumento::model()->findByPk($id);
if ($documento === null)
throw new CHttpException(404, Yii::t('profind', 'La página solicitada no existe.'));
return $documento->download();
}
/**
* @brief Lista todos los candidatos

View File

@ -133,7 +133,8 @@ class CandidatoDocumento extends CActiveRecord {
}
protected function afterSave() {
$this->guardarFicheroDocumento();
if ($this->isNewRecord)
$this->guardarFicheroDocumento();
return parent::afterSave();
}
@ -150,7 +151,6 @@ class CandidatoDocumento extends CActiveRecord {
protected function beforeValidate() {
if ($this->ficheroDocumento) {
$upload = $this->candidato->getUploadPath();
$this->nombre_fichero = $this->generarNombreFicheroDocumento();
Yii::trace('Nombre para el documento: ' . $this->nombre_fichero, 'application.models.CandidatoDocumento');
}
@ -182,7 +182,17 @@ class CandidatoDocumento extends CActiveRecord {
}
}
return $filename;
}
}
public function download() {
$nombre = $this->darRutaCompletaFichero();
return GDownloadHelper::send($nombre);
}
public function darRutaCompletaFichero() {
$upload = $this->candidato->getUploadPath();
return $upload . $this->nombre_fichero;
}
/*
* Guarda un documento subido por el usuario
@ -197,8 +207,7 @@ class CandidatoDocumento extends CActiveRecord {
if (!$this->ficheroDocumento)
throw new CException(Yii::t('profind', 'Fichero de documento no asignado.'));
$upload = $this->candidato->getUploadPath();
$nombre = $upload . $this->nombre_fichero;
$nombre = $this->darRutaCompletaFichero();
return $this->ficheroDocumento->saveAs($nombre);
}
@ -211,8 +220,7 @@ class CandidatoDocumento extends CActiveRecord {
if (!$this->candidato)
throw new CException(Yii::t('profind', 'Candidato no asignado.'));
$upload = $this->candidato->getUploadPath();
$nombre = $upload . $this->nombre_fichero;
$nombre = $this->darRutaCompletaFichero();
return unlink($nombre);
}
}

View File

@ -58,7 +58,10 @@ Yii::app()->clientScript->registerScript('js_datepicker', $js_datepicker, CClien
<?php echo CHtml::hiddenField("CandidatoDocumento[$i][_borrar]", '0', array('class' => 'to_remove')); ?>
<input type="hidden" class="rowIndex" value="<?php echo $i;?>" />
<?php if (!$documento->hasErrors()) : ?>
<a class="btn btn-small download" href="#"><i class="icon-download"></i></a>
<?php echo CHtml::link(CHtml::tag('i', array('class' => 'icon-download'), ''),
$this->createUrl('download', array("id"=>$documento->id)),
array('class' => 'btn btn-small download')
); ?>
<?php endif; ?>
<a class="btn btn-small remove" href="#"><i class="icon-trash"></i></a>
</td>