示例#1
0
function getTreeView(array $roots, $ind)
{
    $tree = '';
    foreach ($roots as $branch) {
        $closed = true;
        if (isset($_SESSION['tree']) && isset($_SESSION['tree'][$branch->getId()])) {
            $closed = $_SESSION['tree'][$branch->getId()] === 'closed';
        }
        $tree .= $ind . '<dl tag-id="' . $branch->getId() . '" class="tree' . ($closed ? ' closed' : '') . '">' . PHP_EOL;
        $tree .= $ind . '  ' . '<dt>' . getTagLinks($branch) . '</dt>' . PHP_EOL;
        $tree .= $ind . '  ' . '<dd>' . PHP_EOL;
        $tree .= getTreeView($branch->getChildren(), $ind . '  ');
        $tree .= $ind . '  ' . '</dd>' . PHP_EOL;
        $tree .= $ind . '</dl>' . PHP_EOL;
    }
    return $tree;
}
示例#2
0
/**
 * Function getTreeView
 * 
 * @description Similar to menu generation code. It recursively fetches pages according to the sitemap, and generates a ul list with drop handlers defined.
 *
 * @param pageId The current Page the function is operation on
 * @param depth depth of the child list to be fetched at each level. Here it is always -1 to fetch till the last element is reached
 * @param rootUri here it is /. Look into Menu documentation for implementation of the same elsewhere.
 * @param userId This is just to check the permission.
 * @param curdepth Current Depth of the recursion
 *
 * @return HTML - UL list of the tree structure of pages
 */
function getTreeView($pageId, $depth, $rootUri, $userId, $curdepth)
{
    global $cmsFolder;
    global $templateFolder;
    require_once "menu.lib.php";
    if ($depth > 0 || $depth == -1) {
        if ($curdepth == 1 || $pageId == 0) {
            $classname = "treeRoot";
        } else {
            $classname = "treeItem";
        }
        $pageRow = getChildren($pageId, $userId);
        $var = "<ul class='{$classname}'>";
        for ($i = 0; $i < count($pageRow); $i += 1) {
            $newdepth = $curdepth + 1;
            $var .= "<li><a href=\"./\" class=\"dropme\" onclick=\"return selectItem(event,this)\"";
            $var .= <<<DROPZONE
\t  ondragenter="dragEnterHandler(event)" ondragover="dragOverHandler(event)" ondragleave="dragOutHandler(event)" ondrop="dropHandler(event)" id="p{$pageRow[$i][0]}">  
DROPZONE;
            if ($pageRow[$i][3] != NULL) {
                $var .= "<img src=\"{$rootUri}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/status/weather-clear.png\" />\n ";
            } else {
                $var .= "<img src=\"{$rootUri}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/status/dialog-error.png\" width=12 height=12/>\n ";
            }
            $var .= "{$pageRow[$i][1]}</a>";
            $var .= getTreeView($pageRow[$i][0], $depth == -1 ? $depth : $depth - 1, $rootUri, $userId, $newdepth);
            $var .= "</li>";
        }
        $var .= "</ul>";
        if (count($pageRow) == 0) {
            return "";
        }
        return $var;
    }
}