src/UI/WebBundle/Controller/Whater/PublicWhaterController.php line 22

Open in your IDE?
  1. <?php
  2. namespace Whater\UI\WebBundle\Controller\Whater;
  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\Whater\CommandRequest\GetWhaterPointForShowCommand;
  8. use Whater\Application\UseCase\Zones\CommandRequest\ListCountryCommand;
  9. use Whater\Application\UseCase\Zones\CommandRequest\GetNearestTownByLatLongCommand;
  10. /**
  11. * @Route("public/whater")
  12. */
  13. class PublicWhaterController extends AbstractBusController
  14. {
  15. /**
  16. * @Route("/{userType}/map", name="web_public_whater_map", defaults={"_format" = "html", "userType" = "user"})
  17. */
  18. public function whaterLocationsMapAction(Request $request, string $userType = null)
  19. {
  20. $grantUser = $this->getGrantedUser();
  21. if ($grantUser != null) {
  22. return new RedirectResponse($this->router()->generate('web_app_whater_map'));
  23. }
  24. $countries = [];
  25. $defaultTown = null;
  26. try {
  27. $countriesPage = $this->handle(new ListCountryCommand(1, 1000, "name", "asc"));
  28. $countries = $countriesPage->getCurrentPageResults();
  29. $ip = $this->requestStack()->getMainRequest()->getClientIp();
  30. if ($ip != '127.0.0.1') {
  31. try {
  32. $record = $this->geoIpReader()->city($ip);
  33. if ($record->ubication->latitude != null) {
  34. $defaultTown = $this->handle(new GetNearestTownByLatLongCommand($record->ubication->latitude, $record->ubication->longitude, 100));
  35. }
  36. } catch (\Exception $e) {
  37. $defaultTown = $this->handle(new GetNearestTownByLatLongCommand(40.416775, -3.70379, 1000));
  38. }
  39. }
  40. if ($defaultTown == null) {
  41. $defaultTown = $this->handle(new GetNearestTownByLatLongCommand(40.416775, -3.70379, 1000));
  42. }
  43. } catch (\Exception $e) {
  44. $errorMessage = '<br/>' . $this->translator()->trans($e->getMessage());
  45. $this->setFlash('error', $this->translator()->trans('public.whater_map.exception') . $errorMessage);
  46. }
  47. return $this->render(
  48. 'Whater/whater_point_map.html.twig',
  49. [
  50. 'countries' => $countries,
  51. 'defaultTown' => $defaultTown,
  52. 'userType' => $userType
  53. ]
  54. );
  55. }
  56. /**
  57. * @Route("/show/whaterpoint/{whaterPointId}", name="web_public_whater_point_show_old", defaults={"_format" = "html"})
  58. */
  59. public function showWhaterPointOldAction(Request $request, $whaterPointId)
  60. {
  61. return new RedirectResponse($this->router()->generate('web_public_whater_point_show', ['whaterPointId' => $whaterPointId]));
  62. }
  63. /**
  64. * @Route("/show/whaterpoint/id/{whaterPointId}", name="web_public_whater_point_show", defaults={"_format" = "html"})
  65. */
  66. public function showWhaterPointAction(Request $request, $whaterPointId)
  67. {
  68. try {
  69. $whaterPoint = $this->handle(new GetWhaterPointForShowCommand($whaterPointId));
  70. if ($whaterPoint == null) {
  71. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  72. }
  73. return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_slug', ['whaterPointSlug' => $whaterPoint->slug()]));
  74. } catch (\Exception $e) {
  75. $this->setFlash('error', $this->translator()->trans($e->getMessage()));
  76. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  77. }
  78. }
  79. /** DEPRECATED URLS */
  80. /**
  81. * Deprecated: USE web_public_whater_point_show_by_slug
  82. * @Route("/show/whaterpoint/slug/{whaterPointSlug}", name="web_public_whater_point_show_by_slug_old", defaults={"_format" = "html"})
  83. */
  84. public function showWhaterpointBySlugAction(Request $request, $whaterPointSlug)
  85. {
  86. return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_slug', ['whaterPointSlug' => $whaterPointSlug]));
  87. }
  88. /**
  89. * Deprecated: USE web_public_whater_map
  90. * @Route("/whater-map", name="web_public_whater_map_1", defaults={"_format" = "html"})
  91. */
  92. public function showWhaterMapDeprecatedAction(Request $request)
  93. {
  94. return new RedirectResponse($this->router()->generate('web_public_whater_map'));
  95. }
  96. /**
  97. * Deprecated: USE web_public_distribution_network_show_by_id
  98. * @Route("/show/distribution_network/{distributionNetworkId}", name="web_public_distribution_network_show_1", defaults={"_format" = "html"})
  99. */
  100. public function showDistributionNetworkIdAction(Request $request, $distributionNetworkId)
  101. {
  102. return new RedirectResponse($this->router()->generate('web_public_distribution_network_show_by_id', ['distributionNetworkId' => $distributionNetworkId]));
  103. }
  104. /**
  105. * Deprecated: USE web_public_distribution_network_show_by_id
  106. * @Route("/show/distribution_network/id/{distributionNetworkId}", name="web_public_distribution_network_show_2", defaults={"_format" = "html"})
  107. */
  108. public function showDistributionNetworkByIdAction(Request $request, $distributionNetworkId)
  109. {
  110. return new RedirectResponse($this->router()->generate('web_public_distribution_network_show_by_id', ['distributionNetworkId' => $distributionNetworkId]));
  111. }
  112. /**
  113. * Deprecated: USE web_public_distribution_network_show_by_slug
  114. * @Route("/show/distribution_network/slug/{distributionNetworkSlug}", name="web_public_distribution_network_show_by_slug_deprecated_1", defaults={"_format" = "html"})
  115. */
  116. public function showDistributionNetworkBySlugAction(Request $request, $distributionNetworkSlug)
  117. {
  118. return new RedirectResponse($this->router()->generate('web_public_distribution_network_show_by_slug', ['distributionNetworkSlug' => $distributionNetworkSlug]));
  119. }
  120. /**
  121. * Deprecated: USE web_public_whater_point_show_by_id_2
  122. * @Route("/show/whaterpoint/{whaterpointId}", name="web_public_whater_point_show_by_id_deprecated_1", defaults={"_format" = "html"})
  123. */
  124. public function showWhaterpointByIdAction(Request $request, $whaterpointId)
  125. {
  126. return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_id_2', ['distributionNetworkId' => $distributionNetworkId]));
  127. }
  128. /**
  129. * Deprecated: USE web_public_whater_point_show_by_id_2
  130. * @Route("/show/whaterpoint/id/{whaterpointId}", name="web_public_whater_point_show_by_id_deprecated_2", defaults={"_format" = "html"})
  131. */
  132. public function showWhaterpointById2Action(Request $request, $whaterpointId)
  133. {
  134. return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_id_2', ['whaterpointId' => $whaterpointId]));
  135. }
  136. /**
  137. * Deprecated: USE web_public_whater_point_show_by_slug
  138. * @Route("/show/whaterpoint/slug/{whaterpointSlug}", name="web_public_whater_point_show_by_slug_deprecated_1", defaults={"_format" = "html"})
  139. */
  140. public function showWhaterpoint2BySlugAction(Request $request, $whaterpointSlug)
  141. {
  142. return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_slug', ['whaterpointSlug' => $whaterpointSlug]));
  143. }
  144. /**
  145. * Deprecated: USE web_public_analytical_show
  146. * @Route("/show/analytical/{analyticalId}", name="web_public_whater_analytical_show_deprecated_1", defaults={"_format" = "html"})
  147. */
  148. public function showAnalyticalByIdAction(Request $request, $analyticalId)
  149. {
  150. return new RedirectResponse($this->router()->generate('web_public_analytical_show', ['analyticalId' => $analyticalId]));
  151. }
  152. }