<?php
declare(strict_types=1);
namespace App\Bundles\OrganizationBundle\EventListener;
use App\Bundles\EpidemiologicalSurveillanceBundle\Service\SurveillanceTemplateDeleteService;
use App\Bundles\OrganizationBundle\Event\UserOrganizationDeletedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UserOrganizationChangedListener implements EventSubscriberInterface
{
public function __construct(
private readonly SurveillanceTemplateDeleteService $surveillanceTemplateDeleteService,
) {
}
public static function getSubscribedEvents(): array
{
return [
UserOrganizationDeletedEvent::NAME => 'onUserOrganizationDeleted',
];
}
public function onUserOrganizationDeleted(UserOrganizationDeletedEvent $event): void
{
$this->surveillanceTemplateDeleteService->deleteAllSharedForUser(
$event->getUserOrganization()->getUser()
);
}
}