コード例 #1
0
    /**
     * Get a site tree HTML listing which displays the nodes under the given criteria.
     * 
     * @param $className The class of the root object
     * @param $rootID The ID of the root object.  If this is null then a complete tree will be
     *  shown
     * @param $childrenMethod The method to call to get the children of the tree. For example,
     *  Children, AllChildrenIncludingDeleted, or AllHistoricalChildren
     * @return String Nested unordered list with links to each page
     */
    function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30)
    {
        // Default childrenMethod and numChildrenMethod
        if (!$childrenMethod) {
            $childrenMethod = 'AllChildrenIncludingDeleted';
        }
        if (!$numChildrenMethod) {
            $numChildrenMethod = 'numChildren';
        }
        // Get the tree root
        $obj = $rootID ? $this->getRecord($rootID) : singleton($className);
        // Mark the nodes of the tree to return
        if ($filterFunction) {
            $obj->setMarkingFilterFunction($filterFunction);
        }
        $obj->markPartialTree($minNodeCount, $this, $childrenMethod, $numChildrenMethod);
        // Ensure current page is exposed
        if ($p = $this->currentPage()) {
            $obj->markToExpose($p);
        }
        // NOTE: SiteTree/CMSMain coupling :-(
        SiteTree::prepopuplate_permission_cache('CanEditType', $obj->markedNodeIDs(), 'SiteTree::can_edit_multiple');
        // getChildrenAsUL is a flexible and complex way of traversing the tree
        $titleEval = '
			"<li id=\\"record-$child->ID\\" class=\\"" . $child->CMSTreeClasses($extraArg) . "\\">" .
			"<a href=\\"" . Controller::join_links(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\\" class=\\"" . $child->CMSTreeClasses($extraArg) . "\\" title=\\"' . _t('LeftAndMain.PAGETYPE', 'Page type: ') . '".$child->class."\\" >" . ($child->TreeTitle) . 
			"</a>"
		';
        $html = $obj->getChildrenAsUL("", $titleEval, $this, true, $childrenMethod, $numChildrenMethod, $minNodeCount);
        // Wrap the root if needs be.
        if (!$rootID) {
            $rootLink = $this->Link('show') . '/root';
            // This lets us override the tree title with an extension
            if ($this->hasMethod('getCMSTreeTitle') && ($customTreeTitle = $this->getCMSTreeTitle())) {
                $treeTitle = $customTreeTitle;
            } else {
                $siteConfig = SiteConfig::current_site_config();
                $treeTitle = $siteConfig->Title;
            }
            $html = "<ul id=\"sitetree\" class=\"tree unformatted\"><li id=\"record-0\" class=\"Root nodelete\"><a href=\"{$rootLink}\"><strong>{$treeTitle}</strong></a>" . $html . "</li></ul>";
        }
        return $html;
    }