Esempio n. 1
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. 2
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);
 }