2014-06-06 07:58:14 -04:00
|
|
|
<?php
|
2016-02-08 09:41:00 -05:00
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-06-06 07:58:14 -04:00
|
|
|
|
|
|
|
|
namespace Icinga\Data\Tree;
|
|
|
|
|
|
2015-02-06 11:32:51 -05:00
|
|
|
use Icinga\Data\Identifiable;
|
2014-06-06 07:58:14 -04:00
|
|
|
|
2015-02-10 11:01:32 -05:00
|
|
|
class TreeNode implements Identifiable
|
2014-06-06 07:58:14 -04:00
|
|
|
{
|
2015-02-06 11:20:23 -05:00
|
|
|
/**
|
|
|
|
|
* The node's ID
|
|
|
|
|
*
|
2015-03-12 08:39:17 -04:00
|
|
|
* @var mixed
|
2015-02-06 11:20:23 -05:00
|
|
|
*/
|
|
|
|
|
protected $id;
|
|
|
|
|
|
2014-06-13 11:22:43 -04:00
|
|
|
/**
|
|
|
|
|
* The node's value
|
|
|
|
|
*
|
|
|
|
|
* @var mixed
|
|
|
|
|
*/
|
2014-06-06 07:58:14 -04:00
|
|
|
protected $value;
|
|
|
|
|
|
2014-06-13 11:22:43 -04:00
|
|
|
/**
|
2015-02-06 11:20:23 -05:00
|
|
|
* The node's children
|
|
|
|
|
*
|
2015-03-12 08:39:17 -04:00
|
|
|
* @var array
|
2015-02-06 11:20:23 -05:00
|
|
|
*/
|
|
|
|
|
protected $children = array();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the node's ID
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $id ID of the node
|
2014-06-13 11:22:43 -04:00
|
|
|
*
|
2015-02-06 11:20:23 -05:00
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setId($id)
|
|
|
|
|
{
|
|
|
|
|
$this->id = $id;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* (non-PHPDoc)
|
|
|
|
|
* @see Identifiable::getId() For the method documentation.
|
2014-06-13 11:22:43 -04:00
|
|
|
*/
|
2015-02-06 11:20:23 -05:00
|
|
|
public function getId()
|
|
|
|
|
{
|
|
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the node's value
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setValue($value)
|
2014-06-06 07:58:14 -04:00
|
|
|
{
|
|
|
|
|
$this->value = $value;
|
2015-02-06 11:20:23 -05:00
|
|
|
return $this;
|
2014-06-06 07:58:14 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-13 11:22:43 -04:00
|
|
|
/**
|
|
|
|
|
* Get the node's value
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2014-06-06 07:58:14 -04:00
|
|
|
public function getValue()
|
|
|
|
|
{
|
|
|
|
|
return $this->value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 11:22:43 -04:00
|
|
|
/**
|
2015-02-06 11:20:23 -05:00
|
|
|
* Append a child node as the last child of this node
|
2014-06-13 11:22:43 -04:00
|
|
|
*
|
2015-02-06 11:27:14 -05:00
|
|
|
* @param TreeNode $child The child to append
|
2014-06-13 11:22:43 -04:00
|
|
|
*
|
2015-02-06 11:20:23 -05:00
|
|
|
* @return $this
|
2014-06-13 11:22:43 -04:00
|
|
|
*/
|
2015-02-06 11:27:14 -05:00
|
|
|
public function appendChild(TreeNode $child)
|
2014-06-06 07:58:14 -04:00
|
|
|
{
|
2015-02-06 11:20:23 -05:00
|
|
|
$this->children[] = $child;
|
|
|
|
|
return $this;
|
2014-06-06 07:58:14 -04:00
|
|
|
}
|
|
|
|
|
|
2015-02-06 11:20:23 -05:00
|
|
|
|
2014-06-13 11:22:43 -04:00
|
|
|
/**
|
2015-02-06 11:20:23 -05:00
|
|
|
* Get whether the node has children
|
2014-06-13 11:22:43 -04:00
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2014-06-06 07:58:14 -04:00
|
|
|
public function hasChildren()
|
|
|
|
|
{
|
2015-02-06 11:20:23 -05:00
|
|
|
return ! empty($this->children);
|
2014-06-06 07:58:14 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-13 11:22:43 -04:00
|
|
|
/**
|
2015-02-06 11:20:23 -05:00
|
|
|
* Get the node's children
|
2014-06-13 11:22:43 -04:00
|
|
|
*
|
2015-02-06 11:20:23 -05:00
|
|
|
* @return array
|
2014-06-13 11:22:43 -04:00
|
|
|
*/
|
2014-06-06 07:58:14 -04:00
|
|
|
public function getChildren()
|
|
|
|
|
{
|
2015-02-06 11:20:23 -05:00
|
|
|
return $this->children;
|
|
|
|
|
}
|
2014-06-06 07:58:14 -04:00
|
|
|
}
|