src/Modules/Notification/Event/Subscriber/SendFormPriceUpdatedNotification.php line 73

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