Incam_PROFIND_Web/www/protected/controllers/CandidatoController.php
2012-10-22 15:47:11 +00:00

194 lines
5.8 KiB
PHP

<?php
/**
* @class CandidatoController
* @brief Controlador del modelo del candidato
*
* @package application.controllers
*/
class CandidatoController extends Controller {
/**
* @return array action filters
*/
public function filters() {
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules() {
return array(
array('allow',
'actions' => array('index', 'view', 'create', 'update', 'delete', 'admin', 'updateEstado'),
'users' => array('@'),
),
);
}
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id) {
$this->render('view', array(
'model' => $this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate() {
$candidato = new Candidato;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Candidato'])) {
$candidato->attributes = $_POST['Candidato'];
if ($candidato->save())
$this->redirect(array('index'));
}
$this->render('create', array(
'candidato' => $candidato,
));
}
/**
* @brief Modificar un candidato.
* @param integer $id el ID del candidato a modificar
*/
public function actionUpdate($id) {
$candidato = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($candidato);
if (isset($_POST['Candidato'])) {
$candidato->attributes = $_POST['Candidato'];
$ficheroFotografia = CUploadedFile::getInstance($candidato, 'ficheroFotografia');
$quitarFotografia = Yii::app()->request->getParam('quitar_fotografia', '0');
if ($candidato->save()) {
if (($quitarFotografia == '1') && ($candidato->fotografia->tieneFotografia()))
$candidato->fotografia->eliminarFotografia();
if ($ficheroFotografia)
$candidato->fotografia->guardarFotografia($ficheroFotografia);
Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha actualizado el candidato'));
$this->redirect(array('index'));
}
}
$this->render('update', array(
'candidato' => $candidato,
));
}
public function actionUpdateEstado($id) {
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if (isset($_GET['ajax']))
var_dump($_GET['ajax']);
if (isset($_POST['Candidato'])) {
$model->id_estado = $_POST['Candidato']['id_estado'];
if ($model->save()) {
} else {
}
} else {
echo $this->renderPartial('_form_estado', array('model' => $model, false, true));
}
}
/**
* 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
*/
public function actionDelete($id) {
if (Yii::app()->request->isPostRequest) {
// we only allow deletion via POST request
$this->loadModel($id)->delete();
$this->borrarFoto($id);
Yii::app()->user->setFlash('success', "Candidato eliminardo 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.');
}
/**
* @brief Lista todos los candidatos
*
*/
public function actionIndex() {
$candidatos = new Candidato('search');
$candidatos->unsetAttributes(); // clear any default values
if (isset($_GET['Candidato']))
$candidatos->attributes = $_GET['Candidato'];
$this->render('index', array(
'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
* @param integer $id el ID del candidato a recuperar
*/
public function loadModel($id) {
Yii::trace('Cargar el modelo', 'application.controllers.CandidatoController');
$model = Candidato::model()->findByPk($id);
if ($model === null)
throw new CHttpException(404, Yii::t('profind', 'La página solicitada no existe.'));
return $model;
}
}
?>