<?php
namespace App\Controller;
use App\Entity\Menu;
use App\Entity\Restaurante;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DefaultController extends AbstractController
{
public function index(Request $request, ManagerRegistry $doctrine): Response
{
return $this->render('default/index.html.twig',);
}
public function menus(Request $request, ManagerRegistry $doctrine): Response
{
// Price
$precioMax = 50;
if ($request->request->get('precioMax')) {
$precioMax= (int) $request->request->get('precioMax');
}
// Distance
$distanciaMax = 50;
if ($request->request->get('distanciaMax')) {
$distanciaMax = (int) $request->request->get('distanciaMax');
}
// Location
$latitude = '';
$longitude = '';
if ($request->request->get('latActual') && $request->request->get('lngActual')) {
$latitude = $request->request->get('latActual');
$longitude = $request->request->get('lngActual');
}
$menuRepository = $doctrine->getRepository(Menu::class);
$menus = $menuRepository->findNearByActiveAndPrice(floatval($latitude), floatval($longitude), $distanciaMax, $precioMax);
return $this->render('default/menus.html.twig', [
'menus' => $menus,
'precioMax' => $precioMax,
'distanciaMax' => $distanciaMax,
'latActual' => $latitude,
'lngActual' => $longitude
]);
}
public function restaurants(Request $request, ManagerRegistry $doctrine): Response
{
// Price
$precioMax = 50;
if ($request->request->get('precioMax')) {
$precioMax= (int) $request->request->get('precioMax');
}
// Distance
$distanciaMax = 50;
if ($request->request->get('distanciaMax')) {
$distanciaMax = (int) $request->request->get('distanciaMax');
}
// Location
$latitude = '';
$longitude = '';
if ($request->request->get('latActual') && $request->request->get('lngActual')) {
$latitude = $request->request->get('latActual');
$longitude = $request->request->get('lngActual');
}
$restaurantRepository = $doctrine->getRepository(Restaurante::class);
$restaurants = $restaurantRepository->findNearByActive(floatval($latitude), floatval($longitude), $distanciaMax);
return $this->render('default/restaurants.html.twig', [
'restaurants' => $restaurants,
'precioMax' => $precioMax,
'distanciaMax' => $distanciaMax,
'latActual' => $latitude,
'lngActual' => $longitude
]);
}
public function showRestaurant(ManagerRegistry $doctrine, $id)
{
$restaurant = $doctrine->getRepository(Restaurante::class)->findOneBy(['id' => $id]);
$googlePlaceDetails = [];
$arrayData = json_decode($restaurant->getPlaceDetails(), true); // json object to array conversion
if (isset($arrayData['result'])) {
$googlePlaceDetails = $arrayData['result'];
}
return $this->render('default/showRestaurant.html.twig', array('restaurant' => $restaurant, 'googlePlaceDetails' => $googlePlaceDetails));
}
}