2012-09-28 15:35:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-10-12 19:22:31 +00:00
|
|
|
class SubscripcionController extends Controller {
|
|
|
|
|
|
|
|
|
|
public $defaultAction = 'modificar';
|
|
|
|
|
|
2012-10-02 19:50:45 +00:00
|
|
|
/**
|
|
|
|
|
* @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('modificar'),
|
|
|
|
|
'users' => array('@'),
|
|
|
|
|
'expression' => 'Yii::app()->user->esCoordinador',
|
|
|
|
|
),
|
|
|
|
|
array('deny', // deny all users
|
|
|
|
|
'users' => array('*'),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-12 19:22:31 +00:00
|
|
|
public function actionModificar($id) {
|
|
|
|
|
Yii::trace('Ver/modificar la subscripción del usuario', 'application.controllers.SubscripcionController');
|
|
|
|
|
|
|
|
|
|
if ($id != Yii::app()->user->subscripcion->id)
|
|
|
|
|
throw new CHttpException(401, Yii::t('profind', 'Acceso no autorizado.'));
|
|
|
|
|
|
|
|
|
|
$subscripcion = $this->loadModel($id);
|
|
|
|
|
$criterial = new CDbCriteria();
|
|
|
|
|
$criterial->order = 'tipo DESC, id';
|
|
|
|
|
$productos = Producto::model()->findAll($criterial);
|
2012-09-28 18:30:16 +00:00
|
|
|
|
|
|
|
|
if (isset($_POST['Subscripcion'])) {
|
2012-10-12 19:22:31 +00:00
|
|
|
$subscripcion->attributes = $_POST['Subscripcion'];
|
2012-09-30 20:00:15 +00:00
|
|
|
|
2012-10-12 19:22:31 +00:00
|
|
|
if ($subscripcion->save()) {
|
|
|
|
|
Yii::trace('Se ha modificado la subscripción del usuario', 'application.controllers.UsuarioController');
|
|
|
|
|
EMail::enviarNotificacionCambioProducto(Yii::app()->user->email, $subscripcion->producto->id);
|
|
|
|
|
Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha actualizado su producto'));
|
|
|
|
|
$this->redirect(array('modificar', 'id' => $id));
|
2012-09-28 15:35:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-12 19:22:31 +00:00
|
|
|
$this->render('index', array(
|
|
|
|
|
'subscripcion' => $subscripcion,
|
|
|
|
|
'productos' => $productos,
|
2012-09-28 15:35:31 +00:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the data model based on the primary key given in the GET variable.
|
|
|
|
|
* If the data model is not found, an HTTP exception will be raised.
|
|
|
|
|
* @param integer the ID of the model to be loaded
|
|
|
|
|
*/
|
|
|
|
|
public function loadModel($id) {
|
2012-09-28 18:30:16 +00:00
|
|
|
$model = Subscripcion::model()->findByPk($id);
|
2012-09-28 15:35:31 +00:00
|
|
|
if ($model === null)
|
|
|
|
|
throw new CHttpException(404, Yii::t('profind', 'La página solicitada no existe.'));
|
|
|
|
|
|
|
|
|
|
return $model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|