src/UI/WebBundle/Controller/Zones/PublicUbicationController.php line 24

Open in your IDE?
  1. <?php
  2. namespace Whater\UI\WebBundle\Controller\Zones;
  3. use Whater\UI\WebBundle\Controller\AbstractBusController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Whater\Application\UseCase\User\CommandRequest\AppRegisterUbicationOwnershipRequestCommand;
  8. use Whater\Application\UseCase\Zones\CommandRequest\GetUbicationByIdCommand;
  9. use Whater\Application\UseCase\Zones\CommandRequest\GetEstablishmentByIdCommand;
  10. use Whater\Application\UseCase\Zones\CommandRequest\GetUbicationBySlugCommand;
  11. use Whater\Infrastructure\UserBundle\Form\Type\AppRegisterUbicationOwnershipRequestType;
  12. /**
  13. * @Route("public/ubication")
  14. */
  15. class PublicUbicationController extends AbstractBusController
  16. {
  17. /**
  18. * @Route("/show/id/{ubicationId}", name="web_public_ubication_show", defaults={"_format" = "html"})
  19. */
  20. public function showLocationAction(Request $request, $ubicationId)
  21. {
  22. try {
  23. $ubication = $this->handle(new GetUbicationByIdCommand($ubicationId));
  24. if ($ubication == null) {
  25. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  26. }
  27. return new RedirectResponse($this->router()->generate('web_public_ubication_show_by_slug', ['ubicationSlug' => $ubication->slug()]));
  28. } catch (\Exception $e) {
  29. $errorMessage = '<br/>' . $this->translator()->trans($e->getMessage());
  30. $this->setFlash('error', $this->translator()->trans('admin.town.show.exception') . $errorMessage);
  31. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  32. }
  33. }
  34. /**
  35. * @Route("/show/name/{ubicationSlug}", name="web_public_ubication_show_by_slug", defaults={"_format" = "html"})
  36. */
  37. public function showLocationBySlugAction(Request $request, $ubicationSlug)
  38. {
  39. $ubication = null;
  40. $registerOwnershipRequestForm = null;
  41. $enableRequestOwnership = true;
  42. try {
  43. $ubication = $this->handle(new GetUbicationBySlugCommand($ubicationSlug));
  44. if ($ubication == null) {
  45. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  46. }
  47. $registerOwnershipRequestForm = $this->getFormFactory()->create(
  48. AppRegisterUbicationOwnershipRequestType::class,
  49. AppRegisterUbicationOwnershipRequestCommand::convertToDTO(),
  50. array(
  51. 'csrf_protection' => true
  52. )
  53. );
  54. if ($request->isMethod('POST')) {
  55. $registerOwnershipRequestForm->handleRequest($request);
  56. if ($registerOwnershipRequestForm->isSubmitted() && $registerOwnershipRequestForm->isValid()) {
  57. $this->handle(AppRegisterUbicationOwnershipRequestCommand::fromDTO($registerOwnershipRequestForm->getData()));
  58. $this->setFlash('success', $this->translator()->trans('public.ownership_request.register.success'));
  59. $enableRequestOwnership = false;
  60. } else {
  61. $this->setFlash('error', $this->translator()->trans('public.ownership_request.register.invalid_form'));
  62. }
  63. }
  64. } catch (\Exception $e) {
  65. $errorMessage = '<br/>' . $this->translator()->trans($e->getMessage());
  66. $this->setFlash('error', $this->translator()->trans('public.ownership_request.show.exception') . $errorMessage);
  67. }
  68. return $this->render('Zones/public_ubication_show.html.twig', array(
  69. 'ubication' => $ubication,
  70. 'form' => $registerOwnershipRequestForm->createView(),
  71. 'enableRequestOwnership' => $enableRequestOwnership
  72. ));
  73. }
  74. /**
  75. * @Route("/show/establishment/{establishmentId}", name="web_public_establishment_show", defaults={"_format" = "html"})
  76. */
  77. public function showEstablishmentAction(Request $request, $establishmentId)
  78. {
  79. $establishment = null;
  80. $distributionNetwork = null;
  81. try {
  82. $establishment = $this->handle(new GetEstablishmentByIdCommand($establishmentId));
  83. if ($establishment == null) {
  84. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  85. }
  86. $distributionNetwork = $establishment->distributionNetwork();
  87. } catch (\Exception $e) {
  88. $errorMessage = '<br/>' . $this->translator()->trans($e->getMessage());
  89. $this->setFlash('error', $this->translator()->trans('admin.establishment.show.exception') . $errorMessage);
  90. }
  91. return $this->render('Zones/establishment_show.html.twig', array(
  92. 'establishment' => $establishment,
  93. 'distributionNetwork' => $distributionNetwork
  94. ));
  95. }
  96. }