src/Services/Campaign/EventSubscriber/ActivityEventSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Services\Campaign\EventSubscriber;
  4. use App\Event\Activity\ActivityDeclinedEvent;
  5. use App\Services\Activity\ActivityServiceInterface;
  6. use App\Services\Activity\Event\ActivityPriceUpdatedEvent;
  7. use App\Services\Campaign\CampaignServiceInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class ActivityEventSubscriber implements EventSubscriberInterface
  10. {
  11.     public static function getSubscribedEvents(): array
  12.     {
  13.         return [
  14.             ActivityPriceUpdatedEvent::class => 'updatePaid',
  15.             ActivityDeclinedEvent::class => 'onDeclined',
  16.         ];
  17.     }
  18.     public function __construct(
  19.         private ActivityServiceInterface $activityService,
  20.         private CampaignServiceInterface $campaignService,
  21.     ) {
  22.     }
  23.     public function updatePaid(ActivityPriceUpdatedEvent $event): void
  24.     {
  25.         $campaignId $this->activityService->getCampaignId($event->getId());
  26.         $this->campaignService->updatePrice($campaignId);
  27.     }
  28.     public function onDeclined(ActivityDeclinedEvent $event): void
  29.     {
  30.         $campaignId $event->getActivity()->getCampaign()->getId();
  31.         $this->campaignService->updatePrice($campaignId);
  32.     }
  33. }