src/Controller/AreasWeCoverController.php line 104

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AreasWeCover;
  4. use App\Form\AreasWeCoverType;
  5. use App\Annotation\CmsAdminDash;
  6. use App\Annotation\CmsComponent;
  7. use App\Repository\AreasWeCoverRepository;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. #[Route('/takeflight/areas-we-cover')]
  13. class AreasWeCoverController extends AbstractController
  14. {
  15. /**
  16. * @CmsAdminDash("Areas We Cover", active=true, routeName="app_areas_we_cover_index", icon="fa fa-map", menuPosition=40, parentRouteName="control_content_index")
  17. */
  18. #[Route('/', name: 'app_areas_we_cover_index', methods: ['GET'])]
  19. public function index(AreasWeCoverRepository $areasWeCoverRepository): Response
  20. {
  21. return $this->render('areas_we_cover/index.html.twig', [
  22. 'areas_we_covers' => $areasWeCoverRepository->findBy(['deleted' => false]),
  23. ]);
  24. }
  25. #[Route('/new', name: 'app_areas_we_cover_new', methods: ['GET', 'POST'])]
  26. public function new(Request $request): Response
  27. {
  28. $areasWeCover = new AreasWeCover();
  29. $form = $this->createForm(AreasWeCoverType::class, $areasWeCover);
  30. $form->handleRequest($request);
  31. if ($form->isSubmitted() && $form->isValid()) {
  32. // REQUIRED IF USING UPLOAD FILE TRAIT
  33. // $areasWeCover->uploadFile();
  34. $entityManager = $this->getDoctrine()->getManager();
  35. $entityManager->persist($areasWeCover);
  36. $entityManager->flush();
  37. return $this->redirectToRoute('app_areas_we_cover_index', [], Response::HTTP_SEE_OTHER);
  38. }
  39. return $this->render('areas_we_cover/new.html.twig', [
  40. 'areas_we_cover' => $areasWeCover,
  41. 'form' => $form->createView(),
  42. ]);
  43. }
  44. #[Route('/{id}', name: 'app_areas_we_cover_show', methods: ['GET'])]
  45. public function show(AreasWeCover $areasWeCover): Response
  46. {
  47. return $this->render('areas_we_cover/show.html.twig', [
  48. 'areas_we_cover' => $areasWeCover,
  49. ]);
  50. }
  51. #[Route('/{id}/edit', name: 'app_areas_we_cover_edit', methods: ['GET', 'POST'])]
  52. public function edit(Request $request, AreasWeCover $areasWeCover): Response
  53. {
  54. $form = $this->createForm(AreasWeCoverType::class, $areasWeCover);
  55. $form->handleRequest($request);
  56. if ($form->isSubmitted() && $form->isValid()) {
  57. // REQUIRED IF USING UPLOAD FILE TRAIT
  58. // $areasWeCover->uploadFile();
  59. $this->getDoctrine()->getManager()->flush();
  60. return $this->redirectToRoute('app_areas_we_cover_index', [], Response::HTTP_SEE_OTHER);
  61. }
  62. return $this->render('areas_we_cover/edit.html.twig', [
  63. 'areas_we_cover' => $areasWeCover,
  64. 'form' => $form->createView(),
  65. ]);
  66. }
  67. #[Route('/{id}', name: 'app_areas_we_cover_delete', methods: ['POST'])]
  68. public function delete(Request $request, AreasWeCover $areasWeCover): Response
  69. {
  70. if ($this->isCsrfTokenValid('delete'.$areasWeCover->getId(), $request->request->get('_token'))) {
  71. $entityManager = $this->getDoctrine()->getManager();
  72. $areasWeCover->setActive(false);
  73. $areasWeCover->setDeleted(true);
  74. $entityManager->persist($areasWeCover);
  75. $entityManager->flush();
  76. $this->addFlash('success', 'Success - AreasWeCover deleted');
  77. }
  78. return $this->redirectToRoute('app_areas_we_cover_index', [], Response::HTTP_SEE_OTHER);
  79. }
  80. /**
  81. * @CmsComponent("Areas We Cover Component", active=true, routeName="embed_areas_we_cover_component")
  82. *
  83. * @param mixed $request
  84. */
  85. #[Route('/areas-we-cover', name: 'embed_areas_we_cover_component')]
  86. public function areasWeCover(): Response
  87. {
  88. $entityManager = $this->getDoctrine()->getManager();
  89. $areas = $entityManager->getRepository(AreasWeCover::class)->findBy(['deleted' => false, 'active' => true], ['sortOrder' => 'ASC']);
  90. if (! $areas) {
  91. return new Response('');
  92. }
  93. return $this->render('@theme/areas_we_cover/index.html.twig', [
  94. 'areas' => $areas
  95. ]);
  96. }
  97. }