/** * Recursively add all subselect properties to their parent. Even when they are member of a subselect themselves. * * @param Legend $legend The legend to add the properties to. * * @param array $subSelectPalettes All subselect palettes. * * @param string $propertyName The name of the property for which all dependant properties shall get added. * * @param string $legendName The name of the legend for which properties shall get retrieved. */ protected function addSubSelectProperties(Legend $legend, $subSelectPalettes, $propertyName, $legendName = '', $insert = 'before', $reference = null) { if (!isset($subSelectPalettes[$propertyName][$legendName])) { return; } $position = null; if ($insert && $reference) { $properties = $legend->getProperties(); if (!empty($properties)) { $property = current($properties); do { if ($property->getName() == $reference) { if ($insert == 'before') { $position = $property; } elseif ($insert == 'after') { $position = next($properties); } break; } } while ($property = next($properties)); } } if ($position === false) { $position = null; } $legend->addProperties($subSelectPalettes[$propertyName][$legendName], $position); foreach ((array) $subSelectPalettes[$propertyName][$legendName] as $property) { /** @var Property $property */ // Add anonymous legends for this property. if (isset($subSelectPalettes[$property->getName()][''])) { $legend->addProperties($subSelectPalettes[$property->getName()]['']); } if (isset($subSelectPalettes[$property->getName()][$legendName])) { $this->addSubSelectProperties($legend, $subSelectPalettes, $property->getName(), $legendName, $insert, $reference); } } }
/** * Create a new legend from a list of properties. * * @param string $name The name of the legend. * * @param array|PropertyInterface $property A list of properties. Can be multiple arrays and arrays of arrays. * * @param PropertyInterface $_ A list of properties. Can be multiple arrays and arrays of arrays. * * @return LegendInterface */ public static function createLegend($name, $property = null, $_ = null) { $legend = new Legend(); $legend->setName($name); $args = func_get_args(); // Drop the name from argument list. array_shift($args); static::fillLegend($legend, $args); return $legend; }
/** * Parse the palettes from the input screen into the data container. * * @param IMetaModelDataDefinition $container The data container. * * @return void */ protected function parsePalettes(IMetaModelDataDefinition $container) { $inputScreen = $this->getInputScreenDetails(); $metaModel = $this->getMetaModel(); if ($container->hasDefinition(PalettesDefinitionInterface::NAME)) { $palettesDefinition = $container->getDefinition(PalettesDefinitionInterface::NAME); } else { $palettesDefinition = new DefaultPalettesDefinition(); $container->setDefinition(PalettesDefinitionInterface::NAME, $palettesDefinition); } $palette = new Palette(); $palette->setName('default')->setCondition(new DefaultPaletteCondition()); $palettesDefinition->addPalette($palette); foreach ($inputScreen->getLegends() as $legendName => $legend) { $paletteLegend = new Legend($legendName); $paletteLegend->setInitialVisibility(isset($legend['visible']) && (bool) $legend['visible']); $palette->addLegend($paletteLegend); $this->translator->setValue($legendName . '_legend', isset($legend['name']) ? $legend['name'] : '', $container->getName()); foreach ($legend['properties'] as $propertyName) { $property = new Property($propertyName); $paletteLegend->addProperty($property); $propInfo = $inputScreen->getProperty($propertyName); $chain = new PropertyConditionChain(); $property->setEditableCondition($chain); $chain->addCondition(new BooleanCondition(!(isset($propInfo['info']['readonly']) && $propInfo['info']['readonly']))); if ($metaModel->hasVariants() && !$metaModel->getAttribute($propertyName)->get('isvariant')) { $chain->addCondition(new PropertyValueCondition('varbase', 1)); } $extra = $propInfo['info']; $chain = new PropertyConditionChain(); $property->setVisibleCondition($chain); $chain->addCondition(new BooleanCondition(!(isset($extra['doNotShow']) && $extra['doNotShow'] || isset($extra['hideInput']) && $extra['hideInput']))); $propertyConditions = $inputScreen->getConditionsFor($propertyName); if ($propertyConditions !== null) { $chain->addCondition($propertyConditions); } // If variants, do show only if allowed. if ($metaModel->hasVariants()) { $chain->addCondition(new IsVariantAttribute()); } } } }