Hallo,
ich möchte folgende Baumstruktur mit dem unten stehenden Script ausgeben lassen:
dieses ist das Script, es gibt den Baum nicht richtig aus:
Kann mir jemand einen Tipp geben, wie ich das richtig hinbekomme?
ich möchte folgende Baumstruktur mit dem unten stehenden Script ausgeben lassen:
PHP-Code:
<ol class="sortable">
<li id="menuItem_1">
<div class="menu-handle">
<span>
Home
</span>
<div class="menu-options">
<a href="#">Delete</a>
</div>
</div>
<ol>
<li id="menuItem_2">
<div class="menu-handle">
<span>
About us
</span>
<div class="menu-options">
<a href="#">Delete</a>
</div>
</div>
<ol>
<li id="menuItem_3">
<div class="menu-handle">
<span>
Our Portfolio
</span>
<div class="menu-options">
<a href="#">Delete</a>
</div>
</div>
</li>
</ol>
</li>
<li id="menuItem_4">
<div class="menu-handle">
<span>
Our Team
</span>
<div class="menu-options">
<a href="#">Delete</a>
</div>
</div>
</li>
</ol>
<li id="menuItem_5">
<div class="menu-handle">
<span>
How it works
</span>
<div class="menu-options">
<a href="#">Delete</a>
</div>
</div>
</li>
<li id="menuItem_6">
<div class="menu-handle">
<span>
Contact us
</span>
<div class="menu-options">
<a href="#">Delete</a>
</div>
</div>
</li>
</ol>
PHP-Code:
public function editSectionHtml($menu_area_id, $language_id, $edited_section) {
$html = "";
$tree = $this->getTree($menu_area_id, $language_id); //get the tree
$html .= "<ol class=\"nested-sortable\">\n"; //start nested-sotable
for ($i=0; $i<count($tree); $i++) {
$html .= "<li>Menu"; //start li
$html .= "<input type=\"text\" name=\"section_" . $tree[$i]['id'] . "\" value=\"" . htmlspecialchars($tree[$i]['menu_name'], ENT_QUOTES, "UTF-8") . "\">";
if (isset($tree[$i]['level'], $tree[$i+1]['level']) AND $tree[$i]['level'] < $tree[$i+1]['level']) {
$html .= "\n<ol>\n"; //start next level
} else if(isset($tree[$i+1]['level']) AND $tree[$i]['level'] > $tree[$i+1]['level']) {
$diff = $tree[$i]['level'] - $tree[$i+1]['level'];
$html .= str_repeat("</ol></li>\n", $diff) . "\n"; //close level
} else if(empty($tree[$i+1]['level']) AND $tree[$i]['level'] < $tree[$i-1]['level']) {
$diff = $tree[$i-1]['level'] - $tree[$i]['level'];
$html .= str_repeat("</ol></li>\n", $diff) . "\n"; //close last level
} else {
$html .= "\n</li>\n"; //close li of same levels
}
}
$html .= "</ol></ol>\n";
return $html;
}
Kommentar