src/Controller/Front/LawController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use App\Repository\Law\LawRepository;
  8. use App\Repository\Law\SectionRepository;
  9. use App\Entity\Law\Section;
  10. use App\Entity\Law\Law;
  11. class LawController extends AbstractController
  12. {
  13.     public function index(Request $requestLawRepository $repositorySectionRepository $sectionRepositoryPaginatorInterface $paginatorSection $section null): Response
  14.     {
  15.         $keyword $request->query->get('keyword');
  16.         $query $repository->findLawsQuery($section$keyword);
  17.         $laws $paginator->paginate($query$request->query->getInt('page'1), 3);
  18.         $sections $sectionRepository->findAll();
  19.         $recentLaw $repository->findRecent();
  20.         $count 0;
  21.         foreach ($sections as $section)  $count += count($section->getLaws());
  22.         return $this->render('front/law/index.html.twig', [
  23.             'laws' => $laws,
  24.             'count' => $count,
  25.             'keyword' => $keyword,
  26.             'sections' => $sections,
  27.             'recent_law' => $recentLaw,
  28.         ]);
  29.     }
  30.     public function show(Law $lawLawRepository $repositorySectionRepository $sectionRepository): Response
  31.     {
  32.         $sections $sectionRepository->findAll();
  33.         $recentLaw $repository->findRecent();
  34.         $count 0;
  35.         foreach ($sections as $section)  $count += count($section->getLaws());
  36.         return $this->render('front/law/show.html.twig', [
  37.             'law' => $law,
  38.             'count' => $count,
  39.             'sections' => $sections,
  40.             'recent_law' => $recentLaw,
  41.         ]);
  42.     }
  43. }