src/Listener/StoreWorflowListener.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: bertrand
  5.  * Date: 29/03/2019
  6.  * Time: 13:53
  7.  */
  8. namespace App\Listener;
  9. use App\Entity\StoreManagementRequest;
  10. use App\Service\StoreManagementRequestService;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Psr\Log\LoggerInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\Workflow\Event\Event;
  15. class StoreWorflowListener implements EventSubscriberInterface
  16. {
  17.     private $logger;
  18.     private $storeManagementRequestService;
  19.     private $entityManager;
  20.     public function __construct(LoggerInterface $loggerStoreManagementRequestService $storeManagementRequestServiceEntityManagerInterface $entityManager)
  21.     {
  22.         $this->logger $logger;
  23.         $this->storeManagementRequestService $storeManagementRequestService;
  24.         $this->entityManager $entityManager;
  25.     }
  26.     public function onValidation(Event $event){
  27.         $store $event->getSubject();
  28.         $store->setAcquisitionEnabled(true);
  29.         $this->logger->info('Validation du centre: activation des leads par défaut');
  30.     }
  31.     public function onRejectCreation(Event $event)
  32.     {
  33.         $store $event->getSubject();
  34.         $this->entityManager->remove($store);
  35.         $this->entityManager->flush();
  36.     }
  37.     public function onAskForSuppression(Event $event)
  38.     {
  39.         $store $event->getSubject();
  40.         $this->storeManagementRequestService->createNewSuppressionRequestForStore($store);
  41.     }
  42.     public function onValidateSuppression(Event $event)
  43.     {
  44.         $store $event->getSubject();
  45.         $this->entityManager->remove($store);
  46.         $this->entityManager->flush();
  47.     }
  48.     public static function getSubscribedEvents()
  49.     {
  50.         return [
  51.             'workflow.store.completed.validate' => 'onValidation',
  52.             'workflow.store.completed.reject' => 'onRejectCreation',
  53.             'workflow.store.completed.askForSuppression' => 'onAskForSuppression',
  54.             'workflow.store.completed.validate_suppression' => 'onValidateSuppression',
  55.         ];
  56.     }
  57. }