src/Services/Technique/MailST.php line 73

Open in your IDE?
  1. <?php
  2. namespace App\Services\Technique;
  3. use App\Manager\Sendinblue\SendinblueManager;
  4. use Doctrine\Persistence\ObjectManager;
  5. use App\Repository\CentreRepository;
  6. use App\Manager\Template\TemplateListManager;
  7. use App\Services\Metier\CentreServicesParametresSM;
  8. class MailST
  9. {
  10. private $centreRepository;
  11. private const EMAILS_CALLANDCO = ['benoit.caquineau@callandco.fr','elodie.magniol@callandco.fr','claire.bellahoues@callandco.fr','nejma.roujean@callandco.fr'];
  12. private const EMAILS_PROSPECT = ['benoit.caquineau@callandco.fr'];
  13. private $csp;
  14. public function __construct(CentreRepository $centreRepository, CentreServicesParametresSM $csp)
  15. {
  16. $this->centreRepository = $centreRepository;
  17. $this->csp = $csp;
  18. }
  19. /**
  20. * Sends an email with the given parameters.
  21. *
  22. * @param ObjectManager $em The entity manager.
  23. * @param array $params The parameters for the email.
  24. * @param string $template The code of the template to use.
  25. * @param int|null $templateID The ID of the template to use (optional).
  26. * @param array $emails The email addresses to send the email to (optional).
  27. * @return void
  28. */
  29. public function sendMailWithParams(ObjectManager $em, array $params, string $template, int $templateID = 0, array $emails = [])
  30. {
  31. $centre = $this->centreRepository->findOneBy(['idCentre'=>$params['idCentre'] ?? 1]);
  32. $template = TemplateListManager::getTemplateByCodeAndIdCentre($em, $template, $centre->getIdCentre());
  33. $params['idTemplate'] = $templateID > 0 ? $templateID : $template->getIdSendiblue();
  34. $params['data'] = $params;
  35. !empty($emails) ? $to = $emails : $to = $params['email'];
  36. $cleApi = $this->csp->getBrevoApiKey();
  37. return SendinblueManager::sendinBlueEmailInCallWithParam($to, $cleApi, $params);
  38. }
  39. /**
  40. * Sends a prospect mail.
  41. *
  42. * @param ObjectManager $em The entity manager.
  43. * @param array $params The parameters for the mail template.
  44. * @param string $template The mail template.
  45. * @param int|null $templateID The ID of the mail template (optional).
  46. * @return bool Returns true if the mail was sent successfully, false otherwise.
  47. */
  48. public function sendProspectMail(ObjectManager $em, array $params, string $template, int $templateID = null)
  49. {
  50. return $this->sendMailWithParams($em, $params, $template, $templateID, self::EMAILS_PROSPECT);
  51. }
  52. /**
  53. * Sends a mail to CallAndCo.
  54. *
  55. * @param ObjectManager $em The entity manager.
  56. * @param array $params The parameters for the mail template.
  57. * @param string $template The mail template.
  58. * @param int|null $templateID The ID of the mail template (optional).
  59. * @return void
  60. */
  61. public function sendMailtoCallAndCo(ObjectManager $em, array $params, string $template, int $templateID = null)
  62. {
  63. $this->sendMailWithParams($em, $params, $template, $templateID, self::EMAILS_CALLANDCO);
  64. }
  65. }