[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], ], ], 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return User::hasAccessBackend(); } ] ], ], ]; } /** * Modifie un producteur. * * @return mixed */ public function actionUpdate() { $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(); } $model->savePrivateKeyApiStripe() ; $model->savePrivateKeyEndpointStripe() ; $model->option_stripe_private_key = ''; $model->option_stripe_endpoint_secret = ''; $model->save(); Yii::$app->getSession()->setFlash('success', 'Paramètres mis à jour.'); return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); } else { if($model->load(Yii::$app->request->post())) { Yii::$app->getSession()->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. * * @return mixed */ public function actionBilling() { $datasInvoices = new ActiveDataProvider([ 'query' => Invoice::find() ->where(['id_producer' => GlobalParam::getCurrentProducerId()]) ->orderBy('reference DESC'), 'pagination' => [ 'pageSize' => 1000, ], ]); $producer = Producer::findOne(GlobalParam::getCurrentProducerId()); if ($producer->load(Yii::$app->request->post())) { $producer->save(); if (!is_null($producer->free_price)) { $alertFreeprice = true; } } return $this->render('billing', [ 'datasInvoices' => $datasInvoices, 'producer' => $producer, 'alertFreePrice' => (isset($alertFreeprice)) ? true : false ]); } /** * Recherche un établissement via son ID. * * @param integer $id * @return Etablissement * @throws NotFoundHttpException */ protected function findModel($id) { if (($model = Producer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }