_menu_tree_data
includes/menu.inc, строка 1065
- Версии
- 6
_menu_tree_data($result, $parents, $depth, $previous_element = '')
Recursive helper function to build the data representing a menu tree.
The function is a bit complex because the rendering of an item depends on the next menu item. So we are always rendering the element previously processed not the current one.
Связанные темы
Код
<?php
function _menu_tree_data($result, $parents, $depth, $previous_element = '') {
$remnant = NULL;
$tree = array();
while ($item = db_fetch_array($result)) {
// We need to determine if we're on the path to root so we can later build
// the correct active trail and breadcrumb.
$item['in_active_trail'] = in_array($item['mlid'], $parents);
// The current item is the first in a new submenu.
if ($item['depth'] > $depth) {
// _menu_tree returns an item and the menu tree structure.
list($item, $below) = _menu_tree_data($result, $parents, $item['depth'], $item);
if ($previous_element) {
$tree[$previous_element['mlid']] = array(
'link' => $previous_element,
'below' => $below,
);
}
else {
$tree = $below;
}
// We need to fall back one level.
if (!isset($item) || $item['depth'] < $depth) {
return array($item, $tree);
}
// This will be the link to be output in the next iteration.
$previous_element = $item;
}
// We are at the same depth, so we use the previous element.
elseif ($item['depth'] == $depth) {
if ($previous_element) {
// Only the first time.
$tree[$previous_element['mlid']] = array(
'link' => $previous_element,
'below' => FALSE,
);
}
// This will be the link to be output in the next iteration.
$previous_element = $item;
}
// The submenu ended with the previous item, so pass back the current item.
else {
$remnant = $item;
break;
}
}
if ($previous_element) {
// We have one more link dangling.
$tree[$previous_element['mlid']] = array(
'link' => $previous_element,
'below' => FALSE,
);
}
return array($remnant, $tree);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии