src/App/EventSubscriber/App/WantedJobEventSubscriber.php line 97

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\App;
  3. use App\Event\WantedJobCreatedDuringProfileCreationEvent;
  4. use App\Event\WantedJobCreatedEvent;
  5. use App\Event\WantedJobEditedEvent;
  6. use App\Event\WantedJobEvent;
  7. use App\Event\WantedJobSharePageRequestedEvent;
  8. use App\Service\ConversionEventService;
  9. use App\Service\NotificationService;
  10. use App\Service\WantedJobService;
  11. use Exception;
  12. use JanusHercules\DatawarehouseIntegration\Domain\Entity\BusinessEvent;
  13. use JanusHercules\DatawarehouseIntegration\Domain\Service\BusinessEventDomainService;
  14. use JanusHercules\Jobradar\Domain\SymfonyMessage\CreateJobradarMatchTriggeredByWantedJobSymfonyMessage;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\Messenger\MessageBusInterface;
  17. class WantedJobEventSubscriber implements EventSubscriberInterface
  18. {
  19. private BusinessEventDomainService $businessEventDomainService;
  20. private NotificationService $notificationService;
  21. private ConversionEventService $conversionEventService;
  22. private WantedJobService $wantedJobService;
  23. private MessageBusInterface $messageBus;
  24. public function __construct(
  25. BusinessEventDomainService $businessEventDomainService,
  26. NotificationService $notificationService,
  27. ConversionEventService $conversionEventService,
  28. WantedJobService $wantedJobService,
  29. MessageBusInterface $messageBus
  30. ) {
  31. $this->businessEventDomainService = $businessEventDomainService;
  32. $this->notificationService = $notificationService;
  33. $this->conversionEventService = $conversionEventService;
  34. $this->wantedJobService = $wantedJobService;
  35. $this->messageBus = $messageBus;
  36. }
  37. public static function getSubscribedEvents()
  38. {
  39. return [
  40. WantedJobCreatedEvent::class => 'onWantedJobCreated',
  41. WantedJobCreatedDuringProfileCreationEvent::class => 'onWantedJobCreatedDuringProfileCreation',
  42. WantedJobEditedEvent::class => 'onWantedJobEdited',
  43. WantedJobSharePageRequestedEvent::class => 'onWantedJobSharePageRequested',
  44. ];
  45. }
  46. /** @throws Exception */
  47. public function onWantedJobCreated(
  48. WantedJobEvent $event
  49. ): void {
  50. if (!is_null($event->getWantedJob())) {
  51. if ($event->getWantedJob()->isPublished()) {
  52. $this->messageBus->dispatch(
  53. new CreateJobradarMatchTriggeredByWantedJobSymfonyMessage(
  54. $event->getWantedJob()
  55. )
  56. );
  57. }
  58. $this->businessEventDomainService->writeNewEvent(
  59. BusinessEvent::EVENT_TYPE_WANTEDJOB_CREATED,
  60. $event->getWantedJob()->getJobseekerProfile()->getUser(),
  61. null,
  62. $event->getWantedJob(),
  63. json_encode(
  64. [
  65. 'id' => $event->getWantedJob()->getId(),
  66. 'searchterm' => $event->getWantedJob()->getOccupationalFieldSearchterm(),
  67. 'zipcode' => $event->getWantedJob()->getZipcode()
  68. ]
  69. )
  70. );
  71. $this->notificationService->uncancelNotification(
  72. $event->getWantedJob()->getJobseekerProfile()->getUser(),
  73. NotificationService::NOTIFICATION_TYPE_UNREAD_CONVERSATION_MESSAGES
  74. );
  75. $this->conversionEventService->handleConversionGoalReached(
  76. ConversionEventService::CAMPAIGN_ID_NOTIFICATION,
  77. NotificationService::NOTIFICATION_TYPE_MISSING_WANTED_JOBS
  78. );
  79. $this->wantedJobService->checkIfWisagNeedsToBeNotified($event->getWantedJob());
  80. }
  81. }
  82. public function onWantedJobCreatedDuringProfileCreation(WantedJobEvent $event): void
  83. {
  84. if (!is_null($event->getWantedJob())) {
  85. if ($event->getWantedJob()->isPublished()) {
  86. $this->messageBus->dispatch(
  87. new CreateJobradarMatchTriggeredByWantedJobSymfonyMessage(
  88. $event->getWantedJob()
  89. )
  90. );
  91. }
  92. $this->businessEventDomainService->writeNewEvent(
  93. BusinessEvent::EVENT_TYPE_WANTEDJOB_CREATED_DURING_PROFILE_CREATION,
  94. $event->getWantedJob()->getJobseekerProfile()->getUser(),
  95. null,
  96. $event->getWantedJob(),
  97. json_encode(
  98. [
  99. 'id' => $event->getWantedJob()->getId(),
  100. 'searchterm' => $event->getWantedJob()->getOccupationalFieldSearchterm(),
  101. 'zipcode' => $event->getWantedJob()->getZipcode()
  102. ]
  103. )
  104. );
  105. $this->wantedJobService->checkIfWisagNeedsToBeNotified($event->getWantedJob());
  106. }
  107. }
  108. /** @throws Exception */
  109. public function onWantedJobEdited(WantedJobEvent $event): void
  110. {
  111. if (!is_null($event->getWantedJob())) {
  112. if ($event->getWantedJob()->isPublished()) {
  113. $this->messageBus->dispatch(
  114. new CreateJobradarMatchTriggeredByWantedJobSymfonyMessage(
  115. $event->getWantedJob()
  116. )
  117. );
  118. }
  119. $this->businessEventDomainService->writeNewEvent(
  120. BusinessEvent::EVENT_TYPE_WANTEDJOB_EDITED,
  121. $event->getWantedJob()->getJobseekerProfile()->getUser(),
  122. null,
  123. $event->getWantedJob(),
  124. json_encode(
  125. [
  126. 'id' => $event->getWantedJob()->getId(),
  127. 'searchterm' => $event->getWantedJob()->getOccupationalFieldSearchterm(),
  128. 'zipcode' => $event->getWantedJob()->getZipcode()
  129. ]
  130. )
  131. );
  132. $this->notificationService->uncancelNotification(
  133. $event->getWantedJob()->getJobseekerProfile()->getUser(),
  134. NotificationService::NOTIFICATION_TYPE_UNREAD_CONVERSATION_MESSAGES
  135. );
  136. }
  137. }
  138. /**
  139. * @throws Exception
  140. */
  141. public function onWantedJobSharePageRequested(WantedJobSharePageRequestedEvent $event): void
  142. {
  143. $this->conversionEventService
  144. ->initiateGoalReachedConversionTrackingBasedOnRequest(
  145. null,
  146. $event->getRequestingUser()
  147. );
  148. }
  149. }