|
- <?php
-
- namespace Lc\SovBundle\Controller\Reminder;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface;
- use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\Form\FormFactoryInterface;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
-
- class ReminderAdminController extends AbstractController
- {
-
- protected $entityManager;
- protected $reminderFactory;
- protected $formFactory;
- protected $urlGenerator;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- ReminderFactoryInterface $reminderFactory,
- FormFactoryInterface $formFactory,
- UrlGeneratorInterface $urlGenerator
- ) {
- $this->entityManager = $entityManager;
- $this->reminderFactory = $reminderFactory;
- $this->formFactory = $formFactory;
- $this->urlGenerator = $urlGenerator;
- }
-
- public function renderModal(Request $request): Response
- {
- $reminder = $this->reminderFactory->create(
- [
- 'crudAction' => $request->get('crudAction'),
- 'crudControllerFqcn' => $request->get('crudControllerFqcn'),
- 'entityId' => $request->get('entityId'),
- ]
- );
- $form = $this->formFactory->create(
- ReminderAdminFormType::class,
- $reminder,
- [
- 'action' => $this->urlGenerator->generate('sov_admin_reminder_new')
- ]
- );
-
- return $this->render(
- '@LcSov/admin/reminder/form_modal.html.twig',
- [
- 'form_reminder' => $form->createView()
- ]
- );
- }
-
- public function new(Request $request)
- {
- $reminder = $this->reminderFactory->create();
- $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 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();
- }*/
- }
|