Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function add(FieldSet $fieldSet)
 {
     $name = $fieldSet->getSetName();
     if (isset($this->fieldSets[$name])) {
         throw new InvalidArgumentException(sprintf('Unable to overwrite already registered FieldSet "%s".', $name));
     }
     if (!$fieldSet->isConfigLocked()) {
         throw new InvalidArgumentException(sprintf('Unable to register unlocked FieldSet "%s".', $name));
     }
     $this->fieldSets[$name] = $fieldSet;
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function add(FieldSet $fieldSet)
 {
     $name = $fieldSet->getSetName();
     if (isset($this->serviceIds[$name])) {
         throw new InvalidArgumentException(sprintf('Unable to overwrite already registered FieldSet "%s".', $name));
     }
     if (!$fieldSet->isConfigLocked()) {
         throw new InvalidArgumentException(sprintf('Unable to register none configuration-locked FieldSet "%s".', $name));
     }
     $serviceId = 'rollerworks_search.fieldset.late_registering.' . $name;
     $this->serviceIds[$name] = $serviceId;
     $this->container->set($serviceId, $fieldSet);
     return $this;
 }
Ejemplo 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);
     }
 }
Ejemplo n.º 6
0
 /**
  * Constructor.
  *
  * @param string                     $name
  * @param ResolvedFieldTypeInterface $type
  * @param array                      $options
  *
  * @throws \InvalidArgumentException When the name is invalid
  */
 public function __construct($name, ResolvedFieldTypeInterface $type, array $options = [])
 {
     FieldSet::validateName($name);
     if ('' === $name) {
         throw new \InvalidArgumentException(sprintf('The name "%s" contains illegal characters. Names should start with a letter, digit or underscore ' . 'and only contain letters, digits, numbers, underscores ("_") and hyphens ("-").', $name));
     }
     $this->name = $name;
     $this->type = $type;
     $this->options = $options;
     $this->locked = false;
 }
Ejemplo 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;
 }
 private function processFields()
 {
     $fields = [];
     foreach ($this->fields as $fieldName => $field) {
         $fields[$fieldName] = new QueryField($this->fieldSet->get($fieldName), $field['db_type'], $field['alias'], $field['column'], isset($this->fieldConversions[$fieldName]) ? $this->fieldConversions[$fieldName] : null, isset($this->valueConversions[$fieldName]) ? $this->valueConversions[$fieldName] : null);
     }
     foreach ($this->combinedFields as $fieldName => $subFieldsConfig) {
         $subsFieldNames = [];
         foreach ($subFieldsConfig as $n => $field) {
             $fieldNameN = $fieldName . '#' . $n;
             $subsFieldNames[] = $fieldNameN;
             $fields[$fieldNameN] = new QueryField($field['field'], $field['db_type'], $field['alias'], $field['column'], isset($this->fieldConversions[$fieldName]) ? $this->fieldConversions[$fieldName] : null, isset($this->valueConversions[$fieldName]) ? $this->valueConversions[$fieldName] : null);
         }
         $fields[$fieldName] = $subsFieldNames;
     }
     return $fields;
 }
Ejemplo n.º 9
0
 /**
  * Constructor.
  *
  * @param string $name
  */
 public function __construct($name)
 {
     \Rollerworks\Component\Search\FieldSet::validateName($name);
     $this->name = $name;
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function getFieldSet()
 {
     if ($this->locked) {
         throw new BadMethodCallException('FieldSetBuilder methods cannot be accessed anymore once the builder is turned into a FieldSet instance.');
     }
     foreach ($this->unresolvedFields as $name => $field) {
         $this->fields[$name] = $this->searchFactory->createField($name, $field['type'], $field['options']);
         unset($this->unresolvedFields[$name]);
     }
     $fieldSet = new FieldSet($this->name);
     foreach ($this->fields as $name => $field) {
         $fieldSet->set($name, $field);
     }
     $this->locked = true;
     return $fieldSet;
 }