← Back
Editing: ReportController.php
<?php namespace App\Controller\Organization; use App\Breadcrumb\BreadcrumbInterface; use App\Breadcrumb\BreadcrumbItem; use App\Entity\Report; use App\Enum\ReportType; use App\Form\ReportFilterType; use App\Report\ReportExporter; use App\Repository\ReportItemRepository; use App\Repository\ReportRepository; use App\Service\OrganizationService; use App\Service\SupervisorService; use Knp\Component\Pager\PaginatorInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; #[Route(path: '/organization/report', name: 'organization_report_')] class ReportController extends AbstractController { #[Route(path: '/detail/{report}', name: 'detail')] public function detail(Report $report): Response { return $this->render('organization/report/detail.html.twig', [ 'report' => $report, ]); } #[Route(path: '/{type}/export.xls', name: 'export')] public function xls(ReportType $type, ReportExporter $reportExporter): Response { $file = ($reportExporter)($type); return $this->file($file, 'export-signalements.xls', ResponseHeaderBag::DISPOSITION_INLINE); } #[Route(path: '/{type}/{page}', name: 'index', defaults: ['page' => 1])] public function index( ReportType $type, BreadcrumbInterface $breadcrumb, ReportRepository $reportRepository, ReportItemRepository $reportItemRepository, PaginatorInterface $paginator, SupervisorService $supervisorService, OrganizationService $organizationService, TranslatorInterface $translator, Request $request, int $page = 1, ): Response { $breadcrumb->addRootItem(BreadcrumbItem::set('Accueil', 'organization_index')); $breadcrumb->addItem(BreadcrumbItem::set('Liste des '.$translator->trans(strtoupper($type->value)).'(s)')); $supervisorService->setSection($type->value); $filter = $this->createForm(type: ReportFilterType::class, options: ['type' => $type]); $filter->handleRequest($request); $agenciesId = $organizationService->getAgenciesId(); $pagination = $paginator->paginate( $reportRepository->getReportsQueryBuilder( null, $filter, $type, $agenciesId ), $page, 25 ); $parentItems = $reportItemRepository->findParentReportItems($type); $pagination->setCustomParameters(['align' => 'center']); return $this->render('organization/report/index.html.twig', [ 'type' => $type, 'filter' => $filter->createView(), 'items' => $reportItemRepository->countReportWithFilterByAgencies( reportType: $type, filter: $filter, agenciesId: $agenciesId ), 'chartData' => json_encode( $reportRepository->countByMonthByAgencies( reportType: $type, filter: $filter, agenciesId: $agenciesId ) ), 'parentItemCharts' => array_map( fn ($item) => json_encode([ 'label' => $item->getLabel(), 'data' => $reportRepository->countByMonthByAgencies( reportType: $type, filter: $filter, agenciesId: $agenciesId, parent: $item ), ]), $parentItems ), 'pagination' => $pagination, ]); } }
Save File
Cancel