<?php
namespace Whater\UI\WebBundle\Controller\Whater;
use Whater\UI\WebBundle\Controller\AbstractBusController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Whater\Application\UseCase\Whater\CommandRequest\GetWhaterPointForShowCommand;
use Whater\Application\UseCase\Whater\CommandRequest\GetWhaterValorationForShowCommand;
use Whater\Application\UseCase\Zones\CommandRequest\ListCountryCommand;
use Whater\Application\UseCase\Whater\CommandRequest\GetAnalyticalByDistributionNetworkAndResponsableCommand;
use Whater\Application\UseCase\Whater\CommandRequest\GetWhaterPointForShowBySlugCommand;
use Whater\Application\UseCase\Zones\CommandRequest\GetNearestTownByLatLongCommand;
/**
* @Route("public/whater")
*/
class PublicWhaterController extends AbstractBusController
{
/**
* @Route("/{userType}/map", name="web_public_whater_map", defaults={"_format" = "html", "userType" = "user"})
*/
public function whaterLocationsMapAction(Request $request, string $userType = null)
{
$grantUser = $this->getGrantedUser();
if ($grantUser != null) {
return new RedirectResponse($this->router()->generate('web_app_whater_map'));
}
$countries = [];
$defaultTown = null;
try {
$countriesPage = $this->handle(new ListCountryCommand(1, 1000, "name", "asc"));
$countries = $countriesPage->getCurrentPageResults();
$ip = $this->requestStack()->getMainRequest()->getClientIp();
if ($ip != '127.0.0.1') {
try {
$record = $this->geoIpReader()->city($ip);
if ($record->ubication->latitude != null) {
$defaultTown = $this->handle(new GetNearestTownByLatLongCommand($record->ubication->latitude, $record->ubication->longitude, 100));
}
} catch (\Exception $e) {
$defaultTown = $this->handle(new GetNearestTownByLatLongCommand(40.416775, -3.70379, 1000));
}
}
if ($defaultTown == null) {
$defaultTown = $this->handle(new GetNearestTownByLatLongCommand(40.416775, -3.70379, 1000));
}
} catch (\Exception $e) {
$errorMessage = '<br/>' . $this->translator()->trans($e->getMessage());
$this->setFlash('error', $this->translator()->trans('public.whater_map.exception') . $errorMessage);
}
return $this->render(
'Whater/whater_point_map.html.twig',
[
'countries' => $countries,
'defaultTown' => $defaultTown,
'userType' => $userType
]
);
}
/**
* @Route("/show/whaterpoint/{whaterPointId}", name="web_public_whater_point_show_old", defaults={"_format" = "html"})
*/
public function showWhaterPointOldAction(Request $request, $whaterPointId)
{
return new RedirectResponse($this->router()->generate('web_public_whater_point_show', ['whaterPointId' => $whaterPointId]));
}
/**
* @Route("/show/whaterpoint/id/{whaterPointId}", name="web_public_whater_point_show", defaults={"_format" = "html"})
*/
public function showWhaterPointAction(Request $request, $whaterPointId)
{
try {
$whaterPoint = $this->handle(new GetWhaterPointForShowCommand($whaterPointId));
if ($whaterPoint == null) {
return new RedirectResponse($this->router()->generate('web_init', array(), true));
}
return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_slug', ['whaterPointSlug' => $whaterPoint->slug()]));
} catch (\Exception $e) {
$this->setFlash('error', $this->translator()->trans($e->getMessage()));
return new RedirectResponse($this->router()->generate('web_init', array(), true));
}
}
/** DEPRECATED URLS */
/**
* Deprecated: USE web_public_whater_point_show_by_slug
* @Route("/show/whaterpoint/slug/{whaterPointSlug}", name="web_public_whater_point_show_by_slug_old", defaults={"_format" = "html"})
*/
public function showWhaterpointBySlugAction(Request $request, $whaterPointSlug)
{
return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_slug', ['whaterPointSlug' => $whaterPointSlug]));
}
/**
* Deprecated: USE web_public_whater_map
* @Route("/whater-map", name="web_public_whater_map_1", defaults={"_format" = "html"})
*/
public function showWhaterMapDeprecatedAction(Request $request)
{
return new RedirectResponse($this->router()->generate('web_public_whater_map'));
}
/**
* Deprecated: USE web_public_distribution_network_show_by_id
* @Route("/show/distribution_network/{distributionNetworkId}", name="web_public_distribution_network_show_1", defaults={"_format" = "html"})
*/
public function showDistributionNetworkIdAction(Request $request, $distributionNetworkId)
{
return new RedirectResponse($this->router()->generate('web_public_distribution_network_show_by_id', ['distributionNetworkId' => $distributionNetworkId]));
}
/**
* Deprecated: USE web_public_distribution_network_show_by_id
* @Route("/show/distribution_network/id/{distributionNetworkId}", name="web_public_distribution_network_show_2", defaults={"_format" = "html"})
*/
public function showDistributionNetworkByIdAction(Request $request, $distributionNetworkId)
{
return new RedirectResponse($this->router()->generate('web_public_distribution_network_show_by_id', ['distributionNetworkId' => $distributionNetworkId]));
}
/**
* Deprecated: USE web_public_distribution_network_show_by_slug
* @Route("/show/distribution_network/slug/{distributionNetworkSlug}", name="web_public_distribution_network_show_by_slug_deprecated_1", defaults={"_format" = "html"})
*/
public function showDistributionNetworkBySlugAction(Request $request, $distributionNetworkSlug)
{
return new RedirectResponse($this->router()->generate('web_public_distribution_network_show_by_slug', ['distributionNetworkSlug' => $distributionNetworkSlug]));
}
/**
* Deprecated: USE web_public_whater_point_show_by_id_2
* @Route("/show/whaterpoint/{whaterpointId}", name="web_public_whater_point_show_by_id_deprecated_1", defaults={"_format" = "html"})
*/
public function showWhaterpointByIdAction(Request $request, $whaterpointId)
{
return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_id_2', ['distributionNetworkId' => $distributionNetworkId]));
}
/**
* Deprecated: USE web_public_whater_point_show_by_id_2
* @Route("/show/whaterpoint/id/{whaterpointId}", name="web_public_whater_point_show_by_id_deprecated_2", defaults={"_format" = "html"})
*/
public function showWhaterpointById2Action(Request $request, $whaterpointId)
{
return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_id_2', ['whaterpointId' => $whaterpointId]));
}
/**
* Deprecated: USE web_public_whater_point_show_by_slug
* @Route("/show/whaterpoint/slug/{whaterpointSlug}", name="web_public_whater_point_show_by_slug_deprecated_1", defaults={"_format" = "html"})
*/
public function showWhaterpoint2BySlugAction(Request $request, $whaterpointSlug)
{
return new RedirectResponse($this->router()->generate('web_public_whater_point_show_by_slug', ['whaterpointSlug' => $whaterpointSlug]));
}
/**
* Deprecated: USE web_public_analytical_show
* @Route("/show/analytical/{analyticalId}", name="web_public_whater_analytical_show_deprecated_1", defaults={"_format" = "html"})
*/
public function showAnalyticalByIdAction(Request $request, $analyticalId)
{
return new RedirectResponse($this->router()->generate('web_public_analytical_show', ['analyticalId' => $analyticalId]));
}
}