Return default tree

@param   array   $page              Root page
@param   integer $depth             Depth
@param   integer $sysLanguage       System language
@param   array   $fieldList         Field list

@return  array
511199
public function index(array $page, $depth, $sysLanguage, $fieldList = array())
    {
        $rootPid = $page['uid'];

        $list = array();

        $fieldList[] = 'pid';
        $pageIdList  = array();

        // ###########################
        // Build tree
        // ############################

        // Init tree
        /** @var \TYPO3\CMS\Backend\Tree\View\PageTreeView $tree */
        $tree = $this->pageTreeView;
        foreach ($fieldList as $field) {
            $tree->addField($field, true);
        }

        $tree->init(
            'AND doktype IN (' . $this->getDocTypeList() . ') AND '
            . $this->getBackendUserAuthentication()->getPagePermsClause(1)
        );

        $tree->tree[] = array(
            'row'           => $page,
            'invertedDepth' => 0,
        );

        $tree->getTree($rootPid, $depth, '');

        // Build tree list
        foreach ($tree->tree as $row) {
            $tmp               = $row['row'];
            $list[$tmp['uid']] = $tmp;

            $pageIdList[$tmp['uid']] = $tmp['uid'];
        }

        // Calc depth
        $rootLineRaw = array();
        foreach ($list as $row) {
            $rootLineRaw[$row['uid']] = $row['pid'];
        }

        $rootLineRaw[$rootPid] = null;

        // overlay status "current"
        $defaultOverlayStatus = 0;
        if (!empty($sysLanguage)) {
            // overlay status "only available from base"
            $defaultOverlayStatus = 2;
        }

        foreach ($list as &$row) {
            // Set field as main fields
            foreach ($fieldList as $fieldName) {
                $row['_overlay'][$fieldName] = $defaultOverlayStatus;
                $row['_base'][$fieldName]    = $row[$fieldName];
            }

            $row['_depth'] = $this->listCalcDepth($row['uid'], $rootLineRaw);
        }
        unset($row);

        // ############################
        // Language overlay
        // ############################

        if (!empty($sysLanguage) && !empty($pageIdList)) {
            // Fetch all overlay rows for current page list
            $overlayFieldList = array();
            foreach ($fieldList as $fieldName) {
                if ($this->isFieldInTcaTable('pages_language_overlay', $fieldName)) {
                    $overlayFieldList[$fieldName] = $fieldName;
                }
            }

            // Build list of fields which we need to query
            $queryFieldList = array(
                'uid',
                'pid',
                'title',
            );
            $queryFieldList = array_merge($queryFieldList, $overlayFieldList);

            $res = DatabaseUtility::connection()->exec_SELECTquery(
                implode(',', $queryFieldList),
                'pages_language_overlay',
                'pid IN(' . implode(',', $pageIdList) . ') AND sys_language_uid = ' . (int)$sysLanguage
                    . ' AND deleted = 0'
            );

            // update all overlay status field to "from base"
            foreach ($list as &$row) {
                foreach ($overlayFieldList as $fieldName) {
                    $row['_overlay'][$fieldName] = 0;
                }
            }
            unset($row);

            while ($overlayRow = DatabaseUtility::connection()->sql_fetch_assoc($res)) {
                $pageOriginalId = $overlayRow['pid'];

                // Don't use uid and pid
                unset($overlayRow['uid'], $overlayRow['pid']);

                // inject title
                $fieldName = 'title';
                if (!empty($overlayRow[$fieldName])) {
                    $list[$pageOriginalId][$fieldName] = $overlayRow[$fieldName];
                }

                // inject all other fields
                foreach ($fieldList as $fieldName) {
                    if (!empty($overlayRow[$fieldName])) {
                        $list[$pageOriginalId][$fieldName] = $overlayRow[$fieldName];

                        // update overlay status field to "from overlay"
                        $list[$pageOriginalId]['_overlay'][$fieldName] = 1;
                    }
                }
            }
        }

        return $list;
    }
