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