Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

89 lines
2.5KB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use backend\models\MailForm;
  6. use yii\data\ActiveDataProvider;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. use yii\filters\AccessControl;
  11. use common\helpers\Upload ;
  12. use common\models\Etablissement ;
  13. /**
  14. * UserController implements the CRUD actions for User model.
  15. */
  16. class EtablissementController extends Controller
  17. {
  18. public function behaviors()
  19. {
  20. return [
  21. 'verbs' => [
  22. 'class' => VerbFilter::className(),
  23. 'actions' => [
  24. 'delete' => ['post'],
  25. ],
  26. ],
  27. 'access' => [
  28. 'class' => AccessControl::className(),
  29. 'rules' => [
  30. [
  31. 'allow' => true,
  32. 'roles' => ['@'],
  33. 'matchCallback' => function ($rule, $action) {
  34. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  35. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  36. }
  37. ]
  38. ],
  39. ],
  40. ];
  41. }
  42. public function actionUpdate()
  43. {
  44. $request = Yii::$app->request ;
  45. $model = $this->findModel(Yii::$app->user->identity->id_etablissement);
  46. $logo_filename_old = $model->logo ;
  47. $photo_filename_old = $model->photo ;
  48. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  49. Upload::uploadFile($model, 'logo', $logo_filename_old) ;
  50. Upload::uploadFile($model, 'photo', $photo_filename_old) ;
  51. $delete_logo = $request->post('delete_logo',0) ;
  52. if($delete_logo) {
  53. $model->logo = '' ;
  54. $model->save() ;
  55. }
  56. $delete_photo = $request->post('delete_photo',0) ;
  57. if($delete_photo) {
  58. $model->photo = '' ;
  59. $model->save() ;
  60. }
  61. return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]);
  62. } else {
  63. return $this->render('update', [
  64. 'model' => $model,
  65. ]);
  66. }
  67. }
  68. protected function findModel($id)
  69. {
  70. if (($model = Etablissement::findOne($id)) !== null) {
  71. return $model;
  72. } else {
  73. throw new NotFoundHttpException('The requested page does not exist.');
  74. }
  75. }
  76. }