[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaObject: render related sets

git at icinga.org git at icinga.org
Mon Feb 29 20:39:05 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: 47f20c93a3d4705b0c1cddc6511379e8f40107ca
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=47f20c93a3d4705b0c1cddc6511379e8f40107ca

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Feb 29 18:19:01 2016 +0100

IcingaObject: render related sets

---

 library/Director/Objects/IcingaObject.php |   31 +++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 0d06068..6794ee2 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -43,6 +43,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         // property => PropertyClass
     );
 
+    protected $relatedSets = array(
+        // property => ExtensibleSetClass
+    );
+
     /**
      * Array of interval property names
      *
@@ -79,6 +83,23 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         return array_key_exists($property, $this->intervalProperties);
     }
 
+    public function propertyIsRelatedSet($property)
+    {
+        return array_key_exists($property, $this->relatedSets);
+    }
+
+    protected function getRelatedSetClass($property)
+    {
+        $prefix = '\\Icinga\\Module\\Director\\IcingaConfig\\';
+        return $prefix . $this->relatedSets[$property];
+    }
+
+    protected function getRelatedSet($property)
+    {
+        $class = $this->getRelatedSetClass($property);
+        return $class::forIcingaObject($this, $property);
+    }
+
     public function hasRelation($property)
     {
         return array_key_exists($property, $this->relations);
@@ -935,6 +956,15 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         }
     }
 
+    protected function renderRelatedSets()
+    {
+        $config = '';
+        foreach ($this->relatedSets as $property => $class) {
+            $config .= $this->getRelatedSet($property)->renderAs($property);
+        }
+        return $config;
+    }
+
     protected function renderRelationProperty($propertyName, $id, $renderKey = null)
     {
         return c::renderKeyValue(
@@ -1010,6 +1040,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
             $this->renderProperties(),
             $this->renderRanges(),
             $this->renderArguments(),
+            $this->renderRelatedSets(),
             $this->renderGroups(),
             $this->renderCustomExtensions(),
             $this->renderCustomVars(),



More information about the icinga-checkins mailing list