<?php
namespace App\Services\Technique;
use App\Manager\Sendinblue\SendinblueManager;
use Doctrine\Persistence\ObjectManager;
use App\Repository\CentreRepository;
use App\Manager\Template\TemplateListManager;
use App\Services\Metier\CentreServicesParametresSM;
class MailST
{
private $centreRepository;
private const EMAILS_CALLANDCO = ['benoit.caquineau@callandco.fr','elodie.magniol@callandco.fr','claire.bellahoues@callandco.fr','nejma.roujean@callandco.fr'];
private const EMAILS_PROSPECT = ['benoit.caquineau@callandco.fr'];
private $csp;
public function __construct(CentreRepository $centreRepository, CentreServicesParametresSM $csp)
{
$this->centreRepository = $centreRepository;
$this->csp = $csp;
}
/**
* Sends an email with the given parameters.
*
* @param ObjectManager $em The entity manager.
* @param array $params The parameters for the email.
* @param string $template The code of the template to use.
* @param int|null $templateID The ID of the template to use (optional).
* @param array $emails The email addresses to send the email to (optional).
* @return void
*/
public function sendMailWithParams(ObjectManager $em, array $params, string $template, int $templateID = 0, array $emails = [])
{
$centre = $this->centreRepository->findOneBy(['idCentre'=>$params['idCentre'] ?? 1]);
$template = TemplateListManager::getTemplateByCodeAndIdCentre($em, $template, $centre->getIdCentre());
$params['idTemplate'] = $templateID > 0 ? $templateID : $template->getIdSendiblue();
$params['data'] = $params;
!empty($emails) ? $to = $emails : $to = $params['email'];
$cleApi = $this->csp->getBrevoApiKey();
return SendinblueManager::sendinBlueEmailInCallWithParam($to, $cleApi, $params);
}
/**
* Sends a prospect mail.
*
* @param ObjectManager $em The entity manager.
* @param array $params The parameters for the mail template.
* @param string $template The mail template.
* @param int|null $templateID The ID of the mail template (optional).
* @return bool Returns true if the mail was sent successfully, false otherwise.
*/
public function sendProspectMail(ObjectManager $em, array $params, string $template, int $templateID = null)
{
return $this->sendMailWithParams($em, $params, $template, $templateID, self::EMAILS_PROSPECT);
}
/**
* Sends a mail to CallAndCo.
*
* @param ObjectManager $em The entity manager.
* @param array $params The parameters for the mail template.
* @param string $template The mail template.
* @param int|null $templateID The ID of the mail template (optional).
* @return void
*/
public function sendMailtoCallAndCo(ObjectManager $em, array $params, string $template, int $templateID = null)
{
$this->sendMailWithParams($em, $params, $template, $templateID, self::EMAILS_CALLANDCO);
}
}