|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
-
- namespace backend\controllers;
-
- use Yii;
- use common\models\User;
- use backend\models\MailForm;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
- use common\helpers\Upload ;
- use common\models\Etablissement ;
-
- /**
- * UserController implements the CRUD actions for User model.
- */
- class EtablissementController extends Controller
- {
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['post'],
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return Yii::$app->user->identity->status == USER::STATUS_ADMIN
- || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
- }
- ]
- ],
- ],
- ];
- }
-
- public function actionUpdate()
- {
- $request = Yii::$app->request ;
- $model = $this->findModel(Yii::$app->user->identity->id_etablissement);
- $logo_filename_old = $model->logo ;
- $photo_filename_old = $model->photo ;
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
-
- Upload::uploadFile($model, 'logo', $logo_filename_old) ;
- Upload::uploadFile($model, 'photo', $photo_filename_old) ;
-
- $delete_logo = $request->post('delete_logo',0) ;
- if($delete_logo) {
- $model->logo = '' ;
- $model->save() ;
- }
-
- $delete_photo = $request->post('delete_photo',0) ;
- if($delete_photo) {
- $model->photo = '' ;
- $model->save() ;
- }
-
- return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
-
- }
-
- protected function findModel($id)
- {
- if (($model = Etablissement::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|