From 7058536530427a78fd39cfade88f8e5c79236348 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 30 Jul 2015 09:09:44 +0200 Subject: [PATCH] IcingaObject: add getFields() lookup method --- library/Director/Objects/IcingaObject.php | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 88541a55..09620d42 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -250,6 +250,39 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $this->getShortTableName() . '_id'; } + public function getFields() + { + $fields = (object) array(); + + if (! $this->supportsFields()) { + return $fields; + } + + $db = $this->getDb(); + + $query = $db->select()->from( + array('df' => 'director_datafield'), + array( + 'datafield_id' => 'f.datafield_id', + 'is_required' => 'f.is_required', + 'varname' => 'df.varname' + ) + )->join( + array('f' => $this->getTableName() . '_field'), + 'df.id = f.datafield_id', + array() + )->where('f.host_id = ?', (int) $this->id) + ->order('df.caption ASC'); + + $res = $db->fetchAll($query); + + foreach ($res as $r) { + $fields->{$r->varname} = $r; + } + + return $fields; + } + public function isTemplate() { return $this->hasProperty('object_type')