Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ReminderAdminController.php 4.1KB

il y a 3 ans
il y a 3 ans
il y a 3 ans
il y a 3 ans
il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace Lc\SovBundle\Controller\Reminder;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface;
  5. use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Form\FormFactoryInterface;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  11. class ReminderAdminController extends AbstractController
  12. {
  13. protected $entityManager;
  14. protected $reminderFactory;
  15. protected $formFactory;
  16. protected $urlGenerator;
  17. public function __construct(
  18. EntityManagerInterface $entityManager,
  19. ReminderFactoryInterface $reminderFactory,
  20. FormFactoryInterface $formFactory,
  21. UrlGeneratorInterface $urlGenerator
  22. ) {
  23. $this->entityManager = $entityManager;
  24. $this->reminderFactory = $reminderFactory;
  25. $this->formFactory = $formFactory;
  26. $this->urlGenerator = $urlGenerator;
  27. }
  28. public function renderModal(Request $request): Response
  29. {
  30. $reminder = $this->reminderFactory->create(
  31. [
  32. 'crudAction' => $request->get('crudAction'),
  33. 'crudControllerFqcn' => $request->get('crudControllerFqcn'),
  34. 'entityId' => $request->get('entityId'),
  35. ]
  36. );
  37. $form = $this->formFactory->create(
  38. ReminderAdminFormType::class,
  39. $reminder,
  40. [
  41. 'action' => $this->urlGenerator->generate('sov_admin_reminder_new')
  42. ]
  43. );
  44. return $this->render(
  45. '@LcSov/admin/reminder/form_modal.html.twig',
  46. [
  47. 'form_reminder' => $form->createView()
  48. ]
  49. );
  50. }
  51. public function new(Request $request)
  52. {
  53. $reminder = $this->reminderFactory->create();
  54. $form = $this->formFactory->create(ReminderAdminFormType::class, $reminder);
  55. $form->handleRequest($request);
  56. if ($form->isSubmitted() && $form->isValid()) {
  57. $reminder = $form->getData();
  58. $this->entityManager->persist($reminder);
  59. $this->entityManager->flush();
  60. $this->addFlash('success', 'Le pense-bête a bien été ajouté');
  61. }
  62. return $this->redirect($request->headers->get('referer'));
  63. }
  64. /*
  65. public function renderTemplate($actionName, $templatePath, array $parameters = [])
  66. {
  67. if ($this->request->isXmlHttpRequest() && ($actionName == 'new' || $actionName == 'edit')) {
  68. $response['flashMessages'] = $this->utils->getFlashMessages();
  69. $response['data'] = $this->render('@LcShop/backend/default/modal/edit_reminder.twig', $parameters)->getContent();
  70. return new Response(json_encode($response));
  71. } else {
  72. return parent::renderTemplate($actionName, $templatePath, $parameters);
  73. }
  74. }
  75. protected function redirectToReferrer()
  76. {
  77. $action = $this->request->query->get('action');
  78. if ($action == 'new') {
  79. $this->utils->addFlash('success', 'success.reminder.add');
  80. } elseif ($action == 'edit') {
  81. $this->utils->addFlash('success', 'success.reminder.edit');
  82. } elseif ($action == ' setReminderDone') {
  83. $this->utils->addFlash('success', 'success.reminder.done');
  84. }
  85. if ($this->request->isXmlHttpRequest()) {
  86. $response['flashMessages'] = $this->utils->getFlashMessages();
  87. return new Response(json_encode($response));
  88. } else {
  89. return parent::redirectToReferrer();
  90. }
  91. }
  92. public function setReminderDoneAction()
  93. {
  94. $id = $this->request->query->get('id');
  95. $done = $this->request->query->get('done');
  96. $easyadmin = $this->request->attributes->get('easyadmin');
  97. $reminder = $easyadmin['item'];
  98. $reminder->setDone($done);
  99. $this->em->persist($reminder);
  100. $this->em->flush();
  101. return $this->redirectToReferrer();
  102. }*/
  103. }