<?php
namespace Whater\UI\WebBundle\Controller\Zones;
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\Zones\CommandRequest\GetCountryAreaByIdCommand;
use Whater\Application\UseCase\Zones\CommandRequest\GetCountryAreaBySlugCommand;
/**
* @Route("public/country-area")
*/
class PublicCountryAreaController extends AbstractBusController
{
/**
* @Route("/show/id/{countryAreaId}", name="web_public_country_area_show", defaults={"_format" = "html"})
*/
public function showCountryAreaAction(Request $request, $countryAreaId)
{
$countryArea = null;
try {
$countryArea = $this->handle(new GetCountryAreaByIdCommand($countryAreaId));
if ($countryArea == null) {
return new RedirectResponse($this->router()->generate('web_init', array(), true));
}
return new RedirectResponse($this->router()->generate('web_public_country_area_show_by_slug', ['countryAreaSlug' => $countryArea->slug()]));
} catch (\Exception $e) {
$errorMessage = '<br/>' . $this->translator()->trans($e->getMessage());
$this->setFlash('error', $this->translator()->trans('admin.country_area.show.exception') . $errorMessage);
return new RedirectResponse($this->router()->generate('web_init', array(), true));
}
}
/**
* @Route("/show/name/{countryAreaSlug}", name="web_public_country_area_show_by_slug", defaults={"_format" = "html"})
*/
public function showCountryAreaBySlugAction(Request $request, $countryAreaSlug)
{
$countryArea = null;
try {
$countryArea = $this->handle(new GetCountryAreaBySlugCommand($countryAreaSlug));
if ($countryArea == null) {
return new RedirectResponse($this->router()->generate('web_init', array(), true));
}
} catch (\Exception $e) {
$this->setFlash('error', $this->translator()->trans($e->getMessage()));
}
return $this->render('Zones/public_country_area_show.html.twig', array(
'countryArea' => $countryArea
));
}
}