Contao\PageSelector::renderPagetree PHP Метод

renderPagetree() защищенный Метод

Recursively render the pagetree
protected renderPagetree ( integer $id, integer $intMargin, boolean $protectedPage = false, boolean $blnNoRecursion = false, array $arrFound = [] ) : string
$id integer
$intMargin integer
$protectedPage boolean
$blnNoRecursion boolean
$arrFound array
Результат string
    protected function renderPagetree($id, $intMargin, $protectedPage = false, $blnNoRecursion = false, $arrFound = array())
    {
        static $session;
        /** @var AttributeBagInterface $objSessionBag */
        $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
        $session = $objSessionBag->all();
        $flag = substr($this->strField, 0, 2);
        $node = 'tree_' . $this->strTable . '_' . $this->strField;
        $xtnode = 'tree_' . $this->strTable . '_' . $this->strName;
        // Get the session data and toggle the nodes
        if (\Input::get($flag . 'tg')) {
            $session[$node][\Input::get($flag . 'tg')] = isset($session[$node][\Input::get($flag . 'tg')]) && $session[$node][\Input::get($flag . 'tg')] == 1 ? 0 : 1;
            $objSessionBag->replace($session);
            $this->redirect(preg_replace('/(&(amp;)?|\\?)' . $flag . 'tg=[^& ]*/i', '', \Environment::get('request')));
        }
        $objPage = $this->Database->prepare("SELECT id, alias, type, protected, published, start, stop, hide, title FROM tl_page WHERE id=?")->limit(1)->execute($id);
        // Return if there is no result
        if ($objPage->numRows < 1) {
            return '';
        }
        $return = '';
        $intSpacing = 20;
        $childs = array();
        // Check whether there are child records
        if (!$blnNoRecursion) {
            $objNodes = $this->Database->prepare("SELECT id FROM tl_page WHERE pid=?" . (!empty($arrFound) ? " AND id IN(" . implode(',', array_map('intval', $arrFound)) . ")" : '') . " ORDER BY sorting")->execute($id);
            if ($objNodes->numRows) {
                $childs = $objNodes->fetchEach('id');
            }
        }
        $return .= "\n    " . '<li class="' . ($objPage->type == 'root' ? 'tl_folder' : 'tl_file') . ' toggle_select hover-div"><div class="tl_left" style="padding-left:' . ($intMargin + $intSpacing) . 'px">';
        $folderAttribute = 'style="margin-left:20px"';
        $session[$node][$id] = is_numeric($session[$node][$id]) ? $session[$node][$id] : 0;
        $level = $intMargin / $intSpacing + 1;
        $blnIsOpen = !empty($arrFound) || $session[$node][$id] == 1 || in_array($id, $this->arrNodes);
        if (!empty($childs)) {
            $folderAttribute = '';
            $img = $blnIsOpen ? 'folMinus.svg' : 'folPlus.svg';
            $alt = $blnIsOpen ? $GLOBALS['TL_LANG']['MSC']['collapseNode'] : $GLOBALS['TL_LANG']['MSC']['expandNode'];
            $return .= '<a href="' . \Backend::addToUrl($flag . 'tg=' . $id) . '" title="' . \StringUtil::specialchars($alt) . '" onclick="return AjaxRequest.togglePagetree(this,\'' . $xtnode . '_' . $id . '\',\'' . $this->strField . '\',\'' . $this->strName . '\',' . $level . ')">' . \Image::getHtml($img, '', 'style="margin-right:2px"') . '</a>';
        }
        // Set the protection status
        $objPage->protected = $objPage->protected || $protectedPage;
        // Add the current page
        if (!empty($childs)) {
            $return .= \Image::getHtml($this->getPageStatusIcon($objPage), '', $folderAttribute) . ' <a href="' . \Backend::addToUrl('pn=' . $objPage->id) . '" title="' . \StringUtil::specialchars($objPage->title . ' (' . $objPage->alias . \Config::get('urlSuffix') . ')') . '">' . ($objPage->type == 'root' ? '<strong>' : '') . $objPage->title . ($objPage->type == 'root' ? '</strong>' : '') . '</a></div> <div class="tl_right">';
        } else {
            $return .= \Image::getHtml($this->getPageStatusIcon($objPage), '', $folderAttribute) . ' ' . ($objPage->type == 'root' ? '<strong>' : '') . $objPage->title . ($objPage->type == 'root' ? '</strong>' : '') . '</div> <div class="tl_right">';
        }
        // Add checkbox or radio button
        switch ($this->fieldType) {
            case 'checkbox':
                $return .= '<input type="checkbox" name="' . $this->strName . '[]" id="' . $this->strName . '_' . $id . '" class="tl_tree_checkbox" value="' . \StringUtil::specialchars($id) . '" onfocus="Backend.getScrollOffset()"' . static::optionChecked($id, $this->varValue) . '>';
                break;
            default:
            case 'radio':
                $return .= '<input type="radio" name="' . $this->strName . '" id="' . $this->strName . '_' . $id . '" class="tl_tree_radio" value="' . \StringUtil::specialchars($id) . '" onfocus="Backend.getScrollOffset()"' . static::optionChecked($id, $this->varValue) . '>';
                break;
        }
        $return .= '</div><div style="clear:both"></div></li>';
        // Begin a new submenu
        if ($blnIsOpen || !empty($childs) && $objSessionBag->get('page_selector_search') != '') {
            $return .= '<li class="parent" id="' . $node . '_' . $id . '"><ul class="level_' . $level . '">';
            for ($k = 0, $c = count($childs); $k < $c; $k++) {
                $return .= $this->renderPagetree($childs[$k], $intMargin + $intSpacing, $objPage->protected, $blnNoRecursion, $arrFound);
            }
            $return .= '</ul></li>';
        }
        return $return;
    }