diff --git a/application/views/helpers/FormExtensibleSet.php b/application/views/helpers/FormExtensibleSet.php index 0ba58d63..6768f02e 100644 --- a/application/views/helpers/FormExtensibleSet.php +++ b/application/views/helpers/FormExtensibleSet.php @@ -1,5 +1,7 @@ _getInfo($name, $value, $attribs); extract($info); // name, value, attribs, options, listsep, disable - if (array_key_exists('multiOptions', $attribs)) { $multiOptions = $attribs['multiOptions']; + unset($attribs['multiOptions']); + $validOptions = $this->flattenOptions($multiOptions); } else { $multiOptions = null; } if (array_key_exists('sorted', $attribs)) { $sorted = (bool) $attribs['sorted']; + unset($attribs['sorted']); } else { $sorted = false; } @@ -53,23 +57,28 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement $elements = array(); $v = $this->view; - $values = array('group a', 'group b'); $name = $v->escape($name); $id = $v->escape($id); + if ($value instanceof ExtensibleSet) { + $value = $value->toPlainObject(); + } + + if (is_array($value)) { + $value = array_filter($value, 'strlen'); + } + + $cnt = 0; $total = 0; if (is_array($value)) { $total = count($value); foreach ($value as $val) { - if (! strlen($val)) { - continue; - } if ($multiOptions !== null) { - if (array_key_exists($val, $multiOptions)) { - unset($multiOptions[$val]); + if (in_array($val, $validOptions)) { + $this->removeOption($multiOptions, $val); } else { continue; // Value no longer valid } @@ -138,6 +147,39 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement . "\n"; } + private function flattenOptions($options) + { + $flat = array(); + + foreach ($options as $key => $option) { + if (is_array($option)) { + foreach ($option as $k => $o) { + $flat[] = $k; + } + } else { + $flat[] = $key; + } + } + + return $flat; + } + + private function removeOption(& $options, $option) + { + foreach ($options as $key => $value) { + if (is_array($value)) { + if ($this->removeOption($value, $option)) { + return true; + } + } elseif ($key === $option) { + unset($options[$key]); + return true; + } + } + + return false; + } + private function suffix($cnt) { if ($cnt === 0) { diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 3ca3699d..a05fca21 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -261,6 +261,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return null; } + if ($this->propertyIsRelatedSet($key)) { + return $this->getRelatedSet($key)->toPlainObject(); + } + return parent::get($key); }