icingaweb2/library/Icinga/Data/Tree/TreeNode.php

110 lines
1.8 KiB
PHP
Raw Normal View History

2014-06-06 13:58:14 +02:00
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
2014-06-06 13:58:14 +02:00
namespace Icinga\Data\Tree;
use Icinga\Data\Identifiable;
2014-06-06 13:58:14 +02:00
class TreeNode implements Identifiable
2014-06-06 13:58:14 +02:00
{
/**
* The node's ID
*
* @var mixed
*/
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
/**
* The node's children
*
* @var array
*/
protected $children = array();
/**
* Set the node's ID
*
* @param mixed $id ID of the node
2014-06-13 17:22:43 +02: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
*/
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;
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
/**
* Append a child node as the last child of this node
2014-06-13 17:22:43 +02:00
*
* @param TreeNode $child The child to append
2014-06-13 17:22:43 +02:00
*
* @return $this
2014-06-13 17:22:43 +02:00
*/
public function appendChild(TreeNode $child)
2014-06-06 13:58:14 +02:00
{
$this->children[] = $child;
return $this;
2014-06-06 13:58:14 +02:00
}
2014-06-13 17:22:43 +02: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()
{
return ! empty($this->children);
2014-06-06 13:58:14 +02:00
}
2014-06-13 17:22:43 +02:00
/**
* Get the node's children
2014-06-13 17:22:43 +02:00
*
* @return array
2014-06-13 17:22:43 +02:00
*/
2014-06-06 13:58:14 +02:00
public function getChildren()
{
return $this->children;
}
2014-06-06 13:58:14 +02:00
}