> For the complete documentation index, see [llms.txt](https://akyos.gitbook.io/book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://akyos.gitbook.io/book/symfony/gestion-des-notifications.md).

# Gestion des notifications

On créera alors ici, un dossier "Notification" où l'on groupera tout ce qui permet de traiter, de remplir et de formaliser les notifications envoyées.

On laissera l'envoi au mailer de symfony.

```
-- src
______Controller
______Notification
___________SMS
___________Email
```

Il faudra alors créer des fichiers PHP en fonction des receveurs.

> * AgentMailer.php
> * ClientMailer.php<br>
> * ClientSMS.php
> * GeniuxSMS.php

Voici des exemples types de fonctions :

```php
use Symfony\Component\Mailer\MailerInterface;

public function __construct(
    private readonly MailerInterface $mailer,
    private readonly ConfigurationService $configurationService,
    private readonly CarParticipationRepository $carParticipationRepository
){}

public function treatment(Booking $booking): void
{
    $configuration = $this->configurationService->getConfiguration();
    $agent = $booking->getAgent();

    $subject = "Votre demande de prêt";
    $email = (new TemplatedEmail())
        ->from(new Address('inscription@instanttestdrive.fr', $configuration->getName() ?? 'La Squadra'))
        ->to($agent->getEmail())
        ->subject($subject)
        ->htmlTemplate('notification/email/task/booking/treatment.html.twig')
        ->context([
            'subject' => $subject,
            'booking' => $booking,
            'user' => $booking->getAgent(),
        ]);

    $this->mailer->send($email);
}
```

```php
use App\Service\SmsApi;

public function __construct(
    private readonly SmsApi $smsApi,
    private readonly CarParticipationRepository $carParticipationRepository,
    private readonly UtilsService $utilsService,
){}

public function trialEnd(Booking\ClientBooking $clientBooking)
{
    $booking = $clientBooking->getBooking();
    $client = $clientBooking->getClient();
    $carParticipation = $booking->getReservationFor();
    $car = $carParticipation->getCar();
    $carParticipation = $this->carParticipationRepository->findOneBy(['id' => $booking->getReservationFor()->getId()]);
    $concessionParticipation = $carParticipation->getConcessionParticipation();
    $brandParticipation = $concessionParticipation->getBrandParticipation();
    $brand = $brandParticipation->getBrand();

    $link = $this->generateUrl('app_review_question_answer', [
        'token' => $clientBooking->getToken()
    ], UrlGeneratorInterface::ABSOLUTE_URL);

    return $this->smsApi->sendSMS(
        $client->getTelephone(),
        "Bonjour {$client->getFirstName()}, nous espérons que votre pret du véhicule $brand ({$car->getModel()}) vous a apporté entière satisfaction. Votre avis compte pour nous. Vous pouvez évaluer cette expérience en cliquant ici : $link . L'équipe $brand"
    );
}
```
