Skip to content
Snippets Groups Projects
Select Git revision
  • d80dc0293652bce9a830403a26e5c0cda8d2a10e
  • main default protected
  • register-logging-channel
  • expr-lang
  • ci-82
  • attr-events
  • locale-wip
  • custom-routes
  • v0.1.85
  • v0.1.84
  • v0.1.83
  • v0.1.82
  • v0.1.81
  • v0.1.80
  • v0.1.79
  • v0.1.78
  • v0.1.77
  • v0.1.76
  • v0.1.75
  • v0.1.74
  • v0.1.73
  • v0.1.72
  • v0.1.71
  • v0.1.70
  • v0.1.69
  • v0.1.68
  • v0.1.67
  • v0.1.65
28 results

Configuration.php

Blame
  • PersonCollectionDataProvider.php 1.67 KiB
    <?php
    
    declare(strict_types=1);
    
    namespace Dbp\Relay\BasePersonBundle\DataProvider;
    
    use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
    use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
    use Dbp\Relay\BasePersonBundle\API\PersonProviderInterface;
    use Dbp\Relay\BasePersonBundle\Entity\Person;
    use Dbp\Relay\CoreBundle\LocalData\LocalData;
    use Dbp\Relay\CoreBundle\Pagination\Pagination;
    use Dbp\Relay\CoreBundle\Pagination\Paginator;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    
    final class PersonCollectionDataProvider extends AbstractController implements CollectionDataProviderInterface, RestrictedDataProviderInterface
    {
        public const MAX_NUM_ITEMS_PER_PAGE_DEFAULT = 50;
    
        /** @var PersonProviderInterface */
        private $personProvider;
    
        public function __construct(PersonProviderInterface $personProvider)
        {
            $this->personProvider = $personProvider;
        }
    
        public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
        {
            return Person::class === $resourceClass;
        }
    
        public function getCollection(string $resourceClass, string $operationName = null, array $context = []): Paginator
        {
            $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
    
            $filters = $context['filters'] ?? [];
            $options = [];
    
            if ($search = ($filters['search'] ?? null)) {
                $options[Person::SEARCH_PARAMETER_NAME] = $search;
            }
    
            LocalData::addOptions($options, $filters);
            Pagination::addOptions($options, $filters, self::MAX_NUM_ITEMS_PER_PAGE_DEFAULT);
    
            return $this->personProvider->getPersons($options);
        }
    }