Paginated comments
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Entity\Conference;
|
||||
use App\Repository\CommentRepository;
|
||||
use App\Repository\ConferenceRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Twig\Environment;
|
||||
@@ -21,11 +22,16 @@ class ConferenceController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/conference/{id}', name: 'conference')]
|
||||
public function show(Environment $twig, Conference $conference, CommentRepository $commentRepository): Response
|
||||
public function show(Request $request, Environment $twig, Conference $conference, CommentRepository $commentRepository): Response
|
||||
{
|
||||
$offset = max(0, $request->query->getInt('offset', 0));
|
||||
$paginator = $commentRepository->getCommentPaginator($conference, $offset);
|
||||
|
||||
return new Response($twig->render('conference/show.html.twig', [
|
||||
'conference' => $conference,
|
||||
'comments' => $commentRepository->findBy(['conference' => $conference], ['createdAt' => 'DESC']),
|
||||
'comments' => $paginator,
|
||||
'previous' => $offset - CommentRepository::COMMENTS_PER_PAGE,
|
||||
'next' => min(count($paginator), $offset + CommentRepository::COMMENTS_PER_PAGE)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user