Skip to content

Commit

Permalink
Merge tag 'v0.3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Dunogier committed Jan 17, 2019
2 parents 57a881e + 3bda7e0 commit afc5898
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
43 changes: 30 additions & 13 deletions src/GraphQL/InputMapper/SearchQueryMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ public function mapInputToQuery(array $inputArray)
$criteria[] = new Query\Criterion\FullText($inputArray['Text']);
}

if (isset($inputArray['Field'])) {
$args = $inputArray['Field'];
foreach (['in', 'eq', 'like', 'contains', 'between', 'lt', 'lte', 'gt', 'gte'] as $opString) {
if (isset($args[$opString])) {
$value = $args[$opString];
$operator = constant(Query\Criterion\Operator::class . '::' . strtoupper($opString));
}
if (isset($inputArray['Field']))
{
if (isset($inputArray['Field']['target'])) {
$criteria[] = $this->mapInputToFieldCriterion($inputArray['Field']);
} else {
$criteria = array_merge(
$criteria,
array_map(
function($input) {
return $this->mapInputToFieldCriterion($input);
},
$inputArray['Field']
)
);
}

if (!isset($operator) || !isset($value)) {
throw new InvalidArgumentException("Unspecified operator");
}

$criteria[] = new Query\Criterion\Field($args['target'], $operator, $value);
}

$criteria = array_merge($criteria, $this->mapDateMetadata($inputArray, 'Modified'));
Expand Down Expand Up @@ -131,4 +132,20 @@ private function mapDateMetadata(array $queryArg = [], $dateMetadata)

return $criteria;
}

private function mapInputToFieldCriterion($input)
{
$operators = ['in', 'eq', 'like', 'contains', 'between', 'lt', 'lte', 'gt', 'gte'];
foreach ($operators as $opString) {
if (isset($input[$opString])) {
$value = $input[$opString];
$operator = constant('eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator::' . strtoupper($opString));
}
}

if (!isset($operator)) {
throw new InvalidArgumentException("Unspecified operator");
}

return new Query\Criterion\Field($input['target'], $operator, $value); }
}
2 changes: 1 addition & 1 deletion src/Resources/config/graphql/Search.types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ContentSearchQuery:
type: "[Int]"
description: "Filter content based on its parent location id"
Field:
type: "FieldCriterionInput"
type: "[FieldCriterionInput]"
description: "Field filter"

FieldCriterionInput:
Expand Down

0 comments on commit afc5898

Please sign in to comment.