Esempio n. 1
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);
     }
 }
Esempio n. 2
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);
     }
 }
Esempio n. 3
0
 private function processGroups(\SimpleXMLElement $values, ValuesGroup $valuesGroup, $groupIdx, $level)
 {
     $this->validateGroupsCount($groupIdx, $values->groups->children()->count(), $level);
     $index = 0;
     foreach ($values->groups->children() as $element) {
         $subValuesGroup = new ValuesGroup(isset($element['logical']) ? (string) $element['logical'] : ValuesGroup::GROUP_LOGICAL_AND);
         $this->processGroup($element, $subValuesGroup, $index, $level + 1);
         $valuesGroup->addGroup($subValuesGroup);
         ++$index;
     }
 }
Esempio n. 4
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);
     }
 }
Esempio n. 5
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);
     }
 }
 /**
  * Add/expend a field on this ValuesGroup and returns the object instance.
  *
  * The object instance is a ValuesBagBuilder (subset of ValuesBag), which
  * allows to add extra values to the field:
  *
  * ->field('name')
  *   ->addSimpleValue('my value')
  *   ->addSimpleValue('my value 2')
  * ->end() // return back to the ValuesGroup
  *
  * Tip! If the field already exists the existing is expended (values are added).
  * To force an overwrite of the existing field use `->field('name', true)` instead.
  *
  * @param string $name
  * @param bool   $forceNew
  *
  * @return ValuesBagBuilder
  */
 public function field($name, $forceNew = false)
 {
     if (!$forceNew && $this->valuesGroup->hasField($name)) {
         $valuesBag = $this->valuesGroup->getField($name);
     } else {
         $valuesBag = new ValuesBagBuilder($this);
         $this->valuesGroup->addField($name, $valuesBag);
     }
     return $valuesBag;
 }
Esempio n. 7
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;
 }
Esempio n. 8
0
 /**
  * @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);
 }
Esempio n. 9
0
 /**
  * {FieldIdentification ":" FieldValues}*.
  *
  * @param ValuesGroup $valuesGroup
  * @param int         $level
  * @param int         $groupIdx
  * @param bool        $inGroup
  */
 private function fieldValuesPairs(ValuesGroup $valuesGroup, $level = 0, $groupIdx = 0, $inGroup = false)
 {
     $groupCount = 0;
     while (null !== $this->lexer->lookahead) {
         switch ($this->lexer->lookahead['type']) {
             case Lexer::T_OPEN_PARENTHESIS:
             case Lexer::T_MULTIPLY:
                 $groupCount++;
                 $this->validateGroupsCount($groupIdx, $groupCount, $level);
                 $valuesGroup->addGroup($this->fieldGroup($level + 1, $groupCount - 1));
                 break;
             case Lexer::T_IDENTIFIER:
                 $fieldName = $this->getFieldName($this->fieldIdentification());
                 $fieldConfig = $this->config->getFieldSet()->get($fieldName);
                 if ($valuesGroup->hasField($fieldName)) {
                     $this->fieldValues($fieldConfig, $valuesGroup->getField($fieldName), $level, $groupIdx);
                 } else {
                     $valuesGroup->addField($fieldName, $this->fieldValues($fieldConfig, new ValuesBag(), $level, $groupIdx));
                 }
                 break;
             case $inGroup && Lexer::T_CLOSE_PARENTHESIS:
                 // Group closing is handled using the Group() method
                 break 2;
             default:
                 $this->syntaxError(['(', 'FieldIdentification']);
                 break;
         }
     }
 }
Esempio n. 10
0
 private function processGroups(array $groups, ValuesGroup $valuesGroup, $level)
 {
     foreach ($groups as $index => $values) {
         $subValuesGroup = new ValuesGroup(isset($values['logical-case']) ? $values['logical-case'] : ValuesGroup::GROUP_LOGICAL_AND);
         $this->processGroup($values, $subValuesGroup, $index, $level + 1);
         $valuesGroup->addGroup($subValuesGroup);
     }
 }