From d5c20e6e5367f4d56613e08de2527d51d56498e9 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 2 Dec 2015 03:08:57 +0100 Subject: [PATCH] IcingaObject: first simple toJson support --- library/Director/Objects/IcingaObject.php | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 4185e40a..2ae48cba 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -811,6 +811,33 @@ return ''; return $class::loadAll($db, $query, $keyColumn); } + public function toJson($resolved = false) + { + $props = array(); + foreach ($this->getProperties() as $k => $v) { + if ($v !== null) { + $props[$k] = $v; + } + } + + if ($this->supportsGroups()) { + // TODO: resolve + $props['groups'] = $this->groups()->listGroupNames(); + } + if ($this->supportsCustomVars()) { + if ($resolved) { + $props['vars'] = $this->getVars(); + } else { + $props['vars'] = $this->getResolvedVars(); + } + } + if ($this->supportsImports()) { + $props['imports'] = $this->imports()->listImportNames(); + } + + return json_encode($props); + } + public function __toString() { try {