diff --git a/library/Director/DataType/DataTypeDirectorObject.php b/library/Director/DataType/DataTypeDirectorObject.php new file mode 100644 index 00000000..faea8f95 --- /dev/null +++ b/library/Director/DataType/DataTypeDirectorObject.php @@ -0,0 +1,78 @@ +getDb()->getDbAdapter(); + + $dummy = IcingaObject::createByType( + $this->getSetting('icinga_object_type') + ); + + $query = $db->select()->from($dummy->getTableName(), array( + 'object_name' => 'object_name', + 'display_name' => 'COALESCE(display_name, object_name)' + ))->where( + 'object_type = ?', + 'object' + ); + + $enum = $db->fetchPairs($query); + + $params = array( + 'required' => true, + 'multiOptions' => array( + null => $form->translate('- please choose -'), + ) + $enum, + ); + + if ($this->getSetting('data_type') === 'array') { + $type = 'extensibleSet'; + $params['sorted'] = true; + } else { + $type = 'select'; + } + + return $form->createElement($type, $name, $params); + } + + public static function addSettingsFormFields(QuickForm $form) + { + $enum = array( + 'host' => $form->translate('Hosts'), + 'hostgroup' => $form->translate('Host groups'), + 'service' => $form->translate('Services'), + 'servicegroup' => $form->translate('Service groups'), + 'user' => $form->translate('Users'), + 'usergroup' => $form->translate('User groups'), + ); + + $form->addElement('select', 'icinga_object_type', array( + 'label' => $form->translate('Object'), + 'description' => $form->translate( + 'Please choose a specific Icinga object type' + ), + 'required' => true, + 'multiOptions' => $form->optionalEnum($enum), + 'sorted' => true, + )); + + $form->addElement('select', 'data_type', array( + 'label' => $form->translate('Target data type'), + 'multiOptions' => $form->optionalEnum(array( + 'string' => $form->translate('String'), + 'array' => $form->translate('Array'), + )), + 'required' => true, + )); + + return $form; + } +} diff --git a/run.php b/run.php index 8534d05e..8eea8693 100644 --- a/run.php +++ b/run.php @@ -15,6 +15,7 @@ $this->provideHook('director/DataType', $prefix . 'DataType\\DataTypeArray'); $this->provideHook('director/DataType', $prefix . 'DataType\\DataTypeBoolean'); $this->provideHook('director/DataType', $prefix . 'DataType\\DataTypeDatalist'); $this->provideHook('director/DataType', $prefix . 'DataType\\DataTypeNumber'); +$this->provideHook('director/DataType', $prefix . 'DataType\\DataTypeDirectorObject'); $this->provideHook('director/DataType', $prefix . 'DataType\\DataTypeSqlQuery'); $this->provideHook('director/DataType', $prefix . 'DataType\\DataTypeString');