[ 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['post'], ], ], 'access' => [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserManager()->hasAccessBackend(); } ] ], ], ]; } /** * Modifie un producteur. */ public function actionUpdate() { $producerManager = $this->getProducerManager(); $request = Yii::$app->request; $model = $this->findModel(GlobalParam::getCurrentProducerId()); $logoFilenameOld = $model->logo; $photoFilenameOld = $model->photo; if (strlen($model->option_dashboard_date_start)) { $model->option_dashboard_date_start = date('d/m/Y', strtotime($model->option_dashboard_date_start)); } if (strlen($model->option_dashboard_date_end)) { $model->option_dashboard_date_end = date('d/m/Y', strtotime($model->option_dashboard_date_end)); } if ($model->load(\Yii::$app->request->post()) && $model->save()) { if (strlen($model->option_dashboard_date_start)) { $model->option_dashboard_date_start = date( 'Y-m-d', strtotime(str_replace('/', '-', $model->option_dashboard_date_start) )); $model->save(); } if (strlen($model->option_dashboard_date_end)) { $model->option_dashboard_date_end = date( 'Y-m-d', strtotime(str_replace('/', '-', $model->option_dashboard_date_end)) ); $model->save(); } Upload::uploadFile($model, 'logo', $logoFilenameOld); Upload::uploadFile($model, 'photo', $photoFilenameOld); $deleteLogo = $request->post('delete_logo', 0); if ($deleteLogo) { $model->logo = ''; $model->save(); } $deletePhoto = $request->post('delete_photo', 0); if ($deletePhoto) { $model->photo = ''; $model->save(); } $producerManager->savePrivateKeyApiStripe($model); $producerManager->savePrivateKeyEndpointStripe($model); $model->option_stripe_private_key = ''; $model->option_stripe_endpoint_secret = ''; $model->save(); $this->setFlash('success', 'Paramètres mis à jour.'); return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); } else { if ($model->load(\Yii::$app->request->post())) { $this->setFlash('error', 'Le formulaire comporte des erreurs.'); } return $this->render('update', [ 'model' => $model, ]); } } /** * Affiche le formulaire permettant au producteur de définir le montant * de son abonnement. */ public function actionBilling() { $producer = Producer::findOne(GlobalParam::getCurrentProducerId()); if ($producer->load(\Yii::$app->request->post())) { $producer->save(); if (!is_null($producer->free_price)) { $alertFreeprice = true; } } $dataProviderPrices = new ActiveDataProvider([ 'query' => ProducerPriceRange::find() ->orderBy('id ASC'), 'pagination' => [ 'pageSize' => 100, ], ]); return $this->render('billing', [ 'dataProviderPrices' => $dataProviderPrices, 'producer' => $producer, 'alertFreePrice' => (isset($alertFreeprice)) ? true : false ]); } /** * Recherche un établissement via son ID. */ protected function findModel(int $id) { if (($model = Producer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } public function actionUpdateOpendistribVersion() { $producerManager = $this->getProducerManager(); $producerManager->updateOpendistribVersion(GlobalParam::getCurrentProducer()); return $this->redirect(\Yii::$app->request->referrer); } }