xref: /webtrees/app/Module/PlaceHierarchyListModule.php (revision 4c78e066e3ba48f4c71bb900fac88b9e85e97474)
167992b6aSRichard Cissee<?php
23976b470SGreg Roach
367992b6aSRichard Cissee/**
467992b6aSRichard Cissee * webtrees: online genealogy
590949315SGreg Roach * Copyright (C) 2021 webtrees development team
667992b6aSRichard Cissee * This program is free software: you can redistribute it and/or modify
767992b6aSRichard Cissee * it under the terms of the GNU General Public License as published by
867992b6aSRichard Cissee * the Free Software Foundation, either version 3 of the License, or
967992b6aSRichard Cissee * (at your option) any later version.
1067992b6aSRichard Cissee * This program is distributed in the hope that it will be useful,
1167992b6aSRichard Cissee * but WITHOUT ANY WARRANTY; without even the implied warranty of
1267992b6aSRichard Cissee * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1367992b6aSRichard Cissee * GNU General Public License for more details.
1467992b6aSRichard Cissee * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
1667992b6aSRichard Cissee */
17fcfa147eSGreg Roach
1867992b6aSRichard Cisseedeclare(strict_types=1);
1967992b6aSRichard Cissee
2067992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Module;
2167992b6aSRichard Cissee
224b2f1dbbSGreg Roachuse Aura\Router\RouterContainer;
2367992b6aSRichard Cisseeuse Fisharebest\Webtrees\Auth;
244b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
25c8db8a43SGreg Roachuse Fisharebest\Webtrees\Family;
2667992b6aSRichard Cisseeuse Fisharebest\Webtrees\I18N;
27c8db8a43SGreg Roachuse Fisharebest\Webtrees\Individual;
28c8db8a43SGreg Roachuse Fisharebest\Webtrees\Location;
294b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Place;
304b2f1dbbSGreg Roachuse Fisharebest\Webtrees\PlaceLocation;
31c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\Services\LeafletJsService;
324b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
334b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Services\SearchService;
344b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
354b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Statistics;
36*4c78e066SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\CountryService;
375229eadeSGreg Roachuse Fisharebest\Webtrees\Tree;
384b2f1dbbSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
396ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface;
406ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
414b2f1dbbSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
42f3874e19SGreg Roach
434b2f1dbbSGreg Roachuse function array_chunk;
444b2f1dbbSGreg Roachuse function array_pop;
454b2f1dbbSGreg Roachuse function array_reverse;
465229eadeSGreg Roachuse function assert;
474b2f1dbbSGreg Roachuse function ceil;
484b2f1dbbSGreg Roachuse function count;
494b2f1dbbSGreg Roachuse function redirect;
504b2f1dbbSGreg Roachuse function route;
514b2f1dbbSGreg Roachuse function view;
5267992b6aSRichard Cissee
5367992b6aSRichard Cissee/**
5467992b6aSRichard Cissee * Class IndividualListModule
5567992b6aSRichard Cissee */
564b2f1dbbSGreg Roachclass PlaceHierarchyListModule extends AbstractModule implements ModuleListInterface, RequestHandlerInterface
5767992b6aSRichard Cissee{
5867992b6aSRichard Cissee    use ModuleListTrait;
5967992b6aSRichard Cissee
604b2f1dbbSGreg Roach    protected const ROUTE_URL = '/tree/{tree}/place-list';
614b2f1dbbSGreg Roach
624b2f1dbbSGreg Roach    /** @var int The default access level for this module.  It can be changed in the control panel. */
634b2f1dbbSGreg Roach    protected $access_level = Auth::PRIV_USER;
644b2f1dbbSGreg Roach
65c9c6f2ecSGreg Roach    private LeafletJsService $leaflet_js_service;
66c9c6f2ecSGreg Roach
67c9c6f2ecSGreg Roach    private ModuleService $module_service;
68c9c6f2ecSGreg Roach
69c9c6f2ecSGreg Roach    private SearchService $search_service;
704b2f1dbbSGreg Roach
714b2f1dbbSGreg Roach    /**
724b2f1dbbSGreg Roach     * PlaceHierarchy constructor.
734b2f1dbbSGreg Roach     *
74c9c6f2ecSGreg Roach     * @param LeafletJsService $leaflet_js_service
75c9c6f2ecSGreg Roach     * @param ModuleService    $module_service
764b2f1dbbSGreg Roach     * @param SearchService    $search_service
774b2f1dbbSGreg Roach     */
78c9c6f2ecSGreg Roach    public function __construct(LeafletJsService $leaflet_js_service, ModuleService $module_service, SearchService $search_service)
794b2f1dbbSGreg Roach    {
80c9c6f2ecSGreg Roach        $this->leaflet_js_service = $leaflet_js_service;
81c9c6f2ecSGreg Roach        $this->module_service = $module_service;
824b2f1dbbSGreg Roach        $this->search_service     = $search_service;
834b2f1dbbSGreg Roach    }
844b2f1dbbSGreg Roach
854b2f1dbbSGreg Roach    /**
864b2f1dbbSGreg Roach     * Initialization.
874b2f1dbbSGreg Roach     *
884b2f1dbbSGreg Roach     * @return void
894b2f1dbbSGreg Roach     */
904b2f1dbbSGreg Roach    public function boot(): void
914b2f1dbbSGreg Roach    {
924b2f1dbbSGreg Roach        $router_container = app(RouterContainer::class);
934b2f1dbbSGreg Roach        assert($router_container instanceof RouterContainer);
944b2f1dbbSGreg Roach
954b2f1dbbSGreg Roach        $router_container->getMap()
964b2f1dbbSGreg Roach            ->get(static::class, static::ROUTE_URL, $this);
974b2f1dbbSGreg Roach    }
984b2f1dbbSGreg Roach
9967992b6aSRichard Cissee    /**
1000cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
10167992b6aSRichard Cissee     *
10267992b6aSRichard Cissee     * @return string
10367992b6aSRichard Cissee     */
10467992b6aSRichard Cissee    public function title(): string
10567992b6aSRichard Cissee    {
10667992b6aSRichard Cissee        /* I18N: Name of a module/list */
10767992b6aSRichard Cissee        return I18N::translate('Place hierarchy');
10867992b6aSRichard Cissee    }
10967992b6aSRichard Cissee
11067992b6aSRichard Cissee    /**
11167992b6aSRichard Cissee     * A sentence describing what this module does.
11267992b6aSRichard Cissee     *
11367992b6aSRichard Cissee     * @return string
11467992b6aSRichard Cissee     */
11567992b6aSRichard Cissee    public function description(): string
11667992b6aSRichard Cissee    {
1179e0868cbSGreg Roach        /* I18N: Description of the “Place hierarchy” module */
11867992b6aSRichard Cissee        return I18N::translate('The place hierarchy.');
11967992b6aSRichard Cissee    }
12067992b6aSRichard Cissee
12167992b6aSRichard Cissee    /**
12267992b6aSRichard Cissee     * CSS class for the URL.
12367992b6aSRichard Cissee     *
12467992b6aSRichard Cissee     * @return string
12567992b6aSRichard Cissee     */
12667992b6aSRichard Cissee    public function listMenuClass(): string
12767992b6aSRichard Cissee    {
12867992b6aSRichard Cissee        return 'menu-list-plac';
12967992b6aSRichard Cissee    }
13067992b6aSRichard Cissee
1314db4b4a9SGreg Roach    /**
13224f2a3afSGreg Roach     * @return array<string>
1334db4b4a9SGreg Roach     */
13467992b6aSRichard Cissee    public function listUrlAttributes(): array
13567992b6aSRichard Cissee    {
13667992b6aSRichard Cissee        return [];
13767992b6aSRichard Cissee    }
1384b2f1dbbSGreg Roach
1394b2f1dbbSGreg Roach    /**
1404b2f1dbbSGreg Roach     * @param Tree $tree
1414b2f1dbbSGreg Roach     *
1424b2f1dbbSGreg Roach     * @return bool
1434b2f1dbbSGreg Roach     */
1444b2f1dbbSGreg Roach    public function listIsEmpty(Tree $tree): bool
1454b2f1dbbSGreg Roach    {
1464b2f1dbbSGreg Roach        return !DB::table('places')
1474b2f1dbbSGreg Roach            ->where('p_file', '=', $tree->id())
1484b2f1dbbSGreg Roach            ->exists();
1494b2f1dbbSGreg Roach    }
1504b2f1dbbSGreg Roach
1514b2f1dbbSGreg Roach    /**
1524b2f1dbbSGreg Roach     * Handle URLs generated by older versions of webtrees
1534b2f1dbbSGreg Roach     *
1544b2f1dbbSGreg Roach     * @param ServerRequestInterface $request
1554b2f1dbbSGreg Roach     *
1564b2f1dbbSGreg Roach     * @return ResponseInterface
1574b2f1dbbSGreg Roach     */
1584b2f1dbbSGreg Roach    public function getListAction(ServerRequestInterface $request): ResponseInterface
1594b2f1dbbSGreg Roach    {
1604b2f1dbbSGreg Roach        return redirect($this->listUrl($request->getAttribute('tree'), $request->getQueryParams()));
1614b2f1dbbSGreg Roach    }
1624b2f1dbbSGreg Roach
1634b2f1dbbSGreg Roach    /**
164c9c6f2ecSGreg Roach     * @param Tree         $tree
165c9c6f2ecSGreg Roach     * @param array<mixed> $parameters
166c9c6f2ecSGreg Roach     *
167c9c6f2ecSGreg Roach     * @return string
168c9c6f2ecSGreg Roach     */
169c9c6f2ecSGreg Roach    public function listUrl(Tree $tree, array $parameters = []): string
170c9c6f2ecSGreg Roach    {
171c9c6f2ecSGreg Roach        $parameters['tree'] = $tree->name();
172c9c6f2ecSGreg Roach
173c9c6f2ecSGreg Roach        return route(static::class, $parameters);
174c9c6f2ecSGreg Roach    }
175c9c6f2ecSGreg Roach
176c9c6f2ecSGreg Roach    /**
1774b2f1dbbSGreg Roach     * @param ServerRequestInterface $request
1784b2f1dbbSGreg Roach     *
1794b2f1dbbSGreg Roach     * @return ResponseInterface
1804b2f1dbbSGreg Roach     */
1814b2f1dbbSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
1824b2f1dbbSGreg Roach    {
1834b2f1dbbSGreg Roach        $tree = $request->getAttribute('tree');
1844b2f1dbbSGreg Roach        assert($tree instanceof Tree);
1854b2f1dbbSGreg Roach
1864b2f1dbbSGreg Roach        $user = $request->getAttribute('user');
1874b2f1dbbSGreg Roach        assert($user instanceof UserInterface);
1884b2f1dbbSGreg Roach
1894b2f1dbbSGreg Roach        Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user);
1904b2f1dbbSGreg Roach
1914b2f1dbbSGreg Roach        $action2  = $request->getQueryParams()['action2'] ?? 'hierarchy';
1924b2f1dbbSGreg Roach        $place_id = (int) ($request->getQueryParams()['place_id'] ?? 0);
1934b2f1dbbSGreg Roach        $place    = Place::find($place_id, $tree);
1944b2f1dbbSGreg Roach
1954b2f1dbbSGreg Roach        // Request for a non-existent place?
1964b2f1dbbSGreg Roach        if ($place_id !== $place->id()) {
1974b2f1dbbSGreg Roach            return redirect($place->url());
1984b2f1dbbSGreg Roach        }
1994b2f1dbbSGreg Roach
200c9c6f2ecSGreg Roach        $map_providers = $this->module_service->findByInterface(ModuleMapProviderInterface::class);
201c9c6f2ecSGreg Roach
2024b2f1dbbSGreg Roach        $content = '';
203c9c6f2ecSGreg Roach        $showmap = $map_providers->isNotEmpty();
2044b2f1dbbSGreg Roach        $data    = null;
2054b2f1dbbSGreg Roach
2064b2f1dbbSGreg Roach        if ($showmap) {
2074b2f1dbbSGreg Roach            $content .= view('modules/place-hierarchy/map', [
2084b2f1dbbSGreg Roach                'data'           => $this->mapData($tree, $place),
209c9c6f2ecSGreg Roach                'leaflet_config' => $this->leaflet_js_service->config(),
2104b2f1dbbSGreg Roach            ]);
2114b2f1dbbSGreg Roach        }
2124b2f1dbbSGreg Roach
2134b2f1dbbSGreg Roach        switch ($action2) {
2144b2f1dbbSGreg Roach            case 'list':
2154b2f1dbbSGreg Roach            default:
2164b2f1dbbSGreg Roach                $alt_link = I18N::translate('Show place hierarchy');
2174b2f1dbbSGreg Roach                $alt_url  = $this->listUrl($tree, ['action2' => 'hierarchy', 'place_id' => $place_id]);
2184b2f1dbbSGreg Roach                $content  .= view('modules/place-hierarchy/list', ['columns' => $this->getList($tree)]);
2194b2f1dbbSGreg Roach                break;
2204b2f1dbbSGreg Roach            case 'hierarchy':
2214b2f1dbbSGreg Roach            case 'hierarchy-e':
2224b2f1dbbSGreg Roach                $alt_link = I18N::translate('Show all places in a list');
2234b2f1dbbSGreg Roach                $alt_url  = $this->listUrl($tree, ['action2' => 'list', 'place_id' => 0]);
2244b2f1dbbSGreg Roach                $data     = $this->getHierarchy($place);
2254b2f1dbbSGreg Roach                $content  .= (null === $data || $showmap) ? '' : view('place-hierarchy', $data);
2264b2f1dbbSGreg Roach                if (null === $data || $action2 === 'hierarchy-e') {
2274b2f1dbbSGreg Roach                    $content .= view('modules/place-hierarchy/events', [
2284b2f1dbbSGreg Roach                        'indilist' => $this->search_service->searchIndividualsInPlace($place),
2294b2f1dbbSGreg Roach                        'famlist'  => $this->search_service->searchFamiliesInPlace($place),
2304b2f1dbbSGreg Roach                        'tree'     => $place->tree(),
2314b2f1dbbSGreg Roach                    ]);
2324b2f1dbbSGreg Roach                }
2334b2f1dbbSGreg Roach        }
2344b2f1dbbSGreg Roach
2354b2f1dbbSGreg Roach        if ($data !== null && $action2 !== 'hierarchy-e' && $place->gedcomName() !== '') {
2364b2f1dbbSGreg Roach            $events_link = $this->listUrl($tree, ['action2' => 'hierarchy-e', 'place_id' => $place_id]);
2374b2f1dbbSGreg Roach        } else {
2384b2f1dbbSGreg Roach            $events_link = '';
2394b2f1dbbSGreg Roach        }
2404b2f1dbbSGreg Roach
2414b2f1dbbSGreg Roach        $breadcrumbs = $this->breadcrumbs($place);
2424b2f1dbbSGreg Roach
2434b2f1dbbSGreg Roach        return $this->viewResponse('modules/place-hierarchy/page', [
2444b2f1dbbSGreg Roach            'alt_link'    => $alt_link,
2454b2f1dbbSGreg Roach            'alt_url'     => $alt_url,
2464b2f1dbbSGreg Roach            'breadcrumbs' => $breadcrumbs['breadcrumbs'],
2474b2f1dbbSGreg Roach            'content'     => $content,
2484b2f1dbbSGreg Roach            'current'     => $breadcrumbs['current'],
2494b2f1dbbSGreg Roach            'events_link' => $events_link,
2504b2f1dbbSGreg Roach            'place'       => $place,
2514b2f1dbbSGreg Roach            'title'       => I18N::translate('Place hierarchy'),
2524b2f1dbbSGreg Roach            'tree'        => $tree,
253c9c6f2ecSGreg Roach            'world_url'   => $this->listUrl($tree),
2544b2f1dbbSGreg Roach        ]);
2554b2f1dbbSGreg Roach    }
2564b2f1dbbSGreg Roach
2574b2f1dbbSGreg Roach    /**
2584b2f1dbbSGreg Roach     * @param Tree  $tree
2594b2f1dbbSGreg Roach     * @param Place $placeObj
2604b2f1dbbSGreg Roach     *
2614b2f1dbbSGreg Roach     * @return array<mixed>
2624b2f1dbbSGreg Roach     */
2634b2f1dbbSGreg Roach    protected function mapData(Tree $tree, Place $placeObj): array
2644b2f1dbbSGreg Roach    {
2654b2f1dbbSGreg Roach        $places    = $placeObj->getChildPlaces();
2664b2f1dbbSGreg Roach        $features  = [];
2674b2f1dbbSGreg Roach        $sidebar   = '';
2684b2f1dbbSGreg Roach        $show_link = true;
2694b2f1dbbSGreg Roach
2704b2f1dbbSGreg Roach        if ($places === []) {
2714b2f1dbbSGreg Roach            $places[]  = $placeObj;
2724b2f1dbbSGreg Roach            $show_link = false;
2734b2f1dbbSGreg Roach        }
2744b2f1dbbSGreg Roach
2754b2f1dbbSGreg Roach        foreach ($places as $id => $place) {
2764b2f1dbbSGreg Roach            $location = new PlaceLocation($place->gedcomName());
2774b2f1dbbSGreg Roach
27890949315SGreg Roach            if ($location->latitude() === null || $location->longitude() === null) {
2794b2f1dbbSGreg Roach                $sidebar_class = 'unmapped';
2804b2f1dbbSGreg Roach            } else {
2814b2f1dbbSGreg Roach                $sidebar_class = 'mapped';
2824b2f1dbbSGreg Roach                $features[]    = [
2834b2f1dbbSGreg Roach                    'type'       => 'Feature',
2844b2f1dbbSGreg Roach                    'id'         => $id,
2854b2f1dbbSGreg Roach                    'geometry'   => [
2864b2f1dbbSGreg Roach                        'type'        => 'Point',
2874b2f1dbbSGreg Roach                        'coordinates' => [$location->longitude(), $location->latitude()],
2884b2f1dbbSGreg Roach                    ],
2894b2f1dbbSGreg Roach                    'properties' => [
2904b2f1dbbSGreg Roach                        'tooltip' => $place->gedcomName(),
2914b2f1dbbSGreg Roach                        'popup'   => view('modules/place-hierarchy/popup', [
2924b2f1dbbSGreg Roach                            'showlink'  => $show_link,
2934b2f1dbbSGreg Roach                            'place'     => $place,
2944b2f1dbbSGreg Roach                            'latitude'  => $location->latitude(),
2954b2f1dbbSGreg Roach                            'longitude' => $location->longitude(),
2964b2f1dbbSGreg Roach                        ]),
2974b2f1dbbSGreg Roach                    ],
2984b2f1dbbSGreg Roach                ];
2994b2f1dbbSGreg Roach            }
3004b2f1dbbSGreg Roach
301*4c78e066SGreg Roach            $statistics = new Statistics(app(CountryService::class), app(ModuleService::class), $tree, app(UserService::class));
3024b2f1dbbSGreg Roach
3034b2f1dbbSGreg Roach            //Stats
304c8db8a43SGreg Roach            $stats = [];
305c8db8a43SGreg Roach            foreach ([Individual::RECORD_TYPE, Family::RECORD_TYPE, Location::RECORD_TYPE] as $type) {
3064b2f1dbbSGreg Roach                $tmp          = $statistics->statsPlaces($type, '', $place->id());
307c8db8a43SGreg Roach                $stats[$type] = $tmp === [] ? 0 : $tmp[0]->tot;
3084b2f1dbbSGreg Roach            }
3094b2f1dbbSGreg Roach            $sidebar .= view('modules/place-hierarchy/sidebar', [
3104b2f1dbbSGreg Roach                'showlink'      => $show_link,
3114b2f1dbbSGreg Roach                'id'            => $id,
3124b2f1dbbSGreg Roach                'place'         => $place,
3134b2f1dbbSGreg Roach                'sidebar_class' => $sidebar_class,
314c8db8a43SGreg Roach                'stats'         => $stats,
3154b2f1dbbSGreg Roach            ]);
3164b2f1dbbSGreg Roach        }
3174b2f1dbbSGreg Roach
3184b2f1dbbSGreg Roach        return [
3194b2f1dbbSGreg Roach            'bounds'  => (new PlaceLocation($placeObj->gedcomName()))->boundingRectangle(),
3204b2f1dbbSGreg Roach            'sidebar' => $sidebar,
3214b2f1dbbSGreg Roach            'markers' => [
3224b2f1dbbSGreg Roach                'type'     => 'FeatureCollection',
3234b2f1dbbSGreg Roach                'features' => $features,
324c9c6f2ecSGreg Roach            ],
325c9c6f2ecSGreg Roach        ];
326c9c6f2ecSGreg Roach    }
327c9c6f2ecSGreg Roach
328c9c6f2ecSGreg Roach    /**
329c9c6f2ecSGreg Roach     * @param Tree $tree
330c9c6f2ecSGreg Roach     *
331c9c6f2ecSGreg Roach     * @return array<array<Place>>
332c9c6f2ecSGreg Roach     */
333c9c6f2ecSGreg Roach    private function getList(Tree $tree): array
334c9c6f2ecSGreg Roach    {
335c9c6f2ecSGreg Roach        $places = $this->search_service->searchPlaces($tree, '')
336c9c6f2ecSGreg Roach            ->sort(static function (Place $x, Place $y): int {
337c9c6f2ecSGreg Roach                return $x->gedcomName() <=> $y->gedcomName();
338c9c6f2ecSGreg Roach            })
339c9c6f2ecSGreg Roach            ->all();
340c9c6f2ecSGreg Roach
341c9c6f2ecSGreg Roach        $count = count($places);
342c9c6f2ecSGreg Roach
343c9c6f2ecSGreg Roach        if ($places === []) {
344c9c6f2ecSGreg Roach            return [];
345c9c6f2ecSGreg Roach        }
346c9c6f2ecSGreg Roach
347c9c6f2ecSGreg Roach        $columns = $count > 20 ? 3 : 2;
348c9c6f2ecSGreg Roach
349c9c6f2ecSGreg Roach        return array_chunk($places, (int) ceil($count / $columns));
350c9c6f2ecSGreg Roach    }
351c9c6f2ecSGreg Roach
352c9c6f2ecSGreg Roach    /**
353c9c6f2ecSGreg Roach     * @param Place $place
354c9c6f2ecSGreg Roach     *
355c9c6f2ecSGreg Roach     * @return array{'tree':Tree,'col_class':string,'columns':array<array<Place>>,'place':Place}|null
356c9c6f2ecSGreg Roach     */
357c9c6f2ecSGreg Roach    private function getHierarchy(Place $place): ?array
358c9c6f2ecSGreg Roach    {
359c9c6f2ecSGreg Roach        $child_places = $place->getChildPlaces();
360c9c6f2ecSGreg Roach        $numfound     = count($child_places);
361c9c6f2ecSGreg Roach
362c9c6f2ecSGreg Roach        if ($numfound > 0) {
363c9c6f2ecSGreg Roach            $divisor = $numfound > 20 ? 3 : 2;
364c9c6f2ecSGreg Roach
365c9c6f2ecSGreg Roach            return [
366c9c6f2ecSGreg Roach                'tree'      => $place->tree(),
367c9c6f2ecSGreg Roach                'col_class' => 'w-' . ($divisor === 2 ? '25' : '50'),
368c9c6f2ecSGreg Roach                'columns'   => array_chunk($child_places, (int) ceil($numfound / $divisor)),
369c9c6f2ecSGreg Roach                'place'     => $place,
370c9c6f2ecSGreg Roach            ];
371c9c6f2ecSGreg Roach        }
372c9c6f2ecSGreg Roach
373c9c6f2ecSGreg Roach        return null;
374c9c6f2ecSGreg Roach    }
375c9c6f2ecSGreg Roach
376c9c6f2ecSGreg Roach    /**
377c9c6f2ecSGreg Roach     * @param Place $place
378c9c6f2ecSGreg Roach     *
379c9c6f2ecSGreg Roach     * @return array{'breadcrumbs':array<Place>,'current':Place|null}
380c9c6f2ecSGreg Roach     */
381c9c6f2ecSGreg Roach    private function breadcrumbs(Place $place): array
382c9c6f2ecSGreg Roach    {
383c9c6f2ecSGreg Roach        $breadcrumbs = [];
384c9c6f2ecSGreg Roach        if ($place->gedcomName() !== '') {
385c9c6f2ecSGreg Roach            $breadcrumbs[] = $place;
386c9c6f2ecSGreg Roach            $parent_place  = $place->parent();
387c9c6f2ecSGreg Roach            while ($parent_place->gedcomName() !== '') {
388c9c6f2ecSGreg Roach                $breadcrumbs[] = $parent_place;
389c9c6f2ecSGreg Roach                $parent_place  = $parent_place->parent();
390c9c6f2ecSGreg Roach            }
391c9c6f2ecSGreg Roach            $breadcrumbs = array_reverse($breadcrumbs);
392c9c6f2ecSGreg Roach            $current     = array_pop($breadcrumbs);
393c9c6f2ecSGreg Roach        } else {
394c9c6f2ecSGreg Roach            $current = null;
395c9c6f2ecSGreg Roach        }
396c9c6f2ecSGreg Roach
397c9c6f2ecSGreg Roach        return [
398c9c6f2ecSGreg Roach            'breadcrumbs' => $breadcrumbs,
399c9c6f2ecSGreg Roach            'current'     => $current,
4004b2f1dbbSGreg Roach        ];
4014b2f1dbbSGreg Roach    }
40267992b6aSRichard Cissee}
403