Example #1
0
/**
 * @todo needs docblock
 */
function bu_navigation_gather_childsections($parent_id, $sections, $max_depth = 0, $current_depth = 1)
{
    $child_sections = array();
    if (array_key_exists($parent_id, $sections) && count($sections[$parent_id]) > 0) {
        foreach ($sections[$parent_id] as $child_id) {
            if (array_key_exists($child_id, $sections) && count($sections[$child_id]) > 0) {
                array_push($child_sections, $child_id);
                if ($max_depth == 0 || $current_depth < $max_depth) {
                    $child_sections = array_merge($child_sections, bu_navigation_gather_childsections($child_id, $sections, $max_depth, $current_depth + 1));
                }
            }
        }
    }
    return $child_sections;
}
Example #2
0
 /**
  *	Covers bu_navigation_gather_childsections()
  */
 public function test_bu_navigation_gather_childsections()
 {
     $all_sections = bu_navigation_load_sections();
     $parent = $this->posts['parent'];
     $child = $this->posts['child'];
     $grandchild_one = $this->posts['grandchild_one'];
     $good_childsections = false;
     // $parent should return child and grandchild_one as the only sections
     $child_sections = bu_navigation_gather_childsections($parent, $all_sections['sections']);
     if (count($child_sections) == 2 and $child_sections[0] == $child and $child_sections[1] == $grandchild_one) {
         $good_childsections = true;
     }
     $this->assertTrue($good_childsections);
     // Test Depth Functionality
     $depth_one = bu_navigation_gather_childsections($parent, $all_sections['sections'], 1);
     $depth_two = bu_navigation_gather_childsections($parent, $all_sections['sections'], 2);
     // Expected results
     $depth_one_exp = array($child);
     $depth_two_exp = array($child, $grandchild_one);
     // Test actual and expected are equal
     $this->assertEquals($depth_one, $depth_one_exp);
     $this->assertEquals($depth_two, $depth_two_exp);
 }