src/EventSubscriber/LivrableSubscriver.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\ResourceLivrable\LivrableAddedEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Mailer\Event\MessageEvent;
  6. use App\Event\VirusCamp\VirusCampEvent;
  7. use App\Event\VirusCamp\FileInfectedEvent;
  8. use App\Service\DynamicHostService;
  9. use App\Repository\SystemEmailRepository;
  10. use App\Entity\SystemEmail;
  11. use App\Service\NotificationService;
  12. class LivrableSubscriver implements EventSubscriberInterface
  13. {
  14.     public function __construct(
  15.         private NotificationService $notificationService
  16.         private SystemEmailRepository $systemEmailRepository,
  17.         private DynamicHostService $dynamicHostService
  18.     ){
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             LivrableAddedEvent::NAME => 'onLivrableAdded',
  24.         ];
  25.     }
  26.     public function onLivrableAdded(LivrableAddedEvent $livrableAddedEvent){
  27.         $mission  $livrableAddedEvent->getMission(); 
  28.         $user $livrableAddedEvent->getUser(); 
  29.         $files $livrableAddedEvent->getFiles(); 
  30.         $email =  empty($files) ? $this->systemEmailRepository->findOneBy(['code' => SystemEmail::NONE_LIVRABLE]) :  $this->systemEmailRepository->findOneBy(['code' => SystemEmail::HAVE_LIVRABLE]);
  31.         foreach ($mission->getParticipants() as $participant) {
  32.             if(
  33.                 !in_array('ROLE_SUBCONTRACTOR'$participant->getUser()->getRoles()) && 
  34.                 !in_array($participant->getRole(), ['ROLE_SUBCONTRACTOR''ROLE_VALIDATOR_EXTERNAL','ROLE_OBSERVER_EXTERNAL'])
  35.             ){
  36.                 $this->notificationService->create(
  37.                     $email,
  38.                     $user
  39.                     $user
  40.                     $mission->getCampaign()->getOrderedBy()->getCompany(),
  41.                     null,
  42.                     $mission->getCampaign(),
  43.                     null,
  44.                     false,
  45.                     false,
  46.                     null,
  47.                     null,
  48.                     $mission);
  49.             }
  50.         }
  51.         if (null !== $email) {
  52.            
  53.             
  54.              $admins $this->dynamicHostService->getMailAdmin();
  55.             foreach ($admins as $admin) {
  56.                 $this->notificationService->create($email$admin->value$mission->getCampaign()->getOrderedBy(), $mission->getCampaign()->getOrderedBy()->getCompany(),null,null,null,false,false,null,null,$mission);
  57.             }
  58.         }
  59.     }
  60. }