From 46c94ef68f1b6158b4b69aa01cbca428e43107d3 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 7 Dec 2016 23:12:11 +0100 Subject: [PATCH] AddNodeForm: use dedicated enums for different... ...host lists --- application/forms/AddNodeForm.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/application/forms/AddNodeForm.php b/application/forms/AddNodeForm.php index ecb583c..17be12b 100644 --- a/application/forms/AddNodeForm.php +++ b/application/forms/AddNodeForm.php @@ -169,7 +169,7 @@ class AddNodeForm extends QuickForm 'required' => true, 'ignore' => true, 'class' => 'autosubmit', - 'multiOptions' => $this->optionalEnum($this->enumHostList()), + 'multiOptions' => $this->optionalEnum($this->enumHostForServiceList()), )); } @@ -223,10 +223,10 @@ class AddNodeForm extends QuickForm } /** - * @param BpNode $node + * @param BpNode|null $node * @return $this */ - public function setParentNode(BpNode $node) + public function setParentNode(BpNode $node = null) { $this->parent = $node; return $this; @@ -250,6 +250,18 @@ class AddNodeForm extends QuickForm return $this; } + protected function enumHostForServiceList() + { + $names = $this->backend->select()->from('hostStatus', array( + 'hostname' => 'host_name', + ))->order('host_name')->getQuery()->fetchColumn(); + + // fetchPairs doesn't seem to work when using the same column with + // different aliases twice + + return array_combine((array) $names, (array) $names); + } + protected function enumHostList() { $names = $this->backend->select()->from('hostStatus', array( @@ -258,7 +270,13 @@ class AddNodeForm extends QuickForm // fetchPairs doesn't seem to work when using the same column with // different aliases twice - return array_combine((array) $names, (array) $names); + $res = array(); + $suffix = ';Hoststatus'; + foreach ($names as $name) { + $res[$name . $suffix] = $name; + } + + return $res; } protected function enumServiceList($host)