<?php
declare(strict_types=1);
namespace App\Services\Campaign\EventSubscriber;
use App\Event\Activity\ActivityDeclinedEvent;
use App\Services\Activity\ActivityServiceInterface;
use App\Services\Activity\Event\ActivityPriceUpdatedEvent;
use App\Services\Campaign\CampaignServiceInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ActivityEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
ActivityPriceUpdatedEvent::class => 'updatePaid',
ActivityDeclinedEvent::class => 'onDeclined',
];
}
public function __construct(
private ActivityServiceInterface $activityService,
private CampaignServiceInterface $campaignService,
) {
}
public function updatePaid(ActivityPriceUpdatedEvent $event): void
{
$campaignId = $this->activityService->getCampaignId($event->getId());
$this->campaignService->updatePrice($campaignId);
}
public function onDeclined(ActivityDeclinedEvent $event): void
{
$campaignId = $event->getActivity()->getCampaign()->getId();
$this->campaignService->updatePrice($campaignId);
}
}