[ '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(Producer::getId()); $logoFilenameOld = $model->logo; $photoFilenameOld = $model->photo; if ($model->load(Yii::$app->request->post()) && $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(); } return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); } else { 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' => Producer::getId()]) ->orderBy('reference DESC'), 'pagination' => [ 'pageSize' => 1000, ], ]); $producer = Producer::findOne(Producer::getId()); 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.'); } } }