<?php
namespace App\EventSubscriber;
use App\Event\ResourceLivrable\LivrableAddedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\MessageEvent;
use App\Event\VirusCamp\VirusCampEvent;
use App\Event\VirusCamp\FileInfectedEvent;
use App\Service\DynamicHostService;
use App\Repository\SystemEmailRepository;
use App\Entity\SystemEmail;
use App\Service\NotificationService;
class LivrableSubscriver implements EventSubscriberInterface
{
public function __construct(
private NotificationService $notificationService,
private SystemEmailRepository $systemEmailRepository,
private DynamicHostService $dynamicHostService,
){
}
public static function getSubscribedEvents()
{
return [
LivrableAddedEvent::NAME => 'onLivrableAdded',
];
}
public function onLivrableAdded(LivrableAddedEvent $livrableAddedEvent){
$mission = $livrableAddedEvent->getMission();
$user = $livrableAddedEvent->getUser();
$files = $livrableAddedEvent->getFiles();
$email = empty($files) ? $this->systemEmailRepository->findOneBy(['code' => SystemEmail::NONE_LIVRABLE]) : $this->systemEmailRepository->findOneBy(['code' => SystemEmail::HAVE_LIVRABLE]);
foreach ($mission->getParticipants() as $participant) {
if(
!in_array('ROLE_SUBCONTRACTOR', $participant->getUser()->getRoles()) &&
!in_array($participant->getRole(), ['ROLE_SUBCONTRACTOR', 'ROLE_VALIDATOR_EXTERNAL','ROLE_OBSERVER_EXTERNAL'])
){
$this->notificationService->create(
$email,
$user,
$user,
$mission->getCampaign()->getOrderedBy()->getCompany(),
null,
$mission->getCampaign(),
null,
false,
false,
null,
null,
$mission);
}
}
if (null !== $email) {
$admins = $this->dynamicHostService->getMailAdmin();
foreach ($admins as $admin) {
$this->notificationService->create($email, $admin->value, $mission->getCampaign()->getOrderedBy(), $mission->getCampaign()->getOrderedBy()->getCompany(),null,null,null,false,false,null,null,$mission);
}
}
}
}