nodeID = $nodeID;
$this->nodeName = $nodeName;
$this->nodeChildID = $nodeChildID; // 0 means its parent node
$this->nodeLevel = $nodeLevel;
Structure::$treeList[] = $this;
} else {
// idk perhaps throwing an error
}
}
public static function nodeExists($nodeID) {
if(is_array(Structure::$treeList)) {
foreach(Structure::$treeList as $key => $obj) {
if($obj->nodeID == $nodeID) return true;
}
}
return false;
}
public static function printTree() {
$parent = Structure::findParentNodes();
foreach($parent as $id => $obj) {
// So lets print all that node childs
echo "Rootnode: {$obj->nodeName}[ID : {$obj->nodeID}]
";
Structure::printChildNodes($obj->nodeID);
}
}
public static function findParentNodes() {
$countID = 0;
foreach(Structure::$treeList as $key => $obj)
if($obj->nodeChildID == 0) $parentNodes[$obj->nodeID] = $obj;
return $parentNodes;
}
public static function printChildNodes($nodeID) {
foreach(Structure::$treeList as $id => $obj) {
if($obj->nodeChildID == $nodeID) {
echo " - Childnode : {$obj->nodeName}[ID : {$obj->nodeID}] (SubID : {$obj->nodeChildID})
";
$lapsed = Structure::kontrolli_lapsi($obj->nodeID);
if($lapsed){
foreach($lapsed as $lapse_id){
echo ' --';
Structure::printNode($lapse_id);
}
}
//Structure::printChildNodes($nodeID);
}
}
echo '
';
}
public static function asd(){
var_dump(Structure::$treeList);
}
public static function printNode($ID_p){
foreach(Structure::$treeList as $id => $obj) {
if($obj->nodeID == $ID_p){
echo ' Noot: '.($obj->nodeName).'[ID : '.($obj->nodeID).'] (SubID : '.($obj->nodeChildID).')
';
}
}
}
public static function kontrolli_lapsi($ID){
$lapsed = array();
foreach(Structure::$treeList as $id => $obj) {
if($obj->nodeChildID == $ID){
array_push($lapsed, $obj->nodeID);
}
}
return $lapsed;
}
}
new Structure(1,"Esimene",0,0);
new Structure(3,"esimese-nod1",1,1);
new Structure(4,"esimese2-nod2",3,1);
new Structure(5,"esimese2-nod3",3,1);
new Structure(6,"esimese3-nod1",4,1);
new Structure(7,"Teine",0,0);
new Structure(8,"teise-nod1",7,1);
Structure::printTree();
Structure::asd();
?>