[icinga-checkins] icinga.org: icingaweb2-module-director/feature/service-set-12891: IcingaObjectFieldLoader: allow to combine objects

git at icinga.org git at icinga.org
Thu Oct 20 09:26:58 CEST 2016


Module: icingaweb2-module-director
Branch: feature/service-set-12891
Commit: 476916b609e10ed2aa5a856e6c7c9452a1567525
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=476916b609e10ed2aa5a856e6c7c9452a1567525

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Oct 20 04:27:43 2016 +0000

IcingaObjectFieldLoader: allow to combine objects

---

 .../Director/Web/Form/IcingaObjectFieldLoader.php  |   25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/library/Director/Web/Form/IcingaObjectFieldLoader.php b/library/Director/Web/Form/IcingaObjectFieldLoader.php
index 1f9e69d..acf860e 100644
--- a/library/Director/Web/Form/IcingaObjectFieldLoader.php
+++ b/library/Director/Web/Form/IcingaObjectFieldLoader.php
@@ -25,13 +25,36 @@ class IcingaObjectFieldLoader
 
     public function addFieldsToForm(QuickForm $form)
     {
-        if ($this->object->supportsFields()) {
+        if ($this->fields || $this->object->supportsFields()) {
             $this->attachFieldsToForm($form);
         }
 
         return $this;
     }
 
+    public function loadFieldsForMultipleObjects($objects)
+    {
+        $fields = array();
+        foreach ($objects as $object) {
+            foreach ($this->prepareObjectFields($object) as $varname => $field) {
+                $varname = $field->varname;
+                if (array_key_exists($varname, $fields)) {
+                    if ($field->datatype !== $fields[$varname]->datatype) {
+                        unset($fields[$varname]);
+                    }
+
+                    continue;
+                }
+
+                $fields[$field->varname] = $field;
+            }
+        }
+
+        $this->fields = $fields;
+
+        return $this;
+    }
+
     /**
      * Set a list of values
      *



More information about the icinga-checkins mailing list