-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from itk-dev/feature/1339_API_multi_value_filt…
…ering 1339: Added multi-value filtering for Lactions and Organizations
- Loading branch information
Showing
8 changed files
with
119 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Api\Filter\ElasticSearch; | ||
|
||
use ApiPlatform\Elasticsearch\Filter\AbstractFilter; | ||
use ApiPlatform\Metadata\Operation; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
final class IdFilter extends AbstractFilter | ||
{ | ||
public function apply(array $clauseBody, string $resourceClass, ?Operation $operation = null, array $context = []): array | ||
{ | ||
$properties = $this->getProperties($resourceClass); | ||
$terms = []; | ||
|
||
/** @var string $property */ | ||
foreach ($properties as $property) { | ||
if (empty($context['filters'][$property])) { | ||
// If no value or empty value is set, skip it. | ||
continue; | ||
} | ||
$terms[$property] = explode(',', $context['filters'][$property]); | ||
} | ||
|
||
return empty($terms) ? $terms : ['terms' => $terms + ['boost' => 1.0]]; | ||
} | ||
|
||
public function getDescription(string $resourceClass): array | ||
{ | ||
if (!$this->properties) { | ||
return []; | ||
} | ||
|
||
$description = []; | ||
foreach ($this->properties as $filterParameterName => $value) { | ||
$description[$filterParameterName] = [ | ||
'property' => $filterParameterName, | ||
'type' => Type::BUILTIN_TYPE_ARRAY, | ||
'required' => false, | ||
'description' => 'Filter based on given entity ids', | ||
'is_collection' => true, | ||
'openapi' => [ | ||
'allowReserved' => false, | ||
'allowEmptyValue' => true, | ||
'explode' => false, | ||
], | ||
]; | ||
} | ||
|
||
return $description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters