src/EventsSubscriber/Activity/ActivityEventSubscriber.php line 59

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\EventsSubscriber\Activity;
  4. use App\Contracts\Activity\Status;
  5. use App\Event\Activity\ActivityActivatedEvent;
  6. use App\Event\Activity\ApproveAllReviewEvent;
  7. use App\Event\Activity\DeclineAllReviewEvent;
  8. use App\Event\Activity\DeclineCampaignActivityEvent;
  9. use App\Event\Campaign\RenewedCampaignEvent;
  10. use App\Messenger\Activity\ApproveAllReviewMessage;
  11. use App\Messenger\Activity\DeclineAllReviewMessage;
  12. use App\Messenger\Activity\DeclineCampaignActivityMessage;
  13. use App\Services\Activity\ActivityServiceInterface;
  14. use App\Services\Campaign\CampaignServiceInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\Messenger\MessageBusInterface;
  17. class ActivityEventSubscriber implements EventSubscriberInterface
  18. {
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             ActivityActivatedEvent::class => 'onActivityActivated',
  23.             DeclineAllReviewEvent::class => 'declineAllReview',
  24.             ApproveAllReviewEvent::class => 'approveAllReview',
  25.             DeclineCampaignActivityEvent::class => 'declineCampaignActivity',
  26.             RenewedCampaignEvent::class => ['onRenewedCampaign'10],
  27.         ];
  28.     }
  29.     public function __construct(
  30.         private readonly MessageBusInterface $bus,
  31.         private readonly ActivityServiceInterface $activityService,
  32.         private readonly CampaignServiceInterface $campaignService,
  33.     ) {}
  34.     public function onActivityActivated(ActivityActivatedEvent $event): void
  35.     {
  36.         $this->campaignService->updateCampaignStatistics($event->getActivity()->getCampaign()->getId());
  37.     }
  38.     public function declineAllReview(DeclineAllReviewEvent $event): void
  39.     {
  40.         $this->bus->dispatch(
  41.             new DeclineAllReviewMessage($event->getCampaign()->getId(), $event->getReason()),
  42.         );
  43.     }
  44.     public function approveAllReview(ApproveAllReviewEvent $event): void
  45.     {
  46.         $this->bus->dispatch(
  47.             new ApproveAllReviewMessage($event->getCampaign()->getId()),
  48.         );
  49.     }
  50.     public function declineCampaignActivity(DeclineCampaignActivityEvent $event): void
  51.     {
  52.         $this->bus->dispatch(
  53.             new DeclineCampaignActivityMessage($event->getCampaign()->getId()),
  54.         );
  55.     }
  56.     public function onRenewedCampaign(RenewedCampaignEvent $event): void
  57.     {
  58.         $activities $this->activityService->getCampaignActivitiesByStatuses(
  59.             $event->getCampaign()->getId(),
  60.             [
  61.                 Status::ACCEPTED,
  62.                 Status::SPONSOR_REVIEW,
  63.                 Status::VIDEO_PENDING,
  64.                 Status::SPONSOR_DECLINE,
  65.                 Status::DRAFT_VIDEO_REVIEW,
  66.             ]
  67.         );
  68.         $this->activityService->deleteActivities($activities);
  69.     }
  70. }