/**
  * @param ValuesGroup $valuesGroup
  *
  * @return string
  */
 public function getGroupQuery(ValuesGroup $valuesGroup)
 {
     $query = [];
     foreach ($valuesGroup->getFields() as $fieldName => $values) {
         if (!isset($this->fields[$fieldName])) {
             continue;
         }
         $groupSql = [];
         $inclusiveSqlGroup = [];
         $exclusiveSqlGroup = [];
         if (is_array($this->fields[$fieldName])) {
             foreach ($this->fields[$fieldName] as $n) {
                 $this->processFieldValues($values, $n, $inclusiveSqlGroup, $exclusiveSqlGroup);
             }
         } else {
             $this->processFieldValues($values, $fieldName, $inclusiveSqlGroup, $exclusiveSqlGroup);
         }
         $groupSql[] = self::implodeWithValue(' OR ', $inclusiveSqlGroup, ['(', ')']);
         $groupSql[] = self::implodeWithValue(' AND ', $exclusiveSqlGroup, ['(', ')']);
         $query[] = self::implodeWithValue(' AND ', $groupSql, ['(', ')', true]);
     }
     $finalQuery = [];
     // Wrap all the fields as a group
     $finalQuery[] = self::implodeWithValue(' ' . strtoupper($valuesGroup->getGroupLogical()) . ' ', $query, ['(', ')', true]);
     $this->processGroups($valuesGroup->getGroups(), $finalQuery);
     return (string) self::implodeWithValue(' AND ', $finalQuery, ['(', ')']);
 }
 /**
  * @param ValuesGroup $valuesGroup
  * @param FieldSet    $fieldSet
  */
 private function validateValuesGroup(ValuesGroup $valuesGroup, FieldSet $fieldSet)
 {
     foreach ($valuesGroup->getGroups() as $i => $group) {
         $this->validateValuesGroup($group, $fieldSet);
     }
     foreach ($valuesGroup->getFields() as $fieldName => $values) {
         if (!$fieldSet->has($fieldName)) {
             $valuesGroup->removeField($fieldName);
             continue;
         }
         $config = $fieldSet->get($fieldName);
         $constraints = $config->getOption('constraints', []);
         // Don't validate values without constraints
         if (!$constraints) {
             continue;
         }
         $groups = self::getValidationGroups($config);
         $this->validateValuesBag($values, $constraints, $groups);
     }
 }