src/Controller/Admin/FirmanteAdminController.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Admin;
  4. use App\Entity\Firmante;
  5. use App\Repository\FirmanteRepository;
  6. use InvalidArgumentException;
  7. use Sonata\AdminBundle\Controller\CRUDController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. final class FirmanteAdminController extends CRUDController
  11. {
  12.     public function __construct(private FirmanteRepository $repository)
  13.     {
  14.     }
  15.     public function getFirmantesByTipoIdiomaAction(Request $request)
  16.     {
  17.         try {
  18.             $firmanteS = [];
  19.             $resultS $this->repository->searchByTipoIdioma(
  20.                 $request->query->get('q'),
  21.                 $request->query->get('tipo'),
  22.                 $request->query->get('idioma'),
  23.                 $request->query->get('unidadNegocio'),
  24.                 $request->query->get('page_limit'),
  25.                 $request->query->get('page') ?: 1,
  26.                 $request->query->get('id') ?: null,
  27.             );
  28.             if (!count($resultS)) {
  29.                 throw new InvalidArgumentException();
  30.             }
  31.             foreach ($resultS as $firmante) {
  32.                 $firmanteS[] = [
  33.                     'id' => $firmante->getId(),
  34.                     'text' => $firmante->getNombre(),
  35.                 ];
  36.             }
  37.             return new JsonResponse(
  38.                 [
  39.                     'results' => $firmanteS,
  40.                     'more' => count($firmanteS) == $request->query->get('page_limit'),
  41.                 ],
  42.                 200
  43.             );
  44.         } catch (InvalidArgumentException $e) {
  45.             return new JsonResponse(['results' => [], 'more' => false], 400);
  46.         }
  47.     }
  48. }