src/Modules/Notification/Event/Subscriber/SendFormFinalizedNotification.php line 71

Open in your IDE?
  1. <?php
  2. namespace App\Modules\Notification\Event\Subscriber;
  3. use App\Modules\Contract\Event\ContractCreated;
  4. use App\Modules\Contract\Event\FormAccepted;
  5. use App\Modules\Contract\Event\FormFinalized;
  6. use App\Modules\Notification\Entity\NotificationEntity;
  7. use App\Modules\Notification\Message\System\FormCreatedNotification;
  8. use App\Modules\Notification\Message\System\FormRequestAcceptedNotification;
  9. use App\Modules\Notification\Message\System\FormRequestFinalizedNotification;
  10. use App\Modules\Notification\Service\NotificationService;
  11. use App\Modules\Contract\Service\ParticipantDetailsService;
  12. use App\Modules\User\Service\RepresentativesService;
  13. use App\Service\WebRoutes;
  14. use Psr\Log\LoggerInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class SendFormFinalizedNotification implements EventSubscriberInterface
  17. {
  18.     private $notificationService;
  19.     private $logger;
  20.     /**
  21.      * @var ParticipantDetailsService
  22.      */
  23.     private $participantDetailsService;
  24.     /**
  25.      * @var RepresentativesService
  26.      */
  27.     private $representativesService;
  28.     public function __construct(
  29.         NotificationService $notificationService,
  30.         ParticipantDetailsService $participantDetailsService,
  31.         RepresentativesService $representativesService,
  32.         LoggerInterface $logger
  33.     )
  34.     {
  35.         $this->notificationService $notificationService;
  36.         $this->logger $logger;
  37.         $this->participantDetailsService $participantDetailsService;
  38.         $this->representativesService $representativesService;
  39.     }
  40.     /**
  41.      * Returns an array of event names this subscriber wants to listen to.
  42.      *
  43.      * The array keys are event names and the value can be:
  44.      *
  45.      *  * The method name to call (priority defaults to 0)
  46.      *  * An array composed of the method name to call and the priority
  47.      *  * An array of arrays composed of the method names to call and respective
  48.      *    priorities, or 0 if unset
  49.      *
  50.      * For instance:
  51.      *
  52.      *  * ['eventName' => 'methodName']
  53.      *  * ['eventName' => ['methodName', $priority]]
  54.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  55.      *
  56.      * @return array The event names to listen to
  57.      */
  58.     public static function getSubscribedEvents()
  59.     {
  60.         return [
  61.             FormFinalized::class => ['sendNotification']
  62.         ];
  63.     }
  64.     public function sendNotification(FormFinalized $event)
  65.     {
  66.         try {
  67.             $form $event->getForm();
  68.             $contract $form->getContract();
  69.             $initiator $contract->getInitiator();
  70.             $executor $contract->getExecutor();
  71.             $sender $this->participantDetailsService->get($executor->getId(), $executor->getType());
  72.             is_null($sender) ? $senderName '' $senderName $sender->getName();
  73.             $refNumber  $contract->getRef();
  74.             $link = ['entity' => NotificationEntity::TCCS_MANAGEMENT];
  75.             $receivers $this->representativesService->get($initiator->getId(), $initiator->getType());
  76.             $notification = new FormRequestFinalizedNotification($refNumber$link$senderName$receivers);
  77.             $this->notificationService->sendSystem($notification);
  78.         } catch (\Exception $e) {
  79.             $this->logger->error($e->getMessage());
  80.         }
  81.     }
  82. }