diff --git a/composer.lock b/composer.lock index c70197ed0b1e48d40d1bd280ca8bf2e70acdcc59..2b1fdf51be2f04936772410ec7b0ea2658841002 100644 --- a/composer.lock +++ b/composer.lock @@ -169,11 +169,11 @@ }, { "name": "dbp/relay-core-bundle", - "version": "v0.1.45", + "version": "v0.1.46", "source": { "type": "git", "url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-core-bundle", - "reference": "277aed04ce808a8fd1f4ed70257dd4900d5a08ba" + "reference": "f60e56773350b9d87ceabf39387e5ce720a7d5ab" }, "require": { "api-platform/core": "^2.6.8 <2.7.0", @@ -236,7 +236,7 @@ "AGPL-3.0-or-later" ], "description": "The core bundle of the Relay API gateway", - "time": "2022-10-17T09:29:42+00:00" + "time": "2022-10-24T11:56:43+00:00" }, { "name": "doctrine/annotations", @@ -10042,5 +10042,5 @@ "platform-overrides": { "php": "7.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/API/OrganizationProviderInterface.php b/src/API/OrganizationProviderInterface.php index 06b7cfa316dc8722301ec0020c453fb392079de6..7f02650425fa10f28a21d6b8185e06d1a1da523e 100644 --- a/src/API/OrganizationProviderInterface.php +++ b/src/API/OrganizationProviderInterface.php @@ -21,10 +21,11 @@ interface OrganizationProviderInterface /** * @param array $options Available options: - * * 'lang' ('de' or 'en') - * * Organization::SEARCH_PARAMETER_NAME (partial, case-insensitive text search on 'name' attribute) - * * LocalData::INCLUDE_PARAMETER_NAME - * * LocalData::QUERY_PARAMETER_NAME + * * string 'lang' ('de' or 'en') + * * array 'identifiers' The list of organizations to return + * * string Organization::SEARCH_PARAMETER_NAME (partial, case-insensitive text search on 'name' attribute) + * * string LocalData::INCLUDE_PARAMETER_NAME + * * string LocalData::QUERY_PARAMETER_NAME * * @throws ApiError */ diff --git a/src/DataProvider/OrganizationCollectionDataProvider.php b/src/DataProvider/OrganizationCollectionDataProvider.php index c63e7de965b65d5f9dc38198d3055552f2f54b25..43995a2a04f8f58e3b0bf9d06cc04dfe72592f91 100644 --- a/src/DataProvider/OrganizationCollectionDataProvider.php +++ b/src/DataProvider/OrganizationCollectionDataProvider.php @@ -11,6 +11,7 @@ use Dbp\Relay\BaseOrganizationBundle\API\OrganizationProviderInterface; use Dbp\Relay\BaseOrganizationBundle\API\OrganizationsByPersonProviderInterface; use Dbp\Relay\BaseOrganizationBundle\Entity\Organization; use Dbp\Relay\CoreBundle\Exception\ApiError; +use Dbp\Relay\CoreBundle\Helpers\Locale; use Dbp\Relay\CoreBundle\LocalData\LocalData; use Dbp\Relay\CoreBundle\Pagination\Pagination; use Dbp\Relay\CoreBundle\Pagination\Paginator; @@ -27,9 +28,13 @@ final class OrganizationCollectionDataProvider extends AbstractController implem /** @var OrganizationsByPersonProviderInterface */ private $organizationsByPersonProvider; - public function __construct(OrganizationProviderInterface $organizationProvider, OrganizationsByPersonProviderInterface $organizationsByPersonProvider) + /** @var Locale */ + private $locale; + + public function __construct(OrganizationProviderInterface $organizationProvider, Locale $locale, OrganizationsByPersonProviderInterface $organizationsByPersonProvider) { $this->organizationProvider = $organizationProvider; + $this->locale = $locale; $this->organizationsByPersonProvider = $organizationsByPersonProvider; } @@ -43,8 +48,7 @@ final class OrganizationCollectionDataProvider extends AbstractController implem $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $filters = $context['filters'] ?? []; - - $options = ['lang' => $filters['lang'] ?? 'de']; + $options = []; if ($search = ($filters['search'] ?? null)) { $options['search'] = $search; @@ -53,7 +57,15 @@ final class OrganizationCollectionDataProvider extends AbstractController implem LocalData::addOptions($options, $filters); Pagination::addOptions($options, $filters, self::MAX_ITEMS_PER_PAGE); - // TODO: make 'person' a local query parameter and move filter implementation to connector (CAUTION: might break existing apps) + // @deprecate 'lang' filter is deprecate, use 'Accept-Language' header instead + if (($lang = $filters['lang'] ?? null) !== null) { + $options[Locale::LANGUAGE_OPTION] = $lang; + } else { + $this->locale->addLanguageOption($options); + } + + //------------------------------------------------------------------------- + // @deprecate The 'person' filter is deprecate. Use the 'identifiers' filter in your custom organizations wrapper. $personId = $filters['person'] ?? ''; if ($personId !== '') { if ($personId !== $this->getUser()->getUserIdentifier()) { @@ -67,14 +79,13 @@ final class OrganizationCollectionDataProvider extends AbstractController implem } if ($orgIdPaginator instanceof PaginatorInterface) { - $paginator = Pagination::createFullPaginator($organizations, $options, intval($orgIdPaginator->getTotalItems())); + return Pagination::createFullPaginator($organizations, $options, intval($orgIdPaginator->getTotalItems())); } else { - $paginator = Pagination::createPartialPaginator($organizations, $options); + return Pagination::createPartialPaginator($organizations, $options); } - } else { - $paginator = $this->organizationProvider->getOrganizations($options); } + //------------------------------------------------------------------------- - return $paginator; + return $this->organizationProvider->getOrganizations($options); } } diff --git a/src/DataProvider/OrganizationItemDataProvider.php b/src/DataProvider/OrganizationItemDataProvider.php index cee182c9e532f838a446eab4f5405a1a0b615efc..515a5da3c0788badf2019b95c94d169d9e4ecc39 100644 --- a/src/DataProvider/OrganizationItemDataProvider.php +++ b/src/DataProvider/OrganizationItemDataProvider.php @@ -8,16 +8,22 @@ use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use Dbp\Relay\BaseOrganizationBundle\API\OrganizationProviderInterface; use Dbp\Relay\BaseOrganizationBundle\Entity\Organization; +use Dbp\Relay\CoreBundle\Helpers\Locale; use Dbp\Relay\CoreBundle\LocalData\LocalData; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; final class OrganizationItemDataProvider extends AbstractController implements ItemDataProviderInterface, RestrictedDataProviderInterface { + /** @var OrganizationProviderInterface */ private $api; - public function __construct(OrganizationProviderInterface $api) + /** @var Locale */ + private $locale; + + public function __construct(OrganizationProviderInterface $api, Locale $locale) { $this->api = $api; + $this->locale = $locale; } public function supports(string $resourceClass, string $operationName = null, array $context = []): bool @@ -30,10 +36,16 @@ final class OrganizationItemDataProvider extends AbstractController implements I $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $filters = $context['filters'] ?? []; - $options = []; - $options['lang'] = $filters['lang'] ?? 'de'; - $options[LocalData::INCLUDE_PARAMETER_NAME] = LocalData::getIncludeParameter($filters); + + LocalData::addOptions($options, $filters); + + // @deprecate 'lang' filter is deprecate, use 'Accept-Language' header instead + if (($lang = $filters['lang'] ?? null) !== null) { + $options[Locale::LANGUAGE_OPTION] = $lang; + } else { + $this->locale->addLanguageOption($options); + } return $this->api->getOrganizationById($id, $options); } diff --git a/src/Entity/Organization.php b/src/Entity/Organization.php index 53def1f473d98ff615c397010ce0448f79f709da..0c5105b6456e3971b39708f2e0293f434b84550d 100644 --- a/src/Entity/Organization.php +++ b/src/Entity/Organization.php @@ -19,8 +19,7 @@ use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareTrait; * "tags" = {"BaseOrganization"}, * "parameters" = { * {"name" = "search", "in" = "query", "description" = "Search filter (partial, case-insensitive text search on 'name' attribute)", "type" = "string", "required" = false}, - * {"name" = "person", "in" = "query", "description" = "Get organizations of a person (ID of BasePerson resource)", "type" = "string", "required" = false}, - * {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"}, + * {"name" = "person", "in" = "query", "description" = "DEPRECATE: Get organizations of a person (ID of BasePerson resource)", "type" = "string", "required" = false}, * {"name" = "queryLocal", "in" = "query", "description" = "Local query parameters to apply", "type" = "string"}, * {"name" = "includeLocal", "in" = "query", "description" = "Local data attributes to include", "type" = "string", "example" = "BaseOrganization.code"}, * {"name" = "partialPagination", "in" = "query", "description" = "Partial pagination", "type" = "bool", "example" = "false"} @@ -36,7 +35,6 @@ use Dbp\Relay\CoreBundle\LocalData\LocalDataAwareTrait; * "tags" = {"BaseOrganization"}, * "parameters" = { * {"name" = "identifier", "in" = "path", "description" = "Resource identifier", "required" = true, "type" = "string", "example" = "1190"}, - * {"name" = "lang", "in" = "query", "description" = "Language of result", "type" = "string", "enum" = {"de", "en"}, "example" = "de"}, * {"name" = "includeLocal", "in" = "query", "description" = "Local data attributes to include", "type" = "string", "example" = "BaseOrganization.code"} * } * }