Example #1
0
 private function removeDuplicatesInGroup(ValuesGroup $valuesGroup, FieldSet $fieldSet)
 {
     foreach ($valuesGroup->getFields() as $fieldName => $values) {
         $this->removeDuplicatesInValuesBag($fieldSet->get($fieldName), $values);
     }
     // Traverse the subgroups.
     foreach ($valuesGroup->getGroups() as $group) {
         $this->removeDuplicatesInGroup($group, $fieldSet);
     }
 }
Example #2
0
 /**
  * @param ValuesGroup $valuesGroup
  * @param FieldSet    $fieldSet
  */
 private function normalizeRangesInGroup(ValuesGroup $valuesGroup, FieldSet $fieldSet)
 {
     foreach ($valuesGroup->getFields() as $fieldName => $values) {
         $config = $fieldSet->get($fieldName);
         if ($values->has(Range::class) || $values->has(ExcludedRange::class)) {
             $this->normalizeRangesInValuesBag($config, $values);
         }
     }
     foreach ($valuesGroup->getGroups() as $group) {
         $this->normalizeRangesInGroup($group, $fieldSet);
     }
 }
Example #3
0
 /**
  * @param ValuesGroup $valuesGroup
  * @param FieldSet    $fieldSet
  */
 private function optimizeValuesInGroup(ValuesGroup $valuesGroup, FieldSet $fieldSet)
 {
     foreach ($valuesGroup->getFields() as $fieldName => $values) {
         if (!isset($this->comparators[$fieldName])) {
             continue;
         }
         $config = $fieldSet->get($fieldName);
         if ($values->hasSimpleValues() || $values->hasExcludedSimpleValues()) {
             $this->optimizeValuesInValuesBag($config, $this->comparators[$fieldName], $values);
         }
     }
     // Traverse the subgroups.
     foreach ($valuesGroup->getGroups() as $group) {
         $this->optimizeValuesInGroup($group, $fieldSet);
     }
 }
Example #4
0
 /**
  * @param ValuesGroup $valuesGroup
  * @param FieldSet    $fieldSet
  * @param bool        $isRoot
  *
  * @return array
  */
 protected function exportGroup(ValuesGroup $valuesGroup, FieldSet $fieldSet, $isRoot = false)
 {
     $result = [];
     $fields = $valuesGroup->getFields();
     foreach ($fields as $name => $values) {
         if (0 === $values->count()) {
             continue;
         }
         $exportedValue = $this->exportValues($values, $fieldSet->get($name));
         // Only export fields with actual values.
         if (count($exportedValue) > 0) {
             $fieldLabel = $this->labelResolver->resolveFieldLabel($fieldSet, $name);
             $result['fields'][$fieldLabel] = $exportedValue;
         }
     }
     foreach ($valuesGroup->getGroups() as $group) {
         $result['groups'][] = $this->exportGroup($group, $fieldSet, false);
     }
     if (isset($result['fields']) && ValuesGroup::GROUP_LOGICAL_OR === $valuesGroup->getGroupLogical()) {
         $result['logical-case'] = 'OR';
     }
     return $result;
 }
 /**
  * @param ValuesGroup $valuesGroup
  * @param FieldSet    $fieldSet
  * @param bool        $isRoot
  *
  * @return string
  */
 protected function exportGroup(ValuesGroup $valuesGroup, FieldSet $fieldSet, $isRoot = false)
 {
     $result = '';
     $exportedGroups = '';
     if ($isRoot && $valuesGroup->countValues() > 0 && ValuesGroup::GROUP_LOGICAL_OR === $valuesGroup->getGroupLogical()) {
         $result .= '*';
     }
     foreach ($valuesGroup->getFields() as $name => $values) {
         if (0 === $values->count()) {
             continue;
         }
         $result .= $this->labelResolver->resolveFieldLabel($fieldSet, $name);
         $result .= ': ' . $this->exportValues($values, $fieldSet->get($name)) . '; ';
     }
     foreach ($valuesGroup->getGroups() as $group) {
         $exportedGroup = '(' . trim($this->exportGroup($group, $fieldSet), ' ;') . '); ';
         if ('(); ' !== $exportedGroup && ValuesGroup::GROUP_LOGICAL_OR === $group->getGroupLogical()) {
             $exportedGroups .= '*';
         }
         $exportedGroups .= $exportedGroup;
     }
     $result .= $exportedGroups;
     return trim($result);
 }
Example #6
0
 /**
  * @param \DOMNode    $parent
  * @param ValuesGroup $valuesGroup
  * @param FieldSet    $fieldSet
  */
 private function exportGroupNode(\DOMNode $parent, ValuesGroup $valuesGroup, FieldSet $fieldSet)
 {
     $fields = $valuesGroup->getFields();
     if ($valuesGroup->countValues() > 0) {
         $fieldsNode = $this->document->createElement('fields');
         foreach ($fields as $name => $values) {
             if (!$values->count()) {
                 continue;
             }
             $fieldLabel = $this->labelResolver->resolveFieldLabel($fieldSet, $name);
             $fieldNode = $this->document->createElement('field');
             $fieldNode->setAttribute('name', $fieldLabel);
             $this->exportValuesToNode($values, $fieldNode, $fieldSet->get($name));
             $fieldsNode->appendChild($fieldNode);
         }
         $parent->appendChild($fieldsNode);
     }
     if ($valuesGroup->hasGroups()) {
         $groupsNode = $this->document->createElement('groups');
         foreach ($valuesGroup->getGroups() as $group) {
             $groupNode = $this->document->createElement('group');
             $groupNode->setAttribute('logical', $group->getGroupLogical());
             $this->exportGroupNode($groupNode, $group, $fieldSet);
             $groupsNode->appendChild($groupNode);
         }
         $parent->appendChild($groupsNode);
     }
 }