File: D:/HostingSpaces/SBogers10/deensekroon.komma-mediadesign.nl/wwwroot/App/Tree/TreeNode.php
<?php
namespace App\Tree;
class TreeNode
{
protected $children = [];
protected $data;
public function __construct($data)
{
$this->data = (array) $data;
}
/**
* @param $name
* @return bool
*/
public function __get($name)
{
if( ! isset($this->data[$name])) return false;
return $this->data[$name];
}
/**
* @param $node
*/
public function addChildNode($node)
{
$this->children[$node->id] = $node;
}
/**
* @param $nodeId
* @return mixed
*/
public function childNodeById($nodeId)
{
if( ! isset($this->children[$nodeId])) return false;
return $this->children[$nodeId];
}
/**
* @return bool
*/
public function hasChildren()
{
return ! empty($this->children);
}
/**
* @return bool
*/
public function hasGrandChildren()
{
if( ! $this->hasChildren()) return false;
foreach($this->children as $child)
{
if($child->hasChildren()) return true;
}
return false;
}
/**
* @return bool
*/
public function children()
{
return $this->children;
}
}