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

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