security->isGranted(SavedExportVoter::DELETE, $savedExport)) { throw new AccessDeniedHttpException(); } $form = $this->formFactory->create(); $form->add('submit', SubmitType::class, ['label' => 'Delete']); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->entityManager->remove($savedExport); $this->entityManager->flush(); $this->session->getFlashBag()->add('success', $this->translator->trans('saved_export.Export is deleted')); return new RedirectResponse( $this->urlGenerator->generate('chill_main_export_saved_list_my') ); } return new Response( $this->templating->render( '@ChillMain/SavedExport/delete.html.twig', [ 'saved_export' => $savedExport, 'delete_form' => $form->createView(), ] ) ); } /** * @Route("/{_locale}/exports/saved/{id}/edit", name="chill_main_export_saved_edit") */ public function edit(SavedExport $savedExport, Request $request): Response { if (!$this->security->isGranted(SavedExportVoter::EDIT, $savedExport)) { throw new AccessDeniedHttpException(); } $form = $this->formFactory->create(SavedExportType::class, $savedExport); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->entityManager->flush(); $this->session->getFlashBag()->add('success', $this->translator->trans('saved_export.Saved export is saved!')); return new RedirectResponse( $this->urlGenerator->generate('chill_main_export_saved_list_my') ); } return new Response( $this->templating->render( '@ChillMain/SavedExport/edit.html.twig', [ 'form' => $form->createView(), ] ) ); } /** * @Route("/{_locale}/exports/saved/my", name="chill_main_export_saved_list_my") */ public function list(): Response { $user = $this->security->getUser(); if (!$this->security->isGranted('ROLE_USER') || !$user instanceof User) { throw new AccessDeniedHttpException(); } $exports = $this->savedExportRepository->findByUser($user, ['title' => 'ASC']); // group by center /** @var array $exportsGrouped */ $exportsGrouped = []; foreach ($exports as $savedExport) { $export = $this->exportManager->getExport($savedExport->getExportAlias()); $exportsGrouped[ $export instanceof GroupedExportInterface ? $this->translator->trans($export->getGroup()) : '_' ][] = ['saved' => $savedExport, 'export' => $export]; } ksort($exportsGrouped); return new Response( $this->templating->render( '@ChillMain/SavedExport/index.html.twig', [ 'grouped_exports' => $exportsGrouped, 'total' => count($exports), ] ) ); } }