From dde55848cafff3bd4bc75033f5361c8bf6eefedd Mon Sep 17 00:00:00 2001 From: nnatter Date: Tue, 31 Mar 2020 14:49:04 +0200 Subject: [PATCH] Add includedFields parameter in DoctrineListRepresentationFactoryInterface (#3) --- ListRepresentation/DoctrineListRepresentationFactory.php | 8 +++++++- .../DoctrineListRepresentationFactoryInterface.php | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ListRepresentation/DoctrineListRepresentationFactory.php b/ListRepresentation/DoctrineListRepresentationFactory.php index 8b729b1..55dd3c7 100644 --- a/ListRepresentation/DoctrineListRepresentationFactory.php +++ b/ListRepresentation/DoctrineListRepresentationFactory.php @@ -48,11 +48,13 @@ public function __construct( /** * @param mixed[] $filters * @param mixed[] $parameters + * @param string[] $includedFields */ public function createDoctrineListRepresentation( string $resourceKey, array $filters = [], - array $parameters = [] + array $parameters = [], + array $includedFields = [] ): PaginatedRepresentation { /** @var DoctrineFieldDescriptor[] $fieldDescriptors */ $fieldDescriptors = $this->fieldDescriptorFactory->getFieldDescriptors($resourceKey); @@ -68,6 +70,10 @@ public function createDoctrineListRepresentation( $listBuilder->where($fieldDescriptors[$key], $value); } + foreach ($includedFields as $field) { + $listBuilder->addSelectField($fieldDescriptors[$field]); + } + $items = $listBuilder->execute(); // sort the items to reflect the order of the given ids if the list was requested to include specific ids diff --git a/ListRepresentation/DoctrineListRepresentationFactoryInterface.php b/ListRepresentation/DoctrineListRepresentationFactoryInterface.php index 9526a48..67f51d0 100644 --- a/ListRepresentation/DoctrineListRepresentationFactoryInterface.php +++ b/ListRepresentation/DoctrineListRepresentationFactoryInterface.php @@ -11,10 +11,12 @@ interface DoctrineListRepresentationFactoryInterface /** * @param mixed[] $filters * @param mixed[] $parameters + * @param string[] $includedFields */ public function createDoctrineListRepresentation( string $resourceKey, array $filters = [], - array $parameters = [] + array $parameters = [], + array $includedFields = [] ): PaginatedRepresentation; }