Exemple #1
0
function _htmlListExt($tree, $treeNodePrefix, $treeClassPrefix, $ext, $depth, $treeId = '', $treeClass = '')
{
    $html = '<ul';
    $html .= !empty($treeId) ? ' id="' . $treeId . '"' : '';
    $html .= !empty($treeClass) ? ' class="' . $treeClass . ' ' . $ext['level'] . $depth . '"' : ' class="' . $ext['level'] . $depth . '"';
    $html .= '>';
    $size = count($tree);
    $i = 1;
    foreach ($tree as $tab) {
        $class = array();
        $class[] = $size == 1 ? $ext['single'] : '';
        $class[] = $i == 1 && $size > 1 ? $ext['first'] : '';
        $class[] = $i == $size && $size > 1 ? $ext['last'] : '';
        $class[] = !empty($tab['nodes']) ? $ext['parent'] : $ext['childless'];
        $class[] = !empty($treeClassPrefix) ? $treeClassPrefix . $tab['item']['id'] : '';
        $class = trim(implode(' ', $class));
        $i++;
        $html .= '<li';
        $html .= !empty($treeNodePrefix) ? ' id="' . $treeNodePrefix . $tab['item']['id'] . '"' : '';
        $html .= ' class="' . $class . '">';
        $attr = !empty($tab['item']['title']) ? ' title="' . $tab['item']['title'] . '"' : '';
        $attr .= !empty($tab['item']['className']) ? ' class="' . $tab['item']['className'] . '"' : '';
        if (!empty($tab['item']['href'])) {
            $html .= '<a href="' . DataUtil::formatForDisplay($tab['item']['href']) . '"' . $attr . '>' . $tab['item']['name'] . '</a>';
        } else {
            $html .= '<span' . $attr . '>' . $tab['item']['name'] . '</span>';
        }
        $html .= !empty($tab['nodes']) ? _htmlListExt($tab['nodes'], $treeNodePrefix, $treeClassPrefix, $ext, $depth + 1) : '';
        $html .= '</li>';
    }
    $html .= '</ul>';
    return $html;
}
Exemple #2
0
/**
 * Helper function to build an html list from a menutree tree structure
 *
 * @param array  $tree            menutree array
 * @param string $treeNodePrefix  string to prefix the css id attribute of the list items
 * @param string $treeClassPrefix string to prefix the css class attribute of the list items
 * @param array  $ext             TODO what does this parameter do?
 * @param int    $depth           TODO what does this parameter do?
 * @param string $treeId          the id of the list control
 * @param string $treeClass       the class of the tree control
 * @param boolean $bootstrap      is the menu to be styled with bootstrap?
 *
 * @return string the rendered list
 */
function _htmlListExt($tree, $treeNodePrefix, $treeClassPrefix, $ext, $depth, $treeId = '', $treeClass = '', $bootstrap = false)
{
    $html = '<ul';
    $html .= !empty($treeId) ? ' id="' . $treeId . '"' : '';
    if ($bootstrap) {
        $ulClass = $depth - 1 > 0 ? "dropdown-menu" : '';
        if (empty($ulClass)) {
            $ulClass = !empty($treeClass) ? $treeClass : '';
        }
        $html .= !empty($ulClass) ? " class='{$ulClass}'" : '';
    } else {
        $html .= !empty($treeClass) ? ' class="' . $treeClass . ' ' . $ext['level'] . $depth . '"' : ' class="' . $ext['level'] . $depth . '"';
    }
    $html .= '>';
    $size = count($tree);
    $i = 1;
    foreach ($tree as $tab) {
        $classes = array();
        if (!$bootstrap) {
            $classes[] = $size == 1 ? $ext['single'] : '';
            $classes[] = $i == 1 && $size > 1 ? $ext['first'] : '';
            $classes[] = $i == $size && $size > 1 ? $ext['last'] : '';
            $classes[] = !empty($treeClassPrefix) ? $treeClassPrefix . $tab['item']['id'] : '';
            $classes[] = !empty($tab['nodes']) ? $ext['parent'] : $ext['childless'];
        } else {
            $classes[] = !empty($tab['nodes']) ? $ext['parent'] : '';
        }
        $classList = trim(implode(' ', $classes));
        $i++;
        $html .= '<li';
        $html .= !empty($treeNodePrefix) ? ' id="' . $treeNodePrefix . $tab['item']['id'] . '"' : '';
        $html .= !empty($classList) ? ' class="' . $classList . '">' : '>';
        $attr = !empty($tab['item']['title']) ? ' title="' . $tab['item']['title'] . '"' : '';
        $attr .= !empty($tab['item']['class']) ? ' class="' . $tab['item']['class'] . '"' : '';
        if (!empty($tab['item']['href'])) {
            if ($bootstrap && in_array('dropdown', $classes)) {
                $html .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . $tab['item']['name'] . ' <b class="caret"></b></a>';
            } else {
                $html .= '<a href="' . DataUtil::formatForDisplay($tab['item']['href']) . '"' . $attr . '>' . $tab['item']['name'] . '</a>';
            }
        } else {
            $html .= '<span' . $attr . '>' . $tab['item']['name'] . '</span>';
        }
        $html .= !empty($tab['nodes']) ? _htmlListExt($tab['nodes'], $treeNodePrefix, $treeClassPrefix, $ext, $depth + 1, '', '', $bootstrap) : '';
        $html .= '</li>';
    }
    $html .= '</ul>';
    return $html;
}