src/Controller/OpinionController.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Dto\OpinionFilterDto;
  4. use App\Entity\User;
  5. use App\Privilege\RoleFactory;
  6. use App\Repository\OpinionRepository;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. /**
  14.  * @method User getUser()
  15.  * @Route("/opinion", name="opinion")
  16.  */
  17. class OpinionController extends AbstractController
  18. {
  19.     const OPINION_PER_PAGE_LATEST 8;
  20.     const OPINION_PER_PAGE_BEST 20;
  21.     /**
  22.      * @var OpinionRepository
  23.      */
  24.     private OpinionRepository $opinionRepository;
  25.     /**
  26.      * @var PaginatorInterface
  27.      */
  28.     private PaginatorInterface $paginator;
  29.     public function __construct(
  30.         OpinionRepository  $opinionRepository,
  31.         PaginatorInterface $paginator
  32.     )
  33.     {
  34.         $this->opinionRepository $opinionRepository;
  35.         $this->paginator $paginator;
  36.     }
  37.     /**
  38.      * @IsGranted(RoleFactory::ROLE_USER)
  39.      * @Route("", name="")
  40.      */
  41.     public function latest(Request $requestOpinionFilterDto $opinionFilterDto): Response
  42.     {
  43.         $pagination $this->paginator->paginate(
  44.             $this->opinionRepository->getLatestOpinion($this->getUser(), $opinionFilterDto),
  45.             $request->query->getInt('page'1),
  46.             self::OPINION_PER_PAGE_LATEST
  47.         );
  48.         return $this->render('opinion/latest.html.twig', [
  49.             'pagination' => $pagination,
  50.         ]);
  51.     }
  52.     /**
  53.      * @IsGranted(RoleFactory::ROLE_USER)
  54.      * @Route("/best", name="_best")
  55.      */
  56.     public function best(Request $requestOpinionFilterDto $opinionFilterDto): Response
  57.     {
  58.         $pagination $this->paginator->paginate(
  59.             $this->opinionRepository->getBestOpinion($this->getUser(), $opinionFilterDto),
  60.             $request->query->getInt('page'1),
  61.             self::OPINION_PER_PAGE_BEST
  62.         );
  63.         return $this->render('opinion/best.html.twig', [
  64.             'pagination' => $pagination,
  65.         ]);
  66.     }
  67. }