File: D:/HostingSpaces/SBogers70/inter-mill.com/workbench/komma/kms/src/Komma/Kms/Core/Tree/TreeNode.php
<?php
namespace Komma\Kms\Core\Tree;
class TreeNode
{
/**
* @var object
*/
public $node;
/**
* @var array
*/
protected $children = [];
/**
* @var TreeNode or null
*/
protected $parent;
/**
* @param object $attributes
* @param object $parent
*/
public function __construct($node, &$parent)
{
$this->node = $node;
$this->parent = $parent;
}
public function addChildNode(TreeNode &$child)
{
return $this->children[] = $child;
}
public function getParent()
{
return $this->parent;
}
public function hasChildren()
{
return count($this->children) > 0 ? true : false;
}
public function getChildren()
{
return $this->children;
}
public function setChildren($children)
{
$this->children = $children;
}
public function getDepth()
{
if($this->parent){
return $this->parent->getDepth() + 1;
}
return 0;
}
public function getPath()
{
if($this->parent != null){
$array = $this->parent->getPath();
return array_merge($array, [$this->node->id]);
}
return [];
}
public function getSlugPath()
{
if($this->parent != null){
$array = $this->parent->getSlugPath();
$value = isset($this->node->slug) ? $this->node->slug : $this->node->id;
return array_merge($array, [$value]);
}
return [];
}
}