<?php
/*
* @since 1.0.0
* @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
* @website http://artmedia.biz.pl
* @author Arkadiusz Tobiasz
* @email kontakt@artmedia.biz.pl
*/
namespace App\EventSubscriber\Core;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Events\Core\NotificationAddEvent;
use App\Events\Core\NotificationEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Entity\Profile\Follow;
use App\Settings\SettingsManager;
use App\Manager\Core\Mail\MailsManager;
class NotificationSubscriber implements EventSubscriberInterface
{
private $translator;
private $mailsManager;
private $settingsManager;
public function __construct(
MailsManager $mailsManager,
SettingsManager $settingsManager,
TranslatorInterface $translator
) {
$this->translator = $translator;
$this->mailsManager = $mailsManager;
$this->settingsManager = $settingsManager;
}
public static function getSubscribedEvents(): array
{
return [
NotificationAddEvent::NAME => 'onNotificationAddEvent',
NotificationEvent::NAME => 'onNotificationEvent',
];
}
public function onNotificationEvent(NotificationEvent $event): void
{
$html = $event->getTemplate() . '.html.twig';
$txt = $event->getTemplate() . '.txt.twig';
$this->mailsManager->create(
$this->settingsManager->get(SettingsManager::CORE_SITE_MAIL, true),
$event->getUser()->getEmail(),
$event->getTitle(),
$html,
$txt,
$event->getParams(),
3,
);
$this->mailsManager->addToQuene();
}
public function onNotificationAddEvent(NotificationAddEvent $event): void
{
$event->addNotification(Follow::NOTIFICATION, $this->translator->trans('Someone follow one of my profiles', [], 'email_notification'));
}
}