src/EventSubscriber/Core/NotificationSubscriber.php line 44

Open in your IDE?
  1. <?php
  2. /*
  3.  * @since 1.0.0
  4.  * @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
  5.  * @website http://artmedia.biz.pl
  6.  * @author Arkadiusz Tobiasz
  7.  * @email kontakt@artmedia.biz.pl
  8.  */
  9. namespace App\EventSubscriber\Core;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use App\Events\Core\NotificationAddEvent;
  12. use App\Events\Core\NotificationEvent;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use App\Entity\Profile\Follow;
  15. use App\Settings\SettingsManager;
  16. use App\Manager\Core\Mail\MailsManager;
  17. class NotificationSubscriber implements EventSubscriberInterface
  18. {
  19.     private $translator;
  20.     private $mailsManager;
  21.     private $settingsManager;
  22.     public function __construct(
  23.         MailsManager $mailsManager,
  24.         SettingsManager $settingsManager,
  25.         TranslatorInterface $translator
  26.     ) {
  27.         $this->translator $translator;
  28.         $this->mailsManager $mailsManager;
  29.         $this->settingsManager $settingsManager;
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             NotificationAddEvent::NAME => 'onNotificationAddEvent',
  35.             NotificationEvent::NAME => 'onNotificationEvent',
  36.         ];
  37.     }
  38.     public function onNotificationEvent(NotificationEvent $event): void
  39.     {
  40.         $html $event->getTemplate() . '.html.twig';
  41.         $txt $event->getTemplate() . '.txt.twig';
  42.         $this->mailsManager->create(
  43.             $this->settingsManager->get(SettingsManager::CORE_SITE_MAILtrue),
  44.             $event->getUser()->getEmail(),
  45.             $event->getTitle(),
  46.             $html,
  47.             $txt,
  48.             $event->getParams(),
  49.             3,
  50.         );
  51.         $this->mailsManager->addToQuene();
  52.     }
  53.     public function onNotificationAddEvent(NotificationAddEvent $event): void
  54.     {
  55.         $event->addNotification(Follow::NOTIFICATION$this->translator->trans('Someone follow one of my profiles', [], 'email_notification'));
  56.     }
  57. }