src/Controller/IndexController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use App\Utils\Utils;
  8. use App\Utils\Paramsutils;
  9. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  10. class IndexController extends AbstractController {
  11. /**
  12. * @Route("/", name="app_index")
  13. */
  14. public function index(ParameterBagInterface $parameters, Request $request): Response {
  15. $paramsutils = new Paramsutils;
  16. $utils = new Utils;
  17. $data = $paramsutils->leerParametros();
  18. $params = $parameters->get("PARAMSCONF");
  19. $service = $data["default_service"];//Cargamos servicio por defecto
  20. $city = null;
  21. if (isset($data["servicios"][$service])) { //Cargamos ciudad por defecto
  22. $city = $data["servicios"][$service]["default_city"];
  23. }
  24. if ($params["level"] == 0) {
  25. // Nivel 0 · Renderizamos una landing estándar de nivel 0
  26. $renderParamsArray = $utils->renderParamsArray($data, $params, $service, $city);
  27. } else if ($params["level"] == 1) {
  28. // Nivel 1 · Redirigimos a /[ciudad] por defecto
  29. $city = reset($data["ciudades"]);
  30. $city = strtolower($city["name"]);
  31. return $this->redirectToRoute("app_nivel1", ["param1" => $city] );
  32. }else if ($params["level"] == 2) {
  33. // Si es Nivel 2, entendemos que el parámetro es el servicio y redirigimos.
  34. $city = strtolower($city);
  35. return $this->redirectToRoute( "app_nivel2", ["service" => $service, "city" => $city]);
  36. }
  37. if ($renderParamsArray != null) {
  38. return $this->render("index/index.html.twig",
  39. $renderParamsArray
  40. );
  41. } else {
  42. return $this->render("bundles\TwigBundle\Exception\error404.html.twig");
  43. }
  44. }
  45. }