src/Controller/Mvc/reportController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Mvc;
  3. use App\Service\Entry\ReportService;
  4. use App\Utils\TargetChoiceUtil;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/report")
  12.  */
  13. class reportController extends AbstractController
  14. {
  15.     /**
  16.      * @Route ("/", name="report_index", methods={"GET"})
  17.      */
  18.     public function index(
  19.         Request $request,
  20.         ReportService $service
  21.     ) {
  22.         $criteria $service->getCriteriaFromRequest($request);
  23.         $qb $service->getQueryBuilder($criteria);
  24.         $paginate $service->handleList($qb$criteria);
  25.         return $this->render('pages/report/index.html.twig', [
  26.             "paginate" => $paginate,
  27.             "data" => $paginate->getPaginator()->getIterator(),
  28.             "categories" => TargetChoiceUtil::localeNames($request->getLocale()),
  29.             "criteria" => $criteria
  30.         ]);
  31.     }
  32.     /**
  33.      * @Route("/{id}", name="report_detail", methods={"GET"}, requirements={"id" = "\d+"})
  34.      */
  35.     public function detail(
  36.         Request $request,
  37.         ReportService $service,
  38.         int $id
  39.     ) {
  40.         $report $service
  41.             ->getQueryBuilder(["id" => $id])
  42.             ->getQuery()
  43.             ->getOneOrNullResult()
  44.             ;
  45.         if(!$report) {
  46.             throw new NotFoundHttpException('記事がありません');
  47.         }
  48.         return $this->render('pages/report/detail.html.twig', [
  49.             "report" => $report
  50.         ]);
  51.     }
  52.     /**
  53.      * @Route ("/headline", name="report_headline", methods={"GET"})
  54.      */
  55.     public function headline(
  56.         ReportService $service
  57.     ): Response {
  58.         $reports $service
  59.             ->getQueryBuilder([])
  60.             ->setMaxResults(2)
  61.             ->getQuery()
  62.             ->getResult()
  63.             ;
  64.         return $this->render('pages/report/headline.html.twig', [
  65.             "reports" => $reports
  66.         ]);
  67.     }
  68. }