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:
parent
b4eedbc7ee
commit
70c8f2fd01
@ -25,7 +25,7 @@ class CandidatoController extends Controller {
|
|||||||
public function accessRules() {
|
public function accessRules() {
|
||||||
return array(
|
return array(
|
||||||
array('allow',
|
array('allow',
|
||||||
'actions' => array('index', 'view', 'create', 'update', 'delete', 'admin', 'updateEstado'),
|
'actions' => array('index', 'view', 'create', 'update', 'delete', 'admin', 'updateEstado', 'download'),
|
||||||
'users' => array('@'),
|
'users' => array('@'),
|
||||||
),
|
),
|
||||||
array('deny', // deny all users
|
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'));
|
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
|
* @brief Lista todos los candidatos
|
||||||
|
|||||||
@ -133,7 +133,8 @@ class CandidatoDocumento extends CActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function afterSave() {
|
protected function afterSave() {
|
||||||
$this->guardarFicheroDocumento();
|
if ($this->isNewRecord)
|
||||||
|
$this->guardarFicheroDocumento();
|
||||||
return parent::afterSave();
|
return parent::afterSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +151,6 @@ class CandidatoDocumento extends CActiveRecord {
|
|||||||
|
|
||||||
protected function beforeValidate() {
|
protected function beforeValidate() {
|
||||||
if ($this->ficheroDocumento) {
|
if ($this->ficheroDocumento) {
|
||||||
$upload = $this->candidato->getUploadPath();
|
|
||||||
$this->nombre_fichero = $this->generarNombreFicheroDocumento();
|
$this->nombre_fichero = $this->generarNombreFicheroDocumento();
|
||||||
Yii::trace('Nombre para el documento: ' . $this->nombre_fichero, 'application.models.CandidatoDocumento');
|
Yii::trace('Nombre para el documento: ' . $this->nombre_fichero, 'application.models.CandidatoDocumento');
|
||||||
}
|
}
|
||||||
@ -182,7 +182,17 @@ class CandidatoDocumento extends CActiveRecord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $filename;
|
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
|
* Guarda un documento subido por el usuario
|
||||||
@ -197,8 +207,7 @@ class CandidatoDocumento extends CActiveRecord {
|
|||||||
if (!$this->ficheroDocumento)
|
if (!$this->ficheroDocumento)
|
||||||
throw new CException(Yii::t('profind', 'Fichero de documento no asignado.'));
|
throw new CException(Yii::t('profind', 'Fichero de documento no asignado.'));
|
||||||
|
|
||||||
$upload = $this->candidato->getUploadPath();
|
$nombre = $this->darRutaCompletaFichero();
|
||||||
$nombre = $upload . $this->nombre_fichero;
|
|
||||||
return $this->ficheroDocumento->saveAs($nombre);
|
return $this->ficheroDocumento->saveAs($nombre);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,8 +220,7 @@ class CandidatoDocumento extends CActiveRecord {
|
|||||||
if (!$this->candidato)
|
if (!$this->candidato)
|
||||||
throw new CException(Yii::t('profind', 'Candidato no asignado.'));
|
throw new CException(Yii::t('profind', 'Candidato no asignado.'));
|
||||||
|
|
||||||
$upload = $this->candidato->getUploadPath();
|
$nombre = $this->darRutaCompletaFichero();
|
||||||
$nombre = $upload . $this->nombre_fichero;
|
|
||||||
return unlink($nombre);
|
return unlink($nombre);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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')); ?>
|
<?php echo CHtml::hiddenField("CandidatoDocumento[$i][_borrar]", '0', array('class' => 'to_remove')); ?>
|
||||||
<input type="hidden" class="rowIndex" value="<?php echo $i;?>" />
|
<input type="hidden" class="rowIndex" value="<?php echo $i;?>" />
|
||||||
<?php if (!$documento->hasErrors()) : ?>
|
<?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; ?>
|
<?php endif; ?>
|
||||||
<a class="btn btn-small remove" href="#"><i class="icon-trash"></i></a>
|
<a class="btn btn-small remove" href="#"><i class="icon-trash"></i></a>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user