HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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;
    }
}