Example #1
0
 public static function scan_for_leaves($node, $root = false, $leaves = [])
 {
     if (!$root) {
         $root = $node;
     }
     if (@(!$node['tag']) && Scanner::has_only_nontagged(Tree::get_parent_from_path($root, $node['path']))) {
         $leaf = Tree::get_parent_from_path($root, $node['path']);
         $leaf['leaf_identified_by'] = $node['path'];
         $leaves[] = $leaf;
         return $leaves;
     } else {
         if (@(!$node['tag'])) {
             return $leaves;
         } else {
             if (@(!!$node['children'])) {
                 foreach ($node['children'] as $child) {
                     $leaves = Scanner::scan_for_leaves($child, $root, $leaves);
                 }
                 return $leaves;
             } else {
                 $leaf = Tree::get_node_from_path($root, $node['path']);
                 $leaf['leaf_identified_by'] = $node['path'];
                 $leaves[] = $leaf;
                 return $leaves;
             }
         }
     }
 }
Example #2
0
 public static function get_siblings($root, $node)
 {
     $path = $node['path'];
     $parent = Tree::get_parent_from_path($root, $path);
     $siblings = [];
     foreach ($parent['children'] as $child) {
         if ($child['path'] != $path) {
             $siblings[] = $child;
         }
     }
     return $siblings;
 }