'csv'])] public function socialIssueList(Request $request, string $_format = 'csv'): StreamedResponse { if (!$this->security->isGranted('ROLE_ADMIN')) { throw new AccessDeniedHttpException('Only ROLE_ADMIN can export this list'); } $socialIssues = $this->socialIssueRepository->findAll(); $socialIssues = array_map(fn ($issue) => [ 'id' => $issue->getId(), 'title' => $this->socialIssueRender->renderString($issue, []), 'ordering' => $issue->getOrdering(), 'desactivationDate' => $issue->getDesactivationDate(), ], $socialIssues); $csv = Writer::createFromPath('php://temp', 'r+'); $csv->insertOne( array_map( fn (string $e) => $this->translator->trans($e), [ 'Id', 'Title', 'Ordering', 'goal.desactivationDate', ] ) ); $csv->addFormatter(fn (array $row) => null !== ($row['desactivationDate'] ?? null) ? array_merge($row, ['desactivationDate' => $row['desactivationDate']->format('Y-m-d')]) : $row); $csv->insertAll($socialIssues); return new StreamedResponse( function () use ($csv) { foreach ($csv->chunk(1024) as $chunk) { echo $chunk; flush(); } }, Response::HTTP_OK, [ 'Content-Encoding' => 'none', 'Content-Type' => 'text/csv; charset=UTF-8', 'Content-Disposition' => 'attachment; users.csv', ] ); } /** * @throws UnavailableStream * @throws CannotInsertRecord * @throws Exception */ #[Route(path: '/{_locale}/admin/social-work/social-action/export/list.{_format}', name: 'chill_person_social_action_export_list', requirements: ['_format' => 'csv'])] public function socialActionList(Request $request, string $_format = 'csv'): StreamedResponse { if (!$this->security->isGranted('ROLE_ADMIN')) { throw new AccessDeniedHttpException('Only ROLE_ADMIN can export this list'); } $socialActions = $this->socialActionRepository->findAll(); $socialActions = array_map(fn ($action) => [ 'id' => $action->getId(), 'title' => $this->socialActionRender->renderString($action, []), 'desactivationDate' => $action->getDesactivationDate(), 'socialIssue' => $this->socialIssueRender->renderString($action->getIssue(), []), 'ordering' => $action->getOrdering(), ], $socialActions); $csv = Writer::createFromPath('php://temp', 'r+'); $csv->insertOne( array_map( fn (string $e) => $this->translator->trans($e), [ 'Id', 'Title', 'goal.desactivationDate', 'Social issue', 'Ordering', ] ) ); $csv->addFormatter(fn (array $row) => null !== ($row['desactivationDate'] ?? null) ? array_merge($row, ['desactivationDate' => $row['desactivationDate']->format('Y-m-d')]) : $row); $csv->insertAll($socialActions); return new StreamedResponse( function () use ($csv) { foreach ($csv->chunk(1024) as $chunk) { echo $chunk; flush(); } }, Response::HTTP_OK, [ 'Content-Encoding' => 'none', 'Content-Type' => 'text/csv; charset=UTF-8', 'Content-Disposition' => 'attachment; users.csv', ] ); } }