Ejemplo n.º 1
0
function render_tree($tree, $has_child, $draw_hasChild, $draw_noChild, $depth = 0, $parent = false)
{
    $html_stack = "";
    if ($depth === 0) {
        $parent = $tree;
    }
    foreach ($tree as $key => $value) {
        $res = call_user_func_array($has_child, array($key, $value, $parent, $depth, $tree));
        $html = "";
        // has children
        if ($res === true) {
            $children_arr = render_tree($value, $has_child, $draw_hasChild, $draw_noChild, $depth + 1, $tree);
            if (is_callable($draw_hasChild)) {
                $html = call_user_func_array($draw_hasChild, array($key, $value, $children_arr, $parent, $depth, $tree));
            } else {
                $html = sprintf($draw_hasChild, $key, $value, implode($children_arr));
            }
        } elseif ($res === false) {
            if (is_callable($draw_hasChild)) {
                $html = call_user_func_array($draw_noChild, array($key, $value, $parent, $depth, $tree));
            } else {
                $html = sprintf($draw_hasChild, $key, $value);
            }
        }
        $html_stack .= $html;
    }
    return $html_stack;
}
Ejemplo n.º 2
0
function render_tree($Pages, $groupID, $parentID = 0, $class = false)
{
    $pages = $Pages->get_by_parent($parentID, $groupID);
    $s = '';
    $s = '<ol class="' . $class . '">';
    if (PerchUtil::count($pages)) {
        foreach ($pages as $Page) {
            $s .= '<li><div class="page icon">' . PerchUtil::html($Page->pageNavText()) . '</div>';
            $s .= render_tree($Pages, $groupID, $Page->id(), $class);
            $s .= '</li>';
        }
    }
    $s .= '</ol>';
    return $s;
}
Ejemplo n.º 3
0
function render_tree($Categories, $Set, $parentID = 0, $class = false)
{
    $categories = $Categories->get_by_parent($parentID, $Set->id());
    $s = '';
    $s = '<ol class="' . $class . '">';
    if (PerchUtil::count($categories)) {
        foreach ($categories as $Category) {
            $s .= '<li id="category_' . $Category->id() . '" data-parent="' . $parentID . '"><div class="category icon">';
            $s .= '<input type="text" name="c-' . $Category->id() . '" value="' . $Category->catOrder() . '" />';
            $s .= '' . PerchUtil::html($Category->catTitle()) . '</div>';
            $s .= render_tree($Categories, $Set, $Category->id());
            $s .= '</li>';
        }
    }
    $s .= '</ol>';
    return $s;
}
Ejemplo n.º 4
0
    $result = '<ul>';
    foreach ($tree as $node) {
        $node_depth = $node['depth'];
        $node_name = $node['name'];
        $node_id = $node['category_id'];
        if ($node_depth == $current_depth) {
            if ($counter > 0) {
                $result .= '</li>';
            }
        } elseif ($node_depth > $current_depth) {
            $result .= '<ul>';
            $current_depth = $current_depth + ($node_depth - $current_depth);
        } elseif ($node_depth < $current_depth) {
            $result .= str_repeat('</li></ul>', $current_depth - $node_depth) . '</li>';
            $current_depth = $current_depth - ($current_depth - $node_depth);
        }
        $result .= '<li id="node' . $node_id . '"';
        $result .= $node_depth < 1 ? ' class=""' : '';
        $result .= '><a href="#">' . $node_name . '</a>';
        ++$counter;
    }
    $result .= str_repeat('</li></ul>', $node_depth) . '</li>';
    $result .= '</ul>';
    return $result;
}
print_r(render_tree($tree));
?>
</div>
</body>
</html>
Ejemplo n.º 5
0
function render_tree($Pages, $CurrentUser, $parentID = 0, $class = false)
{
    $pages = $Pages->get_by_parent($parentID);
    $s = '';
    $s = '<ol class="' . $class . '">';
    if (PerchUtil::count($pages)) {
        foreach ($pages as $Page) {
            $s .= '<li id="page_' . $Page->id() . '" data-parent="' . $parentID . '" ' . (!$Page->role_may_create_subpages($CurrentUser) ? ' class="ui-nestedSortable-no-nesting "' : 'class=""') . '><div class="page icon">';
            $s .= '<input type="text" name="p-' . $Page->id() . '" value="' . $Page->pageOrder() . '" />';
            $s .= '' . PerchUtil::html($Page->pageNavText()) . '</div>';
            $s .= render_tree($Pages, $CurrentUser, $Page->id());
            $s .= '</li>';
        }
    }
    $s .= '</ol>';
    return $s;
}