src/Controller/Espacepros/RestaurantsController.php line 84

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Espacepros;
  3. use App\Data\SearchrestaurantData;
  4. use App\Entity\Restaurants\Restaurants;
  5. use App\Form\Restaurants\SearchFormRestaurantsType;
  6. use App\Repository\Restaurants\RestaurantsRepository;
  7. use MercurySeries\FlashyBundle\FlashyNotifier;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. /**
  14.  * @Route("/sejourner/restaurants")
  15.  */
  16. class RestaurantsController extends AbstractController
  17. {
  18.     /**
  19.      * @var FlashyNotifier
  20.      */
  21.     private $flashy;
  22.     /**
  23.      * @var RestaurantsRepository
  24.      */
  25.     private $restaurantsRepository;
  26.     public function __construct(RestaurantsRepository $restaurantsRepositoryFlashyNotifier $flashy)
  27.     {
  28.         $this->restaurantsRepository $restaurantsRepository;
  29.         $this->flashy $flashy;
  30.     }
  31.     /**
  32.      * @Route("/", name="restaurants.index")
  33.      * @param Request $request
  34.      * @return Response
  35.      */
  36.     public function index(Request $request): Response
  37.     {
  38.         $data = new SearchrestaurantData();
  39.         $data->page $request->get('page'1);
  40.         $formsearch $this->createForm(SearchFormRestaurantsType::class, $data);
  41.         $formsearch->handleRequest($request);
  42.         $restaurants $this->restaurantsRepository->findSearch($data);
  43.         if ($request->get('ajax')) {
  44.             return new JsonResponse([
  45.                 'content' => $this->renderView('pages/espacepro/restaurants/partials/__card.html.twig', ['restaurants' => $restaurants]),
  46.                 'sorting' => $this->renderView('pages/espacepro/restaurants/partials/__sorting.html.twig', ['restaurants' => $restaurants]),
  47.                 'pagination' => $this->renderView('pages/espacepro/restaurants/partials/__pagination.html.twig', ['restaurants' => $restaurants]),
  48.             ]);
  49.         }
  50.         //$restaurants = $this->restaurantsRepository->findRestaurantsByActivated($request->query->getInt('page', 1));
  51.         return $this->render('pages/espacepro/restaurants/index.html.twig', [
  52.             'title' => 'Espace Restauration',
  53.             'restaurants' => $restaurants,
  54.             'formsearch' => $formsearch->createView(),
  55.             'menu' => "Séjourner",
  56.             'submenu' => "Ou manger",
  57.             'current_page' => 'sejourner'
  58.         ]);
  59.     }
  60.     /**
  61.      * @Route("/details/{slug}/{id}", name="restaurants.show")
  62.      * @param $slug
  63.      * @param Restaurants $restaurants
  64.      * @return Response
  65.      */
  66.     public function show($slugRestaurants $restaurants): Response
  67.     {
  68.         if ($restaurants->getSlug() !== $slug) {
  69.             return $this->redirectToRoute('restaurants.show', [
  70.                 'id' => $restaurants->getId(),
  71.                 'slug' => $restaurants->getSlug(),
  72.             ], 301);
  73.         }
  74.         $othersRestaurants $this->restaurantsRepository->getRestaurantsRandom($restaurants3);
  75.         return $this->render('pages/espacepro/restaurants/show.html.twig', [
  76.             'title' => $restaurants->getName(),
  77.             'restaurant' => $restaurants,
  78.             'othersRestaurants' => $othersRestaurants,
  79.             'menu' => "Séjourner",
  80.             'submenu' => "Ou manger",
  81.             'current_page' => 'sejourner'
  82.         ]);
  83.     }
  84. }