← Back
Editing: ReportFactory.php
<?php namespace App\Report; use App\Repository\SolutionRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Security\Core\User\UserInterface; final class ReportFactory { /** * @param iterable<ReportInterface> $reports */ public function __construct( private readonly iterable $reports, private readonly EntityManagerInterface $entityManager, private readonly SolutionRepository $solutionRepository ) { } /** * @throws \Exception */ public function getReportInfo(string $type, UserInterface $user, ?\DateTimeInterface $reportDate = null): array { if ($this->entityManager->getFilters()->isEnabled('solution_filter')) { $this->entityManager->getFilters()->disable('solution_filter'); } $dateStart = $reportDate; if (null === $reportDate) { $dateStart = new \DateTime('first day of previous month'); } $dateStart->setTime(0, 0); $dateEnd = clone $dateStart; $dateEnd->add(new \DateInterval('P1M'))->sub(new \DateInterval('PT1S')); $prevDateStart = clone $dateStart; $prevDateStart->sub(new \DateInterval('P1M')); $prevDateEnd = clone $dateStart; $prevDateEnd->sub(new \DateInterval('PT1S')); foreach ($this->reports as $report) { if ($report->supports($type)) { $result = []; foreach ($this->solutionRepository->findAll() as $solution) { if (!in_array('ROLE_AGENT', $user->getRoles()) || $user->hasSolution($solution)) { $controls = $report->getRateControls( $user, $dateStart, $dateEnd, $prevDateStart, $prevDateEnd, $solution ); $alerts = $report->getRateAlerts( $user, $dateStart, $dateEnd, $prevDateStart, $prevDateEnd, $solution ); $notes = $report->getRateAverageNote( $user, $dateStart, $dateEnd, $prevDateStart, $prevDateEnd, $solution ); $incidences = $report->getRateIncidence( $user, $dateStart, $dateEnd, $prevDateStart, $prevDateEnd, $solution ); $result[$solution->getSlug()] = [ 'totalControls' => $controls['total'], 'rateControls' => $controls['evo'], 'totalAlerts' => $alerts['total'], 'rateAlerts' => $alerts['evo'], 'totalAverageNote' => $notes['total'], 'rateAverageNote' => $notes['evo'], 'totalIncidence' => $incidences['total'], 'rateIncidence' => $incidences['evo'], 'addresses' => $report->getLessNotedControle($user, $dateStart, $dateEnd, $solution), 'items' => $report->getLessNotedItems($user, $dateStart, $dateEnd, $solution), 'elevators' => $report->getElevatorbreakDownByMonth($user, $dateStart, $dateEnd, $solution), ]; } } return $result; } } return []; } }
Save File
Cancel