src/Controller/DefaultController.php line 56

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Menu;
  4. use App\Entity\Restaurante;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. class DefaultController extends AbstractController
  10. {
  11.     public function index(Request $requestManagerRegistry $doctrine): Response
  12.     {
  13.         return $this->render('default/index.html.twig',);
  14.     }
  15.     public function menus(Request $requestManagerRegistry $doctrine): Response
  16.     {
  17.         // Price
  18.         $precioMax 50;
  19.         if ($request->request->get('precioMax')) {
  20.             $precioMax= (int) $request->request->get('precioMax');
  21.         }
  22.         // Distance
  23.         $distanciaMax 50;
  24.         if ($request->request->get('distanciaMax')) {
  25.             $distanciaMax = (int) $request->request->get('distanciaMax');
  26.         }
  27.         // Location
  28.         $latitude '';
  29.         $longitude '';
  30.         if ($request->request->get('latActual') && $request->request->get('lngActual')) {
  31.             $latitude $request->request->get('latActual');
  32.             $longitude $request->request->get('lngActual');
  33.         }
  34.         $menuRepository $doctrine->getRepository(Menu::class);
  35.         $menus $menuRepository->findNearByActiveAndPrice(floatval($latitude), floatval($longitude), $distanciaMax$precioMax);
  36.         
  37.         return $this->render('default/menus.html.twig', [
  38.             'menus' => $menus,
  39.             'precioMax' => $precioMax,
  40.             'distanciaMax' => $distanciaMax,
  41.             'latActual' => $latitude,
  42.             'lngActual' => $longitude
  43.         ]);
  44.     }
  45.     public function restaurants(Request $requestManagerRegistry $doctrine): Response
  46.     {
  47.         // Price
  48.         $precioMax 50;
  49.         if ($request->request->get('precioMax')) {
  50.             $precioMax= (int) $request->request->get('precioMax');
  51.         }
  52.         // Distance
  53.         $distanciaMax 50;
  54.         if ($request->request->get('distanciaMax')) {
  55.             $distanciaMax = (int) $request->request->get('distanciaMax');
  56.         }
  57.         // Location
  58.         $latitude '';
  59.         $longitude '';
  60.         if ($request->request->get('latActual') && $request->request->get('lngActual')) {
  61.             $latitude $request->request->get('latActual');
  62.             $longitude $request->request->get('lngActual');
  63.         }
  64.         $restaurantRepository $doctrine->getRepository(Restaurante::class);
  65.         $restaurants $restaurantRepository->findNearByActive(floatval($latitude), floatval($longitude), $distanciaMax);
  66.         
  67.         return $this->render('default/restaurants.html.twig', [
  68.             'restaurants' => $restaurants,
  69.             'precioMax' => $precioMax,
  70.             'distanciaMax' => $distanciaMax,            
  71.             'latActual' => $latitude,
  72.             'lngActual' => $longitude
  73.         ]);
  74.     }
  75.     public function showRestaurant(ManagerRegistry $doctrine$id)
  76.     {
  77.         $restaurant $doctrine->getRepository(Restaurante::class)->findOneBy(['id' => $id]);
  78.         $googlePlaceDetails = [];
  79.         $arrayData json_decode($restaurant->getPlaceDetails(), true); // json object to array conversion
  80.         if (isset($arrayData['result'])) {
  81.             $googlePlaceDetails $arrayData['result'];
  82.         }
  83.         return $this->render('default/showRestaurant.html.twig', array('restaurant' => $restaurant'googlePlaceDetails' => $googlePlaceDetails));
  84.     }
  85. }