| 433 | | if ( $max_depth == 0 || |
|---|
| 434 | | ($max_depth != 0 && $max_depth > $depth+1 )) { //whether to descend |
|---|
| 435 | | |
|---|
| 436 | | $num_elements = sizeof( $children_elements ); |
|---|
| 437 | | for ( $i = 0; $i < $num_elements; $i++ ) { |
|---|
| 438 | | |
|---|
| 439 | | $child = $children_elements[$i]; |
|---|
| 440 | | if ( $child->$parent_field == $element->$id_field ) { |
|---|
| 441 | | |
|---|
| 442 | | if ( !isset($newlevel) ) { |
|---|
| 443 | | $newlevel = true; |
|---|
| 444 | | //start the child delimiter |
|---|
| 445 | | $cb_args = array_merge( array(&$output, $depth), $args); |
|---|
| 446 | | call_user_func_array(array(&$this, 'start_lvl'), $cb_args); |
|---|
| 447 | | } |
|---|
| 448 | | |
|---|
| 449 | | array_splice( $children_elements, $i, 1 ); |
|---|
| 450 | | $num_elements--; |
|---|
| 451 | | $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output ); |
|---|
| 452 | | $i = -1; |
|---|
| | 432 | $id = $element->$id_field; |
|---|
| | 433 | |
|---|
| | 434 | // descend only the depth is right and there are chilrens for this element |
|---|
| | 435 | if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) { |
|---|
| | 436 | |
|---|
| | 437 | foreach( $children_elements[ $id ] as $child ){ |
|---|
| | 438 | |
|---|
| | 439 | if ( !isset($newlevel) ) { |
|---|
| | 440 | $newlevel = true; |
|---|
| | 441 | //start the child delimiter |
|---|
| | 442 | $cb_args = array_merge( array(&$output, $depth), $args); |
|---|
| | 443 | call_user_func_array(array(&$this, 'start_lvl'), $cb_args); |
|---|
| 514 | | if ( !$top_level_elements ) { |
|---|
| 515 | | |
|---|
| 516 | | $root = $children_elements[0]; |
|---|
| 517 | | $num_elements = sizeof($children_elements); |
|---|
| 518 | | for ( $i = 0; $i < $num_elements; $i++ ) { |
|---|
| 519 | | |
|---|
| 520 | | $child = $children_elements[$i]; |
|---|
| 521 | | if ($root->$parent_field == $child->$parent_field ) { |
|---|
| 522 | | $top_level_elements[] = $child; |
|---|
| 523 | | array_splice( $children_elements, $i, 1 ); |
|---|
| 524 | | $num_elements--; |
|---|
| 525 | | $i--; |
|---|
| 526 | | } |
|---|
| | 509 | if ( empty($top_level_elements) ) { |
|---|
| | 510 | |
|---|
| | 511 | $root = $elements[0]; |
|---|
| | 512 | |
|---|
| | 513 | $top_level_elements = array(); |
|---|
| | 514 | $children_elements = array(); |
|---|
| | 515 | foreach ( $elements as $e) { |
|---|
| | 516 | if ( $root->$parent_field == $e->$parent_field ) |
|---|
| | 517 | $top_level_elements[] = $e; |
|---|
| | 518 | else |
|---|
| | 519 | $children_elements[ $e->$parent_field ][] = $e; |
|---|
| 539 | | foreach ( $children_elements as $orphan_e ) |
|---|
| 540 | | $this->display_element( $orphan_e, $empty_array, 1, 0, $args, $output ); |
|---|
| | 532 | foreach ( $children_elements as $orphans ) |
|---|
| | 533 | foreach( $orphans as $op ) |
|---|
| | 534 | $this->display_element( $op, $empty_array, 1, 0, $args, $output ); |
|---|