<?php
namespace App\Controller\Frontend;
use App\Controller\BaseController;
use App\Form\Frontend\PhoneBookSearchType;
use App\Repository\EnterpriseRepository;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PhoneBookController extends BaseController
{
#[Route('/phone/book', name: 'customer_phone_book', methods: ['GET', 'POST'])]
public function index(
Request $request,
EnterpriseRepository $repository,
PaginatorInterface $paginator
): Response
{
$search = null;
$form = $this->createForm(PhoneBookSearchType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$search = $form->get('search')->getData();
}
$query = $repository->findMemberOnPhoneBookQuery($search);
$firms = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
self::ITEM_PER_PAGE
);
return $this->renderForm('frontend/phone_book/index.html.twig', [
'controller_name' => 'PhoneBookController',
'menu' => 'phone-book',
'firms' => $firms,
'form' => $form
]);
}
}