mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Feature: [saved export] Edit and delete saved exports
This commit is contained in:
@@ -16,38 +16,132 @@ use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Export\ExportInterface;
|
||||
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\SavedExportVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function count;
|
||||
|
||||
class SavedExportController
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private ExportManager $exportManager;
|
||||
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private SavedExportRepositoryInterface $savedExportRepository;
|
||||
|
||||
private Security $security;
|
||||
|
||||
private SessionInterface $session;
|
||||
|
||||
private EngineInterface $templating;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
private UrlGeneratorInterface $urlGenerator;
|
||||
|
||||
public function __construct(
|
||||
EngineInterface $templating,
|
||||
EntityManagerInterface $entityManager,
|
||||
ExportManager $exportManager,
|
||||
FormFactoryInterface $formBuilder,
|
||||
SavedExportRepositoryInterface $savedExportRepository,
|
||||
Security $security,
|
||||
TranslatorInterface $translator
|
||||
SessionInterface $session,
|
||||
TranslatorInterface $translator,
|
||||
UrlGeneratorInterface $urlGenerator
|
||||
) {
|
||||
$this->exportManager = $exportManager;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->formFactory = $formBuilder;
|
||||
$this->savedExportRepository = $savedExportRepository;
|
||||
$this->security = $security;
|
||||
$this->session = $session;
|
||||
$this->templating = $templating;
|
||||
$this->translator = $translator;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/exports/saved/{id}/delete", name="chill_main_export_saved_delete")
|
||||
*/
|
||||
public function delete(SavedExport $savedExport, Request $request): Response
|
||||
{
|
||||
if (!$this->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(),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,6 +177,7 @@ class SavedExportController
|
||||
'@ChillMain/SavedExport/index.html.twig',
|
||||
[
|
||||
'grouped_exports' => $exportsGrouped,
|
||||
'total' => count($exports),
|
||||
]
|
||||
)
|
||||
);
|
||||
|
Reference in New Issue
Block a user