Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FilterGroupFactory.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
18 
23 {
25  private $filterBuilder;
26 
28  private $filterGroupBuilder;
29 
34  public function __construct(
35  \Magento\Framework\Api\FilterBuilder $filterBuilder,
36  \Magento\Framework\Api\Search\FilterGroupBuilder $filterGroupBuilder
37  ) {
38  $this->filterBuilder = $filterBuilder;
39  $this->filterGroupBuilder = $filterGroupBuilder;
40  }
41 
49  public function create(Connective $arguments) : array
50  {
53  $searchCriteriaFilterGroups = [];
54 
55  foreach ($filters->getConditions() as $filter) {
56  if ($filter instanceof Operator) {
57  throw new GraphQlInputException(new Phrase('Can\'t support nested operators'));
58  }
59 
60  if ($filter instanceof Clause) {
61  $searchCriteriaFilterGroups[] = $this->processClause($filter);
62  } elseif ($filter instanceof Connective) {
63  $searchCriteriaFilterGroups[] = $this->processConnective($filter);
64  } else {
65  throw new GraphQlInputException(new Phrase('Nesting "OR" node type not supported'));
66  }
67  }
68 
69  return $searchCriteriaFilterGroups;
70  }
71 
79  private function processConnective(Connective $connective) : FilterGroup
80  {
81  foreach ($connective->getConditions() as $subNode) {
82  if ($subNode instanceof Clause) {
83  $subFilter = $this->filterBuilder
84  ->setField($subNode->getFieldName())
85  ->setValue($subNode->getClauseValue())// Not strictly needed for "null" and "notnull"
86  ->setConditionType($subNode->getClauseType())
87  ->create();
88 
89  $this->filterGroupBuilder->addFilter($subFilter);
90  } elseif ($subNode instanceof Connective) {
91  // This recursive OR processing can be done because AND is not yet supported
92  // we should not be doing this for OR if both AND and OR will be nestedly supported
93  // because it's mathematically incorrect to reduce OR in a boolean operation
94  // you can only do it when you have only OR operation.
95  if (((string)$subNode->getOperator()) == 'OR') {
96  return $this->processConnective($subNode);
97  } else {
98  throw new GraphQlInputException(
99  new Phrase('Sub nesting of %1 is not supported', [$subNode->getOperator()])
100  );
101  }
102  }
103  }
104  return $this->filterGroupBuilder->create();
105  }
106 
113  private function processClause(Clause $clause)
114  {
115  $searchCriteriaFilter = $this->filterBuilder
116  ->setField($clause->getFieldName())
117  ->setValue($clause->getClauseValue())// Not strictly needed for "null" and "notnull"
118  ->setConditionType($clause->getClauseType())
119  ->create();
120 
121  $this->filterGroupBuilder->addFilter($searchCriteriaFilter);
122  return $this->filterGroupBuilder->create();
123  }
124 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Framework\Api\FilterBuilder $filterBuilder, \Magento\Framework\Api\Search\FilterGroupBuilder $filterGroupBuilder)
$filters
Definition: uploader.phtml:11
$arguments