<?php
namespace App\Controller\Front;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Knp\Component\Pager\PaginatorInterface;
use App\Repository\Law\LawRepository;
use App\Repository\Law\SectionRepository;
use App\Entity\Law\Section;
use App\Entity\Law\Law;
class LawController extends AbstractController
{
public function index(Request $request, LawRepository $repository, SectionRepository $sectionRepository, PaginatorInterface $paginator, Section $section = null): Response
{
$keyword = $request->query->get('keyword');
$query = $repository->findLawsQuery($section, $keyword);
$laws = $paginator->paginate($query, $request->query->getInt('page', 1), 3);
$sections = $sectionRepository->findAll();
$recentLaw = $repository->findRecent();
$count = 0;
foreach ($sections as $section) $count += count($section->getLaws());
return $this->render('front/law/index.html.twig', [
'laws' => $laws,
'count' => $count,
'keyword' => $keyword,
'sections' => $sections,
'recent_law' => $recentLaw,
]);
}
public function show(Law $law, LawRepository $repository, SectionRepository $sectionRepository): Response
{
$sections = $sectionRepository->findAll();
$recentLaw = $repository->findRecent();
$count = 0;
foreach ($sections as $section) $count += count($section->getLaws());
return $this->render('front/law/show.html.twig', [
'law' => $law,
'count' => $count,
'sections' => $sections,
'recent_law' => $recentLaw,
]);
}
}