src/UI/WebBundle/Controller/Zones/PublicCountryAreaController.php line 54

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\Zones\CommandRequest\GetCountryAreaByIdCommand;
  8. use Whater\Application\UseCase\Zones\CommandRequest\GetCountryAreaBySlugCommand;
  9. /**
  10. * @Route("public/country-area")
  11. */
  12. class PublicCountryAreaController extends AbstractBusController
  13. {
  14. /**
  15. * @Route("/show/id/{countryAreaId}", name="web_public_country_area_show", defaults={"_format" = "html"})
  16. */
  17. public function showCountryAreaAction(Request $request, $countryAreaId)
  18. {
  19. $countryArea = null;
  20. try {
  21. $countryArea = $this->handle(new GetCountryAreaByIdCommand($countryAreaId));
  22. if ($countryArea == null) {
  23. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  24. }
  25. return new RedirectResponse($this->router()->generate('web_public_country_area_show_by_slug', ['countryAreaSlug' => $countryArea->slug()]));
  26. } catch (\Exception $e) {
  27. $errorMessage = '<br/>' . $this->translator()->trans($e->getMessage());
  28. $this->setFlash('error', $this->translator()->trans('admin.country_area.show.exception') . $errorMessage);
  29. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  30. }
  31. }
  32. /**
  33. * @Route("/show/name/{countryAreaSlug}", name="web_public_country_area_show_by_slug", defaults={"_format" = "html"})
  34. */
  35. public function showCountryAreaBySlugAction(Request $request, $countryAreaSlug)
  36. {
  37. $countryArea = null;
  38. try {
  39. $countryArea = $this->handle(new GetCountryAreaBySlugCommand($countryAreaSlug));
  40. if ($countryArea == null) {
  41. return new RedirectResponse($this->router()->generate('web_init', array(), true));
  42. }
  43. } catch (\Exception $e) {
  44. $this->setFlash('error', $this->translator()->trans($e->getMessage()));
  45. }
  46. return $this->render('Zones/public_country_area_show.html.twig', array(
  47. 'countryArea' => $countryArea
  48. ));
  49. }
  50. }