<?php
namespace App\Controller\Front;
use App\Entity\Community;
use App\Entity\Masjid;
use App\Repository\CommunityRepository;
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("/community")
*/
class CommunityController extends AbstractController
{
/**
* @Route("/", name="community_index", methods={"GET"})
*/
public function index(CommunityRepository $communityRepository): Response
{
return $this->render('community/index.html.twig', [
'communities' => $communityRepository->findAll(),
]);
}
/**
* @Route("/{slug}", name="community_show", methods={"GET"})
*/
public function show(Community $community, Request $request, PaginatorInterface $paginator): Response
{
$masjidsByCommunity = $this->getDoctrine()
->getRepository(Masjid::class)
->findByCommunity($community);
$pagination = $paginator->paginate(
$masjidsByCommunity, /* query NOT result */
$request->query->getInt('page', 1), /*page number*/
10 /*limit per page*/
);
return $this->render('community/show.html.twig', [
'community' => $community,
'masjids' => $pagination
]);
}
}