[ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { $authorizationChecker = $this->getUserModule()->getAuthorizationChecker(); $featureChecker = $this->getFeatureModule()->getChecker(); return $authorizationChecker->isGrantedAsProducer($this->getUserCurrent()) && $featureChecker->isEnabled(Feature::ALIAS_SHARED_POINT_SALE); } ] ], ], ]; } public function actionIndex() { $sharedPointSaleRepository = $this->getSharedPointSaleModule()->getRepository(); return $this->render('index', [ 'sharedPointsSaleRequestOfMe' => $sharedPointSaleRepository->findSharedPointsSaleRequestsOfMe(), 'sharedPointsSaleRequestOthers' => $sharedPointSaleRepository->findSharedPointsSaleRequestsOthers(), 'pointsSaleArray' => $this->getPointSaleModule()->getRepository()->findPointSales() ]); } public function actionCreate() { $sharedPointSaleModule = $this->getSharedPointSaleModule(); $sharedPointSaleModel = $sharedPointSaleModule->getBuilder()->instanciateSharedPointSale(null, null, $this->getUserCurrent()); if($sharedPointSaleModel->load(\Yii::$app->request->post()) && $sharedPointSaleModel->validate()) { $sharedPointSaleModule->getManager()->createSharedPointSale( $sharedPointSaleModel->getPointSale(), $sharedPointSaleModel->getProducerWithSharing(), $this->getUserCurrent() ); $this->setFlash('success', "La demande de partage a bien été créée"); return $this->redirect(['index']); } return $this->render('create', [ 'sharedPointSaleModel' => $sharedPointSaleModel ]); } public function actionConfirm(int $id) { $sharedPointSale = $this->findSharedPointSale($id); $sharedPointSale->scenario = SharedPointSale::SCENARIO_CONFIRM; if($sharedPointSale->load(\Yii::$app->request->post()) && $sharedPointSale->validate()) { $pointSaleWithSharing = $sharedPointSale->getPointSaleWithSharing(); if($this->getSharedPointSaleModule()->getManager()->confirmSharedPointSale($sharedPointSale, $pointSaleWithSharing, $this->getUserCurrent())) { $this->addFlash('success', "Le partage de point de vente a bien été confirmé"); } else { $this->addFlash('error', "Une erreur est survenue lors de la confirmation du partage"); } } else { $this->addFlash('error', "Veuillez sélectionner un point de vente pour confirmer le partage"); } return $this->redirect(['index']); } public function actionDecline(int $id) { $sharedPointSale = $this->findSharedPointSale($id); if($this->getSharedPointSaleModule()->getManager()->declineSharedPointSale($sharedPointSale, $this->getUserCurrent())) { $this->addFlash('success', "La demande de partage de point de vente a bien été annulée."); } else { $this->addFlash('error', "Une erreur est survenue lors de l'annulation de la demande de partage."); } return $this->redirect(['index']); } public function findSharedPointSale(int $id) { $sharedPointSale = $this->getSharedPointSaleModule()->getRepository()->findOneSharedPointSaleById($id); if(!$sharedPointSale) { throw new NotFoundHttpException("La demande de point de vente partagé n'a pas été trouvée."); } return $sharedPointSale; } }