diff --git a/src/Bundle/ChillMainBundle/Controller/SavedExportController.php b/src/Bundle/ChillMainBundle/Controller/SavedExportController.php index 82d41a9e1..dcc988fd4 100644 --- a/src/Bundle/ChillMainBundle/Controller/SavedExportController.php +++ b/src/Bundle/ChillMainBundle/Controller/SavedExportController.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Controller; +use Chill\MainBundle\Entity\ExportGeneration; use Chill\MainBundle\Entity\SavedExport; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Export\ExportInterface; @@ -18,7 +19,9 @@ use Chill\MainBundle\Export\ExportManager; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Form\SavedExportType; use Chill\MainBundle\Repository\SavedExportRepositoryInterface; +use Chill\MainBundle\Security\Authorization\ExportGenerationVoter; use Chill\MainBundle\Security\Authorization\SavedExportVoter; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\FormFactoryInterface; @@ -32,9 +35,20 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Core\Security; use Symfony\Contracts\Translation\TranslatorInterface; -class SavedExportController +final readonly class SavedExportController { - public function __construct(private readonly \Twig\Environment $templating, private readonly EntityManagerInterface $entityManager, private readonly ExportManager $exportManager, private readonly FormFactoryInterface $formFactory, private readonly SavedExportRepositoryInterface $savedExportRepository, private readonly Security $security, private readonly SessionInterface $session, private readonly TranslatorInterface $translator, private readonly UrlGeneratorInterface $urlGenerator) {} + public function __construct( + private \Twig\Environment $templating, + private EntityManagerInterface $entityManager, + private ExportManager $exportManager, + private FormFactoryInterface $formFactory, + private SavedExportRepositoryInterface $savedExportRepository, + private Security $security, + private SessionInterface $session, + private TranslatorInterface $translator, + private UrlGeneratorInterface $urlGenerator, + private TranslatableStringHelperInterface $translatableStringHelper, + ) {} #[Route(path: '/{_locale}/exports/saved/{id}/delete', name: 'chill_main_export_saved_delete')] public function delete(SavedExport $savedExport, Request $request): Response @@ -69,6 +83,49 @@ class SavedExportController ); } + #[Route(path: '/exports/saved/create-from-export-generation/{id}/new', name: 'chill_main_export_saved_create_from_export_generation')] + public function createFromExportGeneration(ExportGeneration $exportGeneration, Request $request): Response + { + if (!$this->security->isGranted(ExportGenerationVoter::VIEW, $exportGeneration)) { + throw new AccessDeniedHttpException(); + } + + $user = $this->security->getUser(); + if (!$user instanceof User) { + throw new AccessDeniedHttpException('only regular user can create a saved export'); + } + + $savedExport = new SavedExport(); + $savedExport + ->setExportAlias($exportGeneration->getExportAlias()) + ->setUser($user) + ->setOptions($exportGeneration->getOptions()) + ->setTitle($this->translator->trans($this->exportManager->getExport($exportGeneration->getExportAlias())->getTitle())); + + $form = $this->formFactory->create(SavedExportType::class, $savedExport); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->persist($savedExport); + $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(path: '/{_locale}/exports/saved/{id}/edit', name: 'chill_main_export_saved_edit')] public function edit(SavedExport $savedExport, Request $request): Response { diff --git a/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig b/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig index 992d72a74..44b814a6b 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/ExportGeneration/wait.html.twig @@ -23,5 +23,10 @@ {{ 'export.generation.Come back later'|trans|chill_return_path_label }} +
  • + + {{ 'Save'|trans }} + +
  • {% endblock content %}