680385
public function treePageDefaultEdit(): ResponseInterface
    {
        $this->checkDefaultTreeBlocksExist();

        $main_blocks = $this->treeBlocks(-1, 'main');
        $side_blocks = $this->treeBlocks(-1, 'side');

        $all_blocks = $this->availableTreeBlocks();
        $title      = I18N::translate('Set the default blocks for new family trees');
        $url_cancel = route('admin-control-panel');
        $url_save   = route('tree-page-default-update');

        return $this->viewResponse('edit-blocks-page', [
            'all_blocks'  => $all_blocks,
            'can_reset'   => false,
            'main_blocks' => $main_blocks,
            'side_blocks' => $side_blocks,
            'title'       => $title,
            'url_cancel'  => $url_cancel,
            'url_save'    => $url_save,
        ]);
    }
1182310
public function findAncestors(Page $root, Page $page) : ObjectCollection
    {
        $pages = new ObjectCollection;

        foreach ($root->getDescendants() as $item)
        {
            if (!($item->getLeftValue() >= $page->getLeftValue() && $item->getRightValue() <= $page->getRightValue()))
            {
                $pages->append($item);
            }
        }

        $tree = $this->nestedSet->getTree($pages, $root->getTreeLeft(), $root->getTreeRight());
        $pages = $this->nestedSet->getFlatCollection($tree);

        return $pages;
    }
417614
public function getMultilingualSectionForPage(Page $page)
    {
        $result = null;
        $siteTree = $page->getSiteTreeObject();
        if ($siteTree !== null) {
            $homeID = $siteTree->getSiteHomePageID();
            if ($homeID) {
                $mlSections = $this->getMultilingualSections();
                if (isset($mlSections[$homeID])) {
                    $result = $mlSections[$homeID];
                }
            }
        }

        return $result;
    }
499774
public function _buildTree(&$rootDoc, &$class, $depth = NULL)
    {
        if ($depth === NULL) {
            $start = TRUE;
            $depth = 0;
        } else {
            $start = FALSE;
        }
        $output = '';
        $undefinedClass = FALSE;
        if ($class->superclass()) {
            $superclass =& $rootDoc->classNamed($class->superclass());
            if ($superclass) {
                $result = $this->_buildTree($rootDoc, $superclass, $depth);
                $output .= $result[0];
                $depth = ++$result[1];
            } else {
                $output .= $class->superclass().'<br>';
                $output .= str_repeat('   ', $depth).' └─';
                $depth++;
                $undefinedClass = TRUE;
            }
        }
        if ($depth > 0 && !$undefinedClass) {
            $output .= str_repeat('   ', $depth).' └─';
        }
        if ($start) {
            $output .= '<strong>'.$class->name().'</strong><br />';
        } else {
            $output .= '<a href="'.str_repeat('../', $this->_depth).$class->asPath().'">'.$class->name().'</a><br>';
        }

        return array($output, $depth);
    }
657191
public function getTree($groups = [], $deep = 0)
    {
        $deep = (int) $deep;
        $deep--;

        /** @var $group Group */
        foreach ($this as $group) {
            $groups[] = $group;
            // 参数为0时,当前为-1,则一直获取下去
            if ($deep) {
                $groups = $group->getChildren()->findAll()->getTree($groups, $deep);
            }
        }

        return $groups;
    }
519265
private function get_default_tree_structure() {

        $frontpage = \context_course::instance(SITEID);

        $categorybranches = $this->get_all_category_branches();

        $elements = [
            'text' => get_string('contextlevelname' . CONTEXT_SYSTEM, 'tool_dataprivacy'),
            'contextlevel' => CONTEXT_SYSTEM,
            'branches' => [
                [
                    'text' => get_string('user'),
                    'contextlevel' => CONTEXT_USER,
                ], [
                    'text' => get_string('categories'),
                    'branches' => $categorybranches,
                    'expandelement' => 'category',
                ], [
                    'text' => get_string('frontpagecourse', 'tool_dataprivacy'),
                    'contextid' => $frontpage->id,
                    'branches' => [
                        [
                            'text' => get_string('activitiesandresources', 'tool_dataprivacy'),
                            'expandcontextid' => $frontpage->id,
                            'expandelement' => 'module',
                            'expanded' => 0,
                        ], [
                            'text' => get_string('blocks'),
                            'expandcontextid' => $frontpage->id,
                            'expandelement' => 'block',
                            'expanded' => 0,
                        ],
                    ]
                ]
            ]
        ];

        // Returned as an array to follow a common array format.
        return [self::complete($elements, $this->defaultcontextlevel, $this->defaultcontextid)];
    }
