src/EventSubscriber/GroupeMessageSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use App\Event\Chat\GroupedMessageSentEvent;
  5. use App\Entity\DiscussionGroup;
  6. use App\Entity\User;
  7. use App\Entity\SystemEmail;
  8. use App\Repository\SystemEmailRepository;
  9. use App\Service\NotificationService;
  10. class GroupeMessageSubscriber implements EventSubscriberInterface
  11. {
  12.   
  13.   public function __construct(private SystemEmailRepository $systemEmailRepository,private NotificationService $notificationService) {
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             GroupedMessageSentEvent::NAME => 'onCreatedGroup',
  19.         ];
  20.     }
  21.     public function onCreatedGroup(GroupedMessageSentEvent $event){
  22.         $group $event->getDiscussionGroup();
  23.         $user $event->getUser();
  24.         $campaign $group->getCampaign();
  25.         if (!$group instanceof DiscussionGroup) {
  26.             return;
  27.         }
  28.         if (!$user instanceof User) {
  29.             return;
  30.         }
  31.         $email $this->systemEmailRepository->findOneBy(['code' => SystemEmail::ADD_GROUPED_MESSAGE]);
  32.         if($email !== null){
  33.             
  34.             $this->notificationService->create(
  35.                 $email$user$user$campaign->getOrderedBy()->getCompany(), null$campaign,null ,false ,false ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null,$group
  36.             );
  37.         }
  38.         
  39.     }   
  40. }