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/SBogers93/fitale.nl/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 [];
    }

}