<?php
/**
* This file is part of Symfony Keen Template Project.
* (c) 2021 One AM SRL
*/
namespace App\Controller\Frontend;
use App\Entity\TalkAboutUs;
use App\Repository\TalkAboutUsRepository;
use Doctrine\ORM\EntityManagerInterface;
use Keen\Attribute\Breadcrumb;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route(path: '/dicono-di-noi', name: 'frontend_talk_about_us_', methods: ['GET'])]
class TalkAboutUsController extends AbstractController
{
#[Route(path: '/', name: 'list', methods: ['GET'])]
#[Breadcrumb('Dicono di noi')]
public function list(TalkAboutUsRepository $talkAboutUsRepository, PaginatorInterface $paginator, Request $request): Response
{
$qb = $talkAboutUsRepository->createQueryBuilder('talkAboutUs')
->addOrderBy('talkAboutUs.position', 'DESC');
$pagination = $paginator->paginate(
$qb,
max(1, $request->query->getInt('page', 1)),
min($request->query->getInt('perPage', 9), 9)
);
return $this->render('frontend/talk_about_us/index.html.twig', [
'pagination' => $pagination,
]);
}
#[Route(path: '/{slug}', name: 'read', methods: ['GET'])]
public function read(string $slug, EntityManagerInterface $entityManager): Response
{
if (null === $article = $entityManager->getRepository(TalkAboutUs::class)->findOneBy(['slug' => $slug])) {
throw $this->createNotFoundException();
}
return $this->render('frontend/talk_about_us/article.html.twig', [
'article' => $article,
]);
}
}