2012-09-20 19:38:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class EmpresaController extends Controller {
|
|
|
|
|
|
2012-10-02 19:36:18 +00:00
|
|
|
public $defaultAction = 'modificar';
|
|
|
|
|
|
2012-09-20 19:38:42 +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(
|
2012-10-02 19:50:45 +00:00
|
|
|
array('allow',
|
2012-10-02 19:36:18 +00:00
|
|
|
'actions' => array('modificar'),
|
2012-09-20 19:38:42 +00:00
|
|
|
'users' => array('@'),
|
2012-10-02 19:50:45 +00:00
|
|
|
'expression' => 'Yii::app()->user->esCoordinador',
|
2012-09-20 19:38:42 +00:00
|
|
|
),
|
|
|
|
|
array('deny', // deny all users
|
|
|
|
|
'users' => array('*'),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates a particular model.
|
|
|
|
|
* If update is successful, the browser will be redirected to the 'view' page.
|
|
|
|
|
* @param integer $id the ID of the model to be updated
|
2012-09-29 18:15:28 +00:00
|
|
|
* @param string $provider
|
2012-09-20 19:38:42 +00:00
|
|
|
*/
|
2012-09-29 18:15:28 +00:00
|
|
|
public function actionModificar($id, $provider = '') {
|
2012-09-20 19:38:42 +00:00
|
|
|
if ($id != Yii::app()->user->id_empresa)
|
2012-10-12 19:22:31 +00:00
|
|
|
throw new CHttpException(401, Yii::t('profind', 'Acceso no autorizado.'));
|
2012-09-20 19:38:42 +00:00
|
|
|
|
2012-09-29 18:15:28 +00:00
|
|
|
if (($provider != '') && (!isset($_POST['Empresa']))) {
|
|
|
|
|
switch ($provider) {
|
|
|
|
|
case 'Twitter':
|
|
|
|
|
case 'Facebook':
|
|
|
|
|
case 'LinkedIn':
|
|
|
|
|
$empresa = $this->loadModelwithSocialData($id, $provider);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new CHttpException(404, Yii::t('profind', 'La página solicitada no existe.'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
$empresa = $this->loadModel($id);
|
2012-09-20 19:38:42 +00:00
|
|
|
|
|
|
|
|
// Uncomment the following line if AJAX validation is needed
|
2012-10-09 11:44:12 +00:00
|
|
|
// $this->performAjaxValidation($model, 'empresa-form');
|
2012-09-20 19:38:42 +00:00
|
|
|
|
|
|
|
|
if (isset($_POST['Empresa'])) {
|
2012-09-29 18:15:28 +00:00
|
|
|
$empresa->attributes = $_POST['Empresa'];
|
2012-10-01 15:15:00 +00:00
|
|
|
$ficheroLogotipo = CUploadedFile::getInstance($empresa, 'ficheroLogotipo');
|
2012-10-01 15:38:32 +00:00
|
|
|
|
2012-10-01 15:15:00 +00:00
|
|
|
$quitarLogotipo = Yii::app()->request->getParam('quitar_logotipo', '0');
|
|
|
|
|
|
2012-09-29 18:15:28 +00:00
|
|
|
if ($empresa->save()) {
|
2012-10-01 15:15:00 +00:00
|
|
|
if (($quitarLogotipo == '1') && ($empresa->logotipo->tieneFotografia()))
|
|
|
|
|
$empresa->logotipo->eliminarFotografia();
|
|
|
|
|
|
|
|
|
|
if ($ficheroLogotipo)
|
|
|
|
|
$empresa->logotipo->guardarFotografia($ficheroLogotipo);
|
|
|
|
|
|
2012-09-20 19:38:42 +00:00
|
|
|
Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha actualizado los datos de la empresa'));
|
2012-09-29 18:15:28 +00:00
|
|
|
$this->redirect(array('modificar', 'id' => $empresa->id));
|
2012-09-20 19:38:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->render('modificar', array(
|
2012-09-29 18:15:28 +00:00
|
|
|
'model' => $empresa,
|
2012-09-20 19:38:42 +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) {
|
|
|
|
|
$model = Empresa::model()->findByPk($id);
|
|
|
|
|
if ($model === null)
|
2012-09-24 23:14:37 +00:00
|
|
|
throw new CHttpException(404, Yii::t('profind', 'La página solicitada no existe.'));
|
2012-09-20 19:38:42 +00:00
|
|
|
return $model;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-29 18:15:28 +00:00
|
|
|
public function loadModelwithSocialData($id, $provider) {
|
|
|
|
|
$empresa = $this->loadModel($id);
|
|
|
|
|
|
|
|
|
|
if (!Yii::app()->socialConnect->loadUserProfile($provider)) {
|
|
|
|
|
throw new CHttpException(
|
|
|
|
|
Yii::app()->socialConnect->errorCode,
|
|
|
|
|
Yii::t('profind', Yii::app()->socialConnect->errorMessage)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$profile = Yii::app()->socialConnect->userProfile;
|
|
|
|
|
|
|
|
|
|
Yii::log(CVarDumper::dumpAsString($profile));
|
|
|
|
|
|
|
|
|
|
$empresa->nombre = $profile->displayName;
|
|
|
|
|
$empresa->pagina_web = $profile->webSiteURL;
|
|
|
|
|
$empresa->email = $profile->email;
|
|
|
|
|
$empresa->descripcion = $profile->description;
|
|
|
|
|
|
|
|
|
|
switch ($provider) {
|
|
|
|
|
case 'Twitter':
|
|
|
|
|
$empresa->direccion = $profile->region;
|
|
|
|
|
break;
|
|
|
|
|
case 'Facebook':
|
|
|
|
|
case 'LinkedIn':
|
|
|
|
|
$empresa->direccion = $profile->city;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $empresa;
|
|
|
|
|
}
|
2012-09-20 19:38:42 +00:00
|
|
|
}
|