<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Event\Chat\GroupedMessageSentEvent;
use App\Entity\DiscussionGroup;
use App\Entity\User;
use App\Entity\SystemEmail;
use App\Repository\SystemEmailRepository;
use App\Service\NotificationService;
class GroupeMessageSubscriber implements EventSubscriberInterface
{
public function __construct(private SystemEmailRepository $systemEmailRepository,private NotificationService $notificationService) {
}
public static function getSubscribedEvents(): array
{
return [
GroupedMessageSentEvent::NAME => 'onCreatedGroup',
];
}
public function onCreatedGroup(GroupedMessageSentEvent $event){
$group = $event->getDiscussionGroup();
$user = $event->getUser();
$campaign = $group->getCampaign();
if (!$group instanceof DiscussionGroup) {
return;
}
if (!$user instanceof User) {
return;
}
$email = $this->systemEmailRepository->findOneBy(['code' => SystemEmail::ADD_GROUPED_MESSAGE]);
if($email !== null){
$this->notificationService->create(
$email, $user, $user, $campaign->getOrderedBy()->getCompany(), null, $campaign,null ,false ,false ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null,$group
);
}
}
}