270346
protected function simulateTitle(array $page, $sysLanguage)
    {
        $this->getFrontendUtility()->initTsfe($page, null, $page, null, $sysLanguage);

        $pagetitle = $this->objectManager->get('Metaseo\\Metaseo\\Page\\Part\\PagetitlePart');
        $ret       = $pagetitle->main($page['title']);

        return $ret;
    }
1045524
public function renderTree($pages, $closedPages, $langId, $level = null) {
        if (empty($pages)) {
            $newPageLink = $this->Html->link(
                __d('wasabi_cms', 'Please add your first Page'),
                [
                    'plugin' => 'Wasabi/Cms',
                    'controller' => 'Pages',
                    'action' => 'add'
                ],
                [
                    'title' => __d('wasabi_cms', 'Add your first Page')
                ]
            );
            return '<li class="center">' . __d('wasabi_cms', 'There are no pages yet. {0}.', $newPageLink) . '</li>';
        }

        $output = '';

        $depth = ($level !== null) ? $level : 1;
        foreach ($pages as $page) {
            $closed = false;
            $classes =  ['page'];
            if (in_array($page->id, $closedPages)) {
                $closed = true;
                $classes[] = 'closed';
            }

            $pageRow = $this->_View->element('Wasabi/Cms.../Pages/__page-row', [
                'page' => $page,
                'closed' => $closed,
                'langId' => $langId
            ]);

            if (!empty($page->children)) {
                $pageRow .= '<ul' . ($closed ? ' style="display: none;"' : '') . '>' . $this->renderTree($page->children, $closedPages, $langId, $depth + 1) . '</ul>';
            } else {
                $classes[] = 'no-children';
            }

            $output .= '<li class="' . join(' ', $classes) . '" data-cms-page-id="' . $page->id . '">' . $pageRow . '</li>';
        }

        return $output;
    }
7333
public function getSimpleTree($fields=array(),$transfields=array(),$lang='',$wh=array()){
		$lang=$this->detectLanguage($lang);
		//
		$cachekey=$this->tableName.':simpletree:'.$lang;
		if(!empty($wh)){
			$cachekey.=':wh('.implode(';',$wh).')';
		}
		//Try to get simple tree from internal cache...
		static $cache_simpletree=array();
		if(isset($cache_simpletree[$cachekey])){
			return $cache_simpletree[$cachekey];
			}
		//
		$bcache=\Brilliant\BFactory::getCache();
		if($bcache){
			$res=$bcache->get($cachekey);
			if(($res!==false)&&($res!==NULL)){
				$this->cache_simpletree[$lang]=$res;
				return $res;
				}
			}
		//Load simle cities names.
		if(!$db=\Brilliant\BFactory::getDBO()){return NULL;}
		$qr='SELECT `'.$this->primaryKeyName.'`';
		foreach($fields as $fld){
			$qr.=', `'.$fld.'`';
			}
		foreach($transfields as $fld){
			$qr.=', `'.$fld.'_'.$lang.'` as `'.$fld.'`';
			}
		$qr.=' FROM `'.$this->tableName.'`';
		if(!empty($wh)){
			$qr.=' WHERE ('.implode(' AND ',$wh).')';
			}
		$qr.=' ORDER BY `'.$this->leftKeyName.'`;';
		$q=$db->Query($qr);
		if(empty($q)){
			return $res;
			}
		//
		$res=array();
		while($l=$db->fetch($q)){
			$id=(int)$l[$this->primaryKeyName];
			$val=array();
			$val[$this->primaryKeyName]=$id;
			foreach($fields as $fld){
				$val[$fld]=$l[$fld];
				}
			foreach($transfields as $fld){
				$val[$fld]=$l[$fld];
				}
			$xval=(object)$val;
			$this->getSimpleTreeFilterItem($xval);
			$res[$id]=$xval;
			}
		$this->cache_simpletree[$cachekey]=$res;
		if($bcache){
			$bcache->set($cachekey,$res,3600);//1 hour
			}
		return $res;
		}
1159382
private function getParentNode($parent, $webspaceKey, $languageCode)
    {
        if (null != $parent) {
            return $this->getMapper()->load($parent, $webspaceKey, $languageCode);
        } else {
            return $this->getMapper()->loadStartPage($webspaceKey, $languageCode);
        }
    }
1154108
public function buildMenuFromMenuList( ADT_Tree_Menu_List $list )
	{
		$root	= array(
			array(
				'id' 	=> $this->rootId,
				'level' => 0,
				'label' => $this->rootLabel
			)
		);
		return self::buildLayersRecursive( $list, $this->rootId, $root );
	}
1323389
protected function createTree(&$list, $parent, $level = 1)
    {
        $tree = [];
        foreach ($parent as $l) {
            $l->level = $level;
            if (isset($list[$l->id])) {
                $l->children = $this->createTree($list, $list[$l->id], ++$level);
                $level--;
            }
            $tree[] = $l;
        }

        return $tree;
    }
530155
private function searchTree(int $depth = 0)
    {
        $this->depth = $depth;
        foreach ($this->children->getList() as $node) {
            if ($depth > count($this->treePath)) {
                break;
            }

            if ($this->treePath[$depth] != $node->key) {
                continue;
            }

            /**
             * @var $node TreeNode
             */
            if (count($this->treePath) > $depth && $this->allowedToDiveDeeper($depth)) {
                $node->setTreePath($this->treePath);

                return $node->searchTree(++$depth);
            }
        }

        return $this;
    }
601651
public function loginPage(ServerRequestInterface $request, ?Tree $tree): ResponseInterface
    {
        // Already logged in?
        if (Auth::check()) {
            $ged = $tree !== null ? $tree->name() : '';

            return redirect(route('user-page', ['ged' => $ged]));
        }

        $error    = $request->get('error', '');
        $url      = $request->get('url', '');
        $username = $request->get('username', '');

        $title = I18N::translate('Sign in');

        switch (Site::getPreference('WELCOME_TEXT_AUTH_MODE')) {
            case 1:
            default:
                $welcome = I18N::translate('Anyone with a user account can access this website.');
                break;
            case 2:
                $welcome = I18N::translate('You need to be an authorized user to access this website.');
                break;
            case 3:
                $welcome = I18N::translate('You need to be a family member to access this website.');
                break;
            case 4:
                $welcome = Site::getPreference('WELCOME_TEXT_AUTH_MODE_' . WT_LOCALE);
                break;
        }

        if (Site::getPreference('USE_REGISTRATION_MODULE') === '1') {
            $welcome .= ' ' . I18N::translate('You can apply for an account using the link below.');
        }

        $can_register = Site::getPreference('USE_REGISTRATION_MODULE') === '1';

        return $this->viewResponse('login-page', [
            'can_register' => $can_register,
            'error'        => $error,
            'title'        => $title,
            'url'          => $url,
            'username'     => $username,
            'welcome'      => $welcome,
        ]);
    }
215323
private function getAlteredQueryNode($fieldName, array $values)
    {
        $newNode = new OrNode();
        $defaultLanguageFieldName = $fieldName.'.'.$this->intUtils->getDefaultLanguage();

        foreach ($values as $singleValue) {
            $newNode->addQuery($this->getEqNode($fieldName, $singleValue));
            // search default language field (as new structure only has 'en' set after creation and no save)
            $newNode->addQuery(
                $this->getEqNode(
                    $defaultLanguageFieldName,
                    $singleValue
                )
            );
        }

        // add default match
        $newNode->addQuery($this->getEqNode($this->node->getField(), $this->getNodeValue()));

        if (!$this->nodeFieldNameHasLanguage()) {
            // if no language, we add it to the query to default node for default language
            $newNode->addQuery(
                $this->getEqNode(
                    $defaultLanguageFieldName,
                    $this->getNodeValue()
                )
            );
        }

        return $newNode;
    }
941358
public function menuNodeHierarchy($depth = 10)
    {
        if ($depth == 0) {
            return $this;
        }

        return $this
            ->prototype('array')
                ->children()
                    ->scalarNode('route')->end()
                    ->arrayNode('routeParameters')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->scalarNode('uri')->end()
                    ->scalarNode('label')->end()
                    ->booleanNode('display')->defaultTrue()->end()
                    ->booleanNode('displayChildren')->defaultTrue()->end()
                    ->integerNode('order')->end()
                    ->arrayNode('attributes')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->arrayNode('linkAttributes')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->arrayNode('childrenAttributes')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->arrayNode('labelAttributes')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->arrayNode('roles')
                        ->prototype('scalar')
                        ->end()
                    ->end()
                    ->arrayNode('extras')
                        ->prototype('scalar')
                        ->end()
                    ->end()
                    ->menuNode('children')->menuNodeHierarchy($depth - 1)
                ->end()
            ->end();
    }