addTitleTab($this->translate('Custom Variables')); $db = Db::fromResourceName( Config::module('director')->get('db', 'resource') )->getDbAdapter(); $query = $db->select() ->from(['dp' => 'director_property'], []) ->joinLeft(['ihp' => 'icinga_host_property'], 'ihp.property_uuid = dp.uuid', []) ->joinLeft(['isp' => 'icinga_service_property'], 'isp.property_uuid = dp.uuid', []) ->joinLeft(['iup' => 'icinga_user_property'], 'isp.property_uuid = dp.uuid', []) ->joinLeft(['icp' => 'icinga_command_property'], 'isp.property_uuid = dp.uuid', []) ->joinLeft(['inp' => 'icinga_notification_property'], 'isp.property_uuid = dp.uuid', []) ->columns([ 'key_name', 'uuid', 'parent_uuid', 'value_type', 'label', 'description', 'used_count' => 'COUNT(ihp.property_uuid) + COUNT(isp.property_uuid)' . ' + COUNT(iup.property_uuid) + COUNT(icp.property_uuid) + COUNT(inp.property_uuid)' ]) ->where('parent_uuid IS NULL') ->group('dp.uuid') ->order('key_name'); $properties = new CustomVarFieldsTable($db->fetchAll($query)); $this->addControl(Html::tag('div', ['class' => 'custom-variable-form'], [ (new ButtonLink( [Text::create($this->translate('Create Custom Variable'))], Url::fromPath('director/variables/add'), null, [ 'class' => 'control-button' ] ))->setBaseTarget('_next') ])); $this->addContent($properties); } public function addAction() { $this->addTitleTab($this->translate('Create Custom Variable')); $db = Db::fromResourceName( Config::module('director')->get('db', 'resource') ); $propertyForm = (new CustomVariableForm($db)) ->on(CustomVariableForm::ON_SUBMIT, function (CustomVariableForm $form) { Notification::success(sprintf( $this->translate('Property "%s" has successfully been added'), $form->getValue('key_name') )); $this->redirectNow(Url::fromPath('director/customvar', ['uuid' => $form->getUUid()->toString()])); }) ->handleRequest($this->getServerRequest()); $this->addContent($propertyForm); } }