src/EventSubscriber/EmptyInvoiceContactSubscriber.php line 49

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\EmptyInvoiceContactEvent;
  13. use App\Service\EmailParametersGenerator;
  14. use App\Service\Sendinblue\SMTPApi;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class EmptyInvoiceContactSubscriber implements EventSubscriberInterface
  17. {
  18.     public const EMAIL_TEMPLATE_ID '29';
  19.     /**
  20.      * @var EmailParametersGenerator
  21.      */
  22.     protected $emailParametersGenerator;
  23.     /**
  24.      * @var SMTPApi
  25.      */
  26.     protected $smtp;
  27.     public function __construct(EmailParametersGenerator $emailParametersGeneratorSMTPApi $smtp)
  28.     {
  29.         $this->emailParametersGenerator $emailParametersGenerator;
  30.         $this->smtp $smtp;
  31.     }
  32.     /**
  33.      * @inheritDoc
  34.      */
  35.     public static function getSubscribedEvents()
  36.     {
  37.         return [
  38.             EmptyInvoiceContactEvent::class => 'onEmptyInvoiceContact'
  39.         ];
  40.     }
  41.     public function onEmptyInvoiceContact(EmptyInvoiceContactEvent $event): void
  42.     {
  43.         $invoice $event->getInvoice();
  44.         $procedure $invoice->getProcedure();
  45.         $emailParams $this->emailParametersGenerator->generateForProcedureStep(
  46.             $procedure->getDispatchedStep() ?? $procedure->getPendingStep(),
  47.             $invoice->getAccountLocale(),
  48.             ['empty_customer_contacts' => true'procedure' => $procedure->getId()]
  49.         );
  50.         // Send email to the user's email.
  51.         $user $invoice->getUser();
  52.         // Send notification email for user to alert him
  53.         // that he needs to add at least one customer contact
  54.         $this->smtp->send(
  55.             $user->getFullName(),
  56.             $user->getUsername(),
  57.             static::EMAIL_TEMPLATE_ID,
  58.             $emailParams,
  59.             []
  60.         );
  61.     }
  62. }