|
- <?php
-
- namespace Lc\SovBundle\Controller\Reminder;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\CaracoleBundle\Resolver\SectionResolver;
- use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface;
- use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
- use Symfony\Component\Form\FormFactoryInterface;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
- use Symfony\Component\Routing\Annotation\Route;
-
- class ReminderAdminController extends AbstractController
- {
-
- protected EntityManagerInterface $entityManager;
- protected ReminderFactoryInterface $reminderFactory;
- protected FormFactoryInterface $formFactory;
- protected UrlGeneratorInterface $urlGenerator;
- protected MerchantResolver $merchantResolver;
- protected SectionResolver $sectionResolver;
- protected ParameterBagInterface $parameterBag;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- ReminderFactoryInterface $reminderFactory,
- FormFactoryInterface $formFactory,
- UrlGeneratorInterface $urlGenerator,
- MerchantResolver $merchantResolver,
- SectionResolver $sectionResolver,
- ParameterBagInterface $parameterBag
- ) {
- $this->entityManager = $entityManager;
- $this->reminderFactory = $reminderFactory;
- $this->formFactory = $formFactory;
- $this->urlGenerator = $urlGenerator;
- $this->merchantResolver = $merchantResolver;
- $this->sectionResolver = $sectionResolver;
- $this->parameterBag = $parameterBag;
- }
-
- /**
- * @Route("/admin/reminder/modal", name="sov_admin_reminder_render_modal")
- */
- public function renderModal(Request $request): Response
- {
- $crudAction = $request->get('crudAction');
- $crudControllerFqcn = $request->get('crudControllerFqcn');
- $entityId = $request->get('entityId');
-
- $reminder = $this->createEntity($crudAction, $crudControllerFqcn, $entityId);
-
- $form = $this->formFactory->create(
- ReminderAdminFormType::class,
- $reminder,
- [
- 'action' => $this->urlGenerator->generate(
- $this->parameterBag->get('app.reminder.route_new')
- )
- ]
- );
-
- return $this->render(
- '@LcSov/admin/reminder/form_modal.html.twig',
- [
- 'form_reminder' => $form->createView()
- ]
- );
- }
-
- /**
- * @Route("/admin/reminder/new", name="sov_admin_reminder_new")
- */
- public function new(Request $request)
- {
- $reminder = $this->createEntity();
-
- $form = $this->formFactory->create(ReminderAdminFormType::class, $reminder);
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $reminder = $form->getData();
- $this->entityManager->persist($reminder);
- $this->entityManager->flush();
-
- $this->addFlash('success', 'Le pense-bête a bien été ajouté');
- }
-
- return $this->redirect($request->headers->get('referer'));
- }
-
- public function createEntity(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null)
- {
- return $this->reminderFactory->create($crudAction, $crudControllerFqcn, $entityId);
- }
-
-
- /*
- public function renderTemplate($actionName, $templatePath, array $parameters = [])
- {
- if ($this->request->isXmlHttpRequest() && ($actionName == 'new' || $actionName == 'edit')) {
- $response['flashMessages'] = $this->utils->getFlashMessages();
-
- $response['data'] = $this->render('@LcShop/backend/default/modal/edit_reminder.twig', $parameters)->getContent();
- return new Response(json_encode($response));
- } else {
- return parent::renderTemplate($actionName, $templatePath, $parameters);
- }
- }
-
- protected function redirectToReferrer()
- {
- $action = $this->request->query->get('action');
-
- if ($action == 'new') {
- $this->utils->addFlash('success', 'success.reminder.add');
- } elseif ($action == 'edit') {
- $this->utils->addFlash('success', 'success.reminder.edit');
- } elseif ($action == ' setReminderDone') {
- $this->utils->addFlash('success', 'success.reminder.done');
- }
-
- if ($this->request->isXmlHttpRequest()) {
- $response['flashMessages'] = $this->utils->getFlashMessages();
- return new Response(json_encode($response));
- } else {
- return parent::redirectToReferrer();
- }
- }
-
- public function setReminderDoneAction()
- {
- $id = $this->request->query->get('id');
- $done = $this->request->query->get('done');
-
- $easyadmin = $this->request->attributes->get('easyadmin');
- $reminder = $easyadmin['item'];
-
- $reminder->setDone($done);
- $this->em->persist($reminder);
- $this->em->flush();
- return $this->redirectToReferrer();
- }*/
- }
|