src/EventSubscriber/ProcedureResumeRemindSubscriber.php line 50

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the CosaVostra, TrackPay package.
  4.  *
  5.  * (c) Mohamed Radhi GUENNICHI <rg@mate.tn> <+216 50 711 816>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\EventSubscriber;
  12. use App\Event\ProcedureResumeRemindEvent;
  13. use App\Service\EmailParametersGenerator;
  14. use App\Service\Sendinblue\SMTPApi;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class ProcedureResumeRemindSubscriber implements EventSubscriberInterface
  18. {
  19.     public const EMAIL_TEMPLATE_ID '21'// TODO: change this to the correct snooze template - NOT READY YET
  20.     /**
  21.      * @var SMTPApi
  22.      */
  23.     protected $smtp;
  24.     /**
  25.      * @var EmailParametersGenerator
  26.      */
  27.     protected $parametersGenerator;
  28.     /**
  29.      * @var EntityManagerInterface
  30.      */
  31.     protected $entityManager;
  32.     public function __construct(SMTPApi $smtpEmailParametersGenerator $parametersGeneratorEntityManagerInterface $entityManager)
  33.     {
  34.         $this->smtp                $smtp;
  35.         $this->parametersGenerator $parametersGenerator;
  36.         $this->entityManager       $entityManager;
  37.     }
  38.     /**
  39.      * @param ProcedureResumeRemindEvent $event
  40.      */
  41.     public function onResumeRemind(ProcedureResumeRemindEvent $event): void
  42.     {
  43.         $procedure      $event->getProcedure();
  44.         $dispatchedStep $procedure->getDispatchedStep();
  45.         $invoice        $procedure->getInvoice();
  46.         if (null === $dispatchedStep) {
  47.             // Do nothing.
  48.             return;
  49.         }
  50.         $parameters     $this->parametersGenerator->generateForProcedureStep($dispatchedStep$invoice->getAccountLocale());
  51.         $contacts $invoice->getActiveAccountContacts();
  52.         if ($contacts->isEmpty()) {
  53.             $this->smtp->send(
  54.                 $invoice->getCreditorName(),
  55.                 $invoice->getCreditorEmail(),
  56.                 self::EMAIL_TEMPLATE_ID,
  57.                 $parameters,
  58.                 []
  59.             );
  60.         } else {
  61.             $this->smtp->sendToContacts(
  62.                 $contacts,
  63.                 self::EMAIL_TEMPLATE_ID,
  64.                 $parameters,
  65.                 []
  66.             );
  67.         }
  68.         $procedure->setResumeReminded(true);
  69.         $this->entityManager->flush();
  70.     }
  71.     /**
  72.      * @inheritDoc
  73.      */
  74.     public static function getSubscribedEvents()
  75.     {
  76.         return [
  77.             ProcedureResumeRemindEvent::class => 'onResumeRemind'
  78.         ];
  79.     }
  80. }