From e9d9a435b91b866fa85bc52878758454c3a17bae Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 4 Aug 2015 19:26:53 +0200 Subject: [PATCH] IcingaObject: add more class loading helpers --- library/Director/Objects/IcingaObject.php | 28 ++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index a30d7954..18222044 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -684,11 +684,33 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer } } - public static function loadByType($type, $id, Db $connection) + protected static function classByType($type) { - $class = 'Icinga\\Module\\Director\\Objects\\Icinga' . ucfirst($type); + if (strpos($type, 'data') === false) { + $prefix = 'Icinga'; + } else { + $prefix = 'Director'; + } + return 'Icinga\\Module\\Director\\Objects\\' . $prefix . ucfirst($type); + } - return $class::load($id, $connection); + public static function createByType($type, $properties = array(), Db $db = null) + { + $class = self::classByType($type); + return $class::create($properties, $db); + } + + public static function loadByType($type, $id, Db $db) + { + $class = self::classByType($type); + return $class::load($id, $db); + } + + public static function loadAllByType($type, Db $db, $query = null, $keyColumn = 'object_name') + { + if ($type === 'datalistEntry') $keyColumn = 'entry_name'; + $class = self::classByType($type); + return $class::loadAll($db, $query, $keyColumn); } public function __toString()