<?php
namespace App\Controller;
use App\Entity\Agencesvoyages\Agencesvoyages;
use App\Repository\Agencesvoyages\AgencesvoyagesRepository;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/agences/voyages")
*/
class AgencesvoyagesController extends AbstractController
{
/**
* @var AgencesvoyagesRepository
*/
private $repository;
/**
* AgencesvoyagesController constructor.
* @param AgencesvoyagesRepository $repository
*/
public function __construct(AgencesvoyagesRepository $repository)
{
$this->repository = $repository;
}
/**
* @Route("/", name="agencesvoyages.index", defaults={"title":"Agences de voyages"})
* @param Request $request
* @param $title
* @param PaginatorInterface $paginator
* @return Response
*/
public function agencesVoyages(Request $request, $title, PaginatorInterface $paginator)
{
$agences = $paginator->paginate(
$this->repository->findBy(['online' => true]), /* query NOT result */
$request->query->getInt('page', 1)/*page number*/,
$request->query->getInt('limit', 6)/*limit per page*/
);
return $this->render('pages/internes/agencesvoyages/index.html.twig', [
'title' => $title,
'agences' => $agences,
'menu' => "Séjourner",
'current_page' => 'sejours'
]);
}
/**
* @Route("/{slug}/{id}", name="agencesvoyages.show")
* @param $slug
* @param Agencesvoyages $agencesvoyage
* @return Response
*/
public function show($slug, Agencesvoyages $agencesvoyage)
{
if ($agencesvoyage->getSlug() !== $slug) {
return $this->redirectToRoute('agencesvoyages.show', [
'id' => $agencesvoyage->getId(),
'slug' => $agencesvoyage->getSlug(),
], 301);
}
$othersAgences = $this->repository->getAgencesvoyagesRandom($agencesvoyage, 3);
return $this->render('pages/internes/agencesvoyages/show.html.twig', [
'title' => $agencesvoyage->getName(),
'agence' => $agencesvoyage,
'agences' => $othersAgences,
'menu' => "Côte d'Ivoire Tourisme",
'current_page' => 'cit'
]);
}
}