← Back
Editing: ReportService.php
<?php namespace App\Service; use App\Entity\Report; use App\Enum\ReportType; use App\Session\Filter\Role\ManagerSessionFilters; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\Form\FormInterface; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\Address; final class ReportService { public function __construct( private readonly MailerInterface $mailer, private readonly SolutionService $solutionService, private readonly ManagerSessionFilters $sessionFilters, private readonly UserService $userService, ) { } public function sendNewReportConfirmation(Report $report): void { $emailFrom = 'contact@arithmetic.fr'; $email = (new TemplatedEmail()) ->from($emailFrom) ->to(new Address($report->getAgent()->getManager()->getEmail())); if ($report->isSendCopy()) { $email->cc(new Address($report->getAgent()->getEmail())); } $logo = $report->getAgent()->getAgency()->getLogo(); $email ->subject('Confirmation de création du report') // path of the Twig template to render ->htmlTemplate('emails/report/new_report_confirm.html.twig') // pass variables (name => value) to the template ->context( [ 'report' => $report, 'agent' => $report->getAgent(), 'logo' => $logo ? sprintf('@logos/%s', $logo) : '@images/bot.png', 'adresse' => $report->getLocation(), 'today' => new \DateTime('today'), 'solution' => $this->solutionService->getCurrent(), ] ); $this->mailer->send($email); } public function groupReportsByMonth(ReportType $reportType, FormInterface $filter): array { $array = []; $agents = $this->userService->getAgentsForCurrentSolution(); $formatter = new \IntlDateFormatter('fr_FR', \IntlDateFormatter::TRADITIONAL, \IntlDateFormatter::TRADITIONAL); $formatter->setPattern('MMM yy'); $endDate = $this->sessionFilters->getDateRange()->getDateEnd(); $endDate->modify('last day of this month'); $period = new \DatePeriod( $this->sessionFilters->getDateRange()->getDateStart(), new \DateInterval('P1M'), $endDate ); /** @var \DateTime $i */ foreach ($period as $i) { $date = $formatter->format($i); array_key_exists($date, $array) ?: $array[$date] = 0; } foreach ($agents as $agent) { $reports = $agent->getReportsWithDates( $reportType, $this->sessionFilters->getDateRange()->getDateStart(), $this->sessionFilters->getDateRange()->getDateEnd() ); foreach ($reports as $report) { $createdAt = $formatter->format($report->getCreatedAt()); if (array_key_exists($createdAt, $array)) { ++$array[$createdAt]; } } } return $array; } }
Save File
Cancel