mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 23:00:16 -05:00
BpNode: rename child_nodes to childNode...
...and move method related to children from base Node
This commit is contained in:
parent
cdbd28b25b
commit
b8df6a8823
2 changed files with 39 additions and 21 deletions
|
|
@ -3,7 +3,6 @@
|
|||
namespace Icinga\Module\Businessprocess;
|
||||
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
class BpNode extends Node
|
||||
{
|
||||
|
|
@ -14,8 +13,12 @@ class BpNode extends Node
|
|||
protected $url;
|
||||
protected $info_command;
|
||||
protected $display = 0;
|
||||
|
||||
/** @var Node[] */
|
||||
protected $children;
|
||||
protected $child_names = array();
|
||||
|
||||
/** @var array */
|
||||
protected $childNames = array();
|
||||
protected $alias;
|
||||
protected $counters;
|
||||
protected $missing = null;
|
||||
|
|
@ -89,6 +92,30 @@ class BpNode extends Node
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node $node
|
||||
* @return $this
|
||||
* @throws ConfigurationError
|
||||
*/
|
||||
public function addChild(Node $node)
|
||||
{
|
||||
if ($this->children === null) {
|
||||
$this->getChildren();
|
||||
}
|
||||
|
||||
$name = (string) $node;
|
||||
if (array_key_exists($name, $this->children)) {
|
||||
throw new ConfigurationError(
|
||||
'Node "%s" has been defined more than once',
|
||||
$name
|
||||
);
|
||||
}
|
||||
$this->children[$name] = $node;
|
||||
$this->children[] = $name;
|
||||
$node->addParent($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProblematicChildren()
|
||||
{
|
||||
$problems = array();
|
||||
|
|
@ -304,26 +331,32 @@ class BpNode extends Node
|
|||
public function setChildNames($names)
|
||||
{
|
||||
sort($names);
|
||||
$this->child_names = $names;
|
||||
$this->childNames = $names;
|
||||
$this->children = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasChildren($filter = null)
|
||||
{
|
||||
return !empty($this->childNames);
|
||||
}
|
||||
|
||||
public function getChildNames()
|
||||
{
|
||||
return $this->child_names;
|
||||
return $this->childNames;
|
||||
}
|
||||
|
||||
public function getChildren($filter = null)
|
||||
{
|
||||
if ($this->children === null) {
|
||||
$this->children = array();
|
||||
natsort($this->child_names);
|
||||
foreach ($this->child_names as $name) {
|
||||
natsort($this->childNames);
|
||||
foreach ($this->childNames as $name) {
|
||||
$this->children[$name] = $this->bp->getNode($name);
|
||||
$this->children[$name]->addParent($this);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,21 +142,6 @@ abstract class Node
|
|||
return false;
|
||||
}
|
||||
|
||||
public function addChild(Node $node)
|
||||
{
|
||||
if (array_key_exists((string) $node, $this->children)) {
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
'Node "%s" has been defined more than once',
|
||||
$node
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->childs[(string) $node] = $node;
|
||||
$node->addParent($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setState($state)
|
||||
{
|
||||
$this->state = (int) $state;
|
||||
|
|
|
|||
Loading…
Reference in a new issue