mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-23 16:19:42 -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;
|
namespace Icinga\Module\Businessprocess;
|
||||||
|
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\ProgrammingError;
|
|
||||||
|
|
||||||
class BpNode extends Node
|
class BpNode extends Node
|
||||||
{
|
{
|
||||||
|
|
@ -14,8 +13,12 @@ class BpNode extends Node
|
||||||
protected $url;
|
protected $url;
|
||||||
protected $info_command;
|
protected $info_command;
|
||||||
protected $display = 0;
|
protected $display = 0;
|
||||||
|
|
||||||
|
/** @var Node[] */
|
||||||
protected $children;
|
protected $children;
|
||||||
protected $child_names = array();
|
|
||||||
|
/** @var array */
|
||||||
|
protected $childNames = array();
|
||||||
protected $alias;
|
protected $alias;
|
||||||
protected $counters;
|
protected $counters;
|
||||||
protected $missing = null;
|
protected $missing = null;
|
||||||
|
|
@ -89,6 +92,30 @@ class BpNode extends Node
|
||||||
return false;
|
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()
|
public function getProblematicChildren()
|
||||||
{
|
{
|
||||||
$problems = array();
|
$problems = array();
|
||||||
|
|
@ -304,26 +331,32 @@ class BpNode extends Node
|
||||||
public function setChildNames($names)
|
public function setChildNames($names)
|
||||||
{
|
{
|
||||||
sort($names);
|
sort($names);
|
||||||
$this->child_names = $names;
|
$this->childNames = $names;
|
||||||
$this->children = null;
|
$this->children = null;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasChildren($filter = null)
|
||||||
|
{
|
||||||
|
return !empty($this->childNames);
|
||||||
|
}
|
||||||
|
|
||||||
public function getChildNames()
|
public function getChildNames()
|
||||||
{
|
{
|
||||||
return $this->child_names;
|
return $this->childNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getChildren($filter = null)
|
public function getChildren($filter = null)
|
||||||
{
|
{
|
||||||
if ($this->children === null) {
|
if ($this->children === null) {
|
||||||
$this->children = array();
|
$this->children = array();
|
||||||
natsort($this->child_names);
|
natsort($this->childNames);
|
||||||
foreach ($this->child_names as $name) {
|
foreach ($this->childNames as $name) {
|
||||||
$this->children[$name] = $this->bp->getNode($name);
|
$this->children[$name] = $this->bp->getNode($name);
|
||||||
$this->children[$name]->addParent($this);
|
$this->children[$name]->addParent($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->children;
|
return $this->children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,21 +142,6 @@ abstract class Node
|
||||||
return false;
|
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)
|
public function setState($state)
|
||||||
{
|
{
|
||||||
$this->state = (int) $state;
|
$this->state = (int) $state;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue