A menu, to be added to the main application menu.

@param Tree $tree

@return Menu|null
772201
public function getMenu(Tree $tree): ?Menu
    {
        $request    = app(ServerRequestInterface::class);
        $xref       = $request->getQueryParams()['xref'] ?? '';
        $individual = Individual::getInstance($xref, $tree) ?? $tree->significantIndividual(Auth::user());
        $submenus   = $this->module_service->findByComponent(ModuleReportInterface::class, $tree, Auth::user())
            ->map(static function (ModuleReportInterface $module) use ($individual): Menu {
                return $module->getReportMenu($individual);
            });

        if ($submenus->isEmpty()) {
            return null;
        }

        return new Menu(I18N::translate('Reports'), '#', 'menu-report', ['rel' => 'nofollow'], $submenus->all());
    }
736745
public function actionTree()
    {
        $tree = DpAdminMenu::getAccessTreeByParentId($this->identity->is_super, $this->menuIdList, null, [
            'is_hide' => 0,
        ]);

        return [
            'children' => $tree,
        ];
    }
921455
public function treePageUpdate(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $defaults = (bool) $request->get('defaults');

        if ($defaults) {
            $main_blocks = $this->treeBlocks(-1, 'main')->all();
            $side_blocks = $this->treeBlocks(-1, 'side')->all();
        } else {
            $main_blocks = (array) $request->get('main');
            $side_blocks = (array) $request->get('side');
        }

        $this->updateTreeBlocks($tree->id(), $main_blocks, $side_blocks);

        return redirect(route('tree-page', ['ged' => $tree->name()]));
    }
732126
private function treeOutput(TreeBase $tree, Menu $menu = null)
    {
        $items = [];

        foreach ($tree->getChildren() as $item) {
            $element = [];

            $input = [
                '#prefix'         => '<div class="tree-item clearfix">',
                '#type'           => 'textfield',
                '#attributes'     => ['class' => ['']],
                '#value'          => $item->getTitle(),
                '#theme_wrappers' => [],
                '#suffix'         => '<span class="fa fa-times"></span></div>',
            ];

            $element['data']            = drupal_render($input);
            $element['data-item-type']  = 'node';
            $element['data-item-id']    = $item->getNodeId();
            $element['data-mlid']       = $item->getId();

            if ($item->hasChildren()) {
                $elements = $this->treeOutput($item);
                $element['data'] .= drupal_render($elements);
            }

            $items[] = $element;
        }

        $build = [
            '#theme' => 'item_list',
            '#type'  => 'ol',
            '#items' => $items,
        ];

        if ($menu) {
            $build['#attributes'] = [
                'data-menu' => $menu->getName(),
                'class'     => ['sortable'],
            ];
            $build['#title'] = $menu->getTitle();

            // If tree has no children, add an empty element to allow drop.
            if (!$tree->hasChildren()) {
                $build['#items'] = [' '];
            }
        }

        return $build;
    }
1172997
public function menuControlPanel(Tree $tree): ?Menu
    {
        if (Auth::isAdmin()) {
            return new Menu(I18N::translate('Control panel'), route('admin-control-panel'), 'menu-admin');
        }

        if (Auth::isManager($tree)) {
            return new Menu(I18N::translate('Control panel'), route('admin-control-panel-manager'), 'menu-admin');
        }

        return null;
    }
352548
public function findBranchByNodeId(Branch $tree, $nodeId)
    {
        foreach ($tree->getChildren() as $branch) {
            if ($branch->getNodeId() == $nodeId) {
                return $branch;
            }

            // recursive search:
            $branch = $this->findBranchByNodeId($branch, $nodeId);
            if ($branch) {
                return $branch;
            }
        }

        return null;
    }
944217
public function render_tree(tree $tree) {
        $return = \html_writer::start_tag('div', array('class' => 'profile_tree'));
        $categories = $tree->categories;
        foreach ($categories as $category) {
            $return .= $this->render($category);
        }
        $return .= \html_writer::end_tag('div');
        return $return;
    }
133896
public function repositoryList(Tree $tree): ResponseInterface
    {
        $repositories = $this->allRepositories($tree);

        return $this->viewResponse('repository-list-page', [
            'repositories' => $repositories,
            'title'        => I18N::translate('Repositories'),
        ]);
    }
14063
public function getMenu(Tree $tree): ?Menu
    {
        $submenus = $this->module_service->findByComponent(ModuleListInterface::class, $tree, Auth::user())
            ->map(static function (ModuleListInterface $module) use ($tree): ?Menu {
                return $module->listMenu($tree);
            })
            ->filter()
            ->sort(static function (Menu $x, Menu $y) {
                return $x->getLabel() <=> $y->getLabel();
            });

        if ($submenus->isEmpty()) {
            return null;
        }

        return new Menu(I18N::translate('Lists'), '#', 'menu-list', [], $submenus->all());
    }
286876
public function getMenu(Tree $tree): ?Menu
    {
        $submenu = [
            $this->menuSearchGeneral($tree),
            $this->menuSearchPhonetic($tree),
            $this->menuSearchAdvanced($tree),
            $this->menuSearchAndReplace($tree),
        ];

        $submenu = array_filter($submenu);

        return new Menu(I18N::translate('Search'), '#', 'menu-search', ['rel' => 'nofollow'], $submenu);
    }
435480
protected function bootstrapBreadcrumbs(NavigationTree $tree) {

        $attributes = [];

        $attributes["class"] = ["breadcrumb"];

        $innerHTML = [];

        $nodes = NavigationTreeHelper::getBreadcrumbs($tree);
        $count = count($nodes);

        for ($i = 0; $i < $count; ++$i) {
            $innerHTML[] = $this->bootstrapBreadcrumb($nodes[$i], $count === $i + 1);
        }

        return static::coreHTMLElement("ol", "\n" . implode("\n", $innerHTML) . "\n", $attributes);
    }
948965
protected function buildTree(array $simpleTree, $tree = [])
    {
        foreach ($simpleTree as $item) {
            if (!isset($this->collection[$item['id']])) {
                continue;
            }

            $content = $this->collection[$item['id']];

            unset($this->collection[$item['id']]); // TODO Fix multi-usage of single item

            if (isset($item['__children']) && count($item['__children'])) {
                $content['__children'] = $this->buildTree($item['__children']);
            } else {
                $content['__children'] = [];
            }

            $tree[] = $content;
        }

        return $tree;
    }
69094
public function importLocationsFromTree(Tree $tree): ResponseInterface
    {
        // Get all the places from the places table ...
        $places = DB::table('places AS p0')
            ->leftJoin('places AS p1', 'p1.p_id', '=', 'p0.p_parent_id')
            ->leftJoin('places AS p2', 'p2.p_id', '=', 'p1.p_parent_id')
            ->leftJoin('places AS p3', 'p3.p_id', '=', 'p2.p_parent_id')
            ->leftJoin('places AS p4', 'p4.p_id', '=', 'p3.p_parent_id')
            ->leftJoin('places AS p5', 'p5.p_id', '=', 'p4.p_parent_id')
            ->leftJoin('places AS p6', 'p6.p_id', '=', 'p5.p_parent_id')
            ->leftJoin('places AS p7', 'p7.p_id', '=', 'p6.p_parent_id')
            ->leftJoin('places AS p8', 'p8.p_id', '=', 'p7.p_parent_id')
            ->where('p0.p_file', '=', $tree->id())
            ->select([
                'p0.p_place AS place0',
                'p1.p_place AS place1',
                'p2.p_place AS place2',
                'p3.p_place AS place3',
                'p4.p_place AS place4',
                'p5.p_place AS place5',
                'p6.p_place AS place6',
                'p7.p_place AS place7',
                'p8.p_place AS place8',
            ])
            ->get()
            ->map(static function (stdClass $row): string {
                return implode(', ', array_filter((array) $row));
            });

        // ... and the placelocation table
        $locations = DB::table('placelocation AS p0')
            ->leftJoin('placelocation AS p1', 'p1.pl_id', '=', 'p0.pl_parent_id')
            ->leftJoin('placelocation AS p2', 'p2.pl_id', '=', 'p1.pl_parent_id')
            ->leftJoin('placelocation AS p3', 'p3.pl_id', '=', 'p2.pl_parent_id')
            ->leftJoin('placelocation AS p4', 'p4.pl_id', '=', 'p3.pl_parent_id')
            ->leftJoin('placelocation AS p5', 'p5.pl_id', '=', 'p4.pl_parent_id')
            ->leftJoin('placelocation AS p6', 'p6.pl_id', '=', 'p5.pl_parent_id')
            ->leftJoin('placelocation AS p7', 'p7.pl_id', '=', 'p6.pl_parent_id')
            ->leftJoin('placelocation AS p8', 'p8.pl_id', '=', 'p7.pl_parent_id')
            ->select([
                'p0.pl_id',
                'p0.pl_place AS place0',
                'p1.pl_place AS place1',
                'p2.pl_place AS place2',
                'p3.pl_place AS place3',
                'p4.pl_place AS place4',
                'p5.pl_place AS place5',
                'p6.pl_place AS place6',
                'p7.pl_place AS place7',
                'p8.pl_place AS place8',
            ])
            ->get()
            ->map(static function (stdClass $row): stdClass {
                $row->place = implode(', ', array_filter(array_slice((array) $row, 1)));

                return $row;
            })
            ->pluck('place', 'pl_id');

        // Compare the two ...
        $diff = $places->diff($locations);

        // ... and process the differences
        $inserted = 0;
        if ($diff->isNotEmpty()) {
            $nextRecordId = 1 + (int) DB::table('placelocation')->max('pl_id');

            foreach ($diff as $place) {
                // For Westminster, London, England, we must also create England and London, England
                $place_parts = explode(', ', $place);
                $count       = count($place_parts);

                try {
                    $parent_id = 0;
                    for ($i = $count - 1; $i >= 0; $i--) {
                        $parent   = implode(', ', array_slice($place_parts, $i));
                        $place_id = $locations->search($parent);

                        if ($place_id === false) {
                            DB::table('placelocation')->insert([
                                'pl_id'        => $nextRecordId,
                                'pl_parent_id' => $parent_id,
                                'pl_level'     => $count - $i,
                                'pl_place'     => $place_parts[$i],
                            ]);

                            $parent_id             = $nextRecordId;
                            $locations[$parent_id] = $parent;
                            $inserted++;
                            $nextRecordId++;
                        } else {
                            $parent_id = $place_id;
                        }
                    }
                } catch (QueryException $ex) {
                    // Duplicates are expected due to collation differences.  e.g. Quebec / Québec
                }
            }
        }

        FlashMessages::addMessage(I18N::plural('%s location has been imported.', '%s locations have been imported.', $inserted, I18N::number($inserted)), 'success');

        $url = route('map-data');

        return redirect($url);
    }
595989
public function menu()
    {
        if (!empty($this->menu)) {
            return $this->menu;
        }

        $menuModel = config('admin.database.menu_model');

        return $this->menu = (new $menuModel())->toTree();
    }
549912
protected function fillTreeNodesForItems($tree, $nodes)
    {
        foreach ($tree as $key => $item) {
            $tree[$key]['node'] = $nodes[$item['id']] ?? null;

            $tree[$key]['__children'] = $this->fillTreeNodesForItems($tree[$key]['__children'], $nodes);
        }

        return $tree;
    }
620625
public function addUnlinkedAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $this->glevels = $request->get('glevels', []);
        $this->tag     = $request->get('tag', []);
        $this->text    = $request->get('text', []);
        $this->islink  = $request->get('islink', []);

        $this->splitSource();
        $gedrec = '0 @@ INDI';
        $gedrec .= $this->addNewName($request, $tree);
        $gedrec .= $this->addNewSex($request);
        if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
            foreach ($matches[1] as $match) {
                $gedrec .= $this->addNewFact($request, $tree, $match);
            }
        }
        if ((bool) $request->get('SOUR_INDI')) {
            $gedrec = $this->handleUpdates($gedrec);
        } else {
            $gedrec = $this->updateRest($gedrec);
        }

        $new_indi = $tree->createIndividual($gedrec);

        if ($request->get('goto') === 'new') {
            return redirect($new_indi->url());
        }

        return redirect(route('admin-trees', ['ged' => $tree->name()]));
    }
245354
protected function parseRecursive( $root, $tree )
	{
		$nodes = array();
		if( $child = $root->firstChild )
		{
			while( $child )
			{
				$attributes	= $child->hasAttributes()? $child->attributes : array();
				switch( $child->nodeType )
				{
					case XML_ELEMENT_NODE:
						$node = new XML_DOM_Node( $child->nodeName );
						if( !$this->parseRecursive( $child, $node ) )
						{
	#						$node->setContent( utf8_decode( $child->textContent ) );
							$node->setContent( $child->textContent );
						}
						foreach( $attributes as $attribute)
							$node->setAttribute( $attribute->nodeName, stripslashes( $attribute->nodeValue ) );
						$tree->addChild( $node );
						break;
					case XML_TEXT_NODE:
						if( strlen( trim( $content = $child->textContent ) ) )
						{
							return false;
						}
						else if( isset( $attributes['type'] ) && preg_match( "/.*ml/i", $attributes['type'] ) )
						{
							return false;
						}
						break;
					case XML_CDATA_SECTION_NODE:
						$tree->setContent( stripslashes( $child->textContent ) );
						break;
					default:
						break;
				}
				$child = $child->nextSibling;
			}
		}
		return true;
	}