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*f78da678SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\CenturyService; 37*f78da678SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\ColorService; 384c78e066SGreg Roachuse Fisharebest\Webtrees\Statistics\Service\CountryService; 395229eadeSGreg Roachuse Fisharebest\Webtrees\Tree; 404b2f1dbbSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 416ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 426ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 434b2f1dbbSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 44f3874e19SGreg Roach 45*f78da678SGreg Roachuse function app; 464b2f1dbbSGreg Roachuse function array_chunk; 474b2f1dbbSGreg Roachuse function array_pop; 484b2f1dbbSGreg Roachuse function array_reverse; 495229eadeSGreg Roachuse function assert; 504b2f1dbbSGreg Roachuse function ceil; 514b2f1dbbSGreg Roachuse function count; 524b2f1dbbSGreg Roachuse function redirect; 534b2f1dbbSGreg Roachuse function route; 544b2f1dbbSGreg Roachuse function view; 5567992b6aSRichard Cissee 5667992b6aSRichard Cissee/** 5767992b6aSRichard Cissee * Class IndividualListModule 5867992b6aSRichard Cissee */ 594b2f1dbbSGreg Roachclass PlaceHierarchyListModule extends AbstractModule implements ModuleListInterface, RequestHandlerInterface 6067992b6aSRichard Cissee{ 6167992b6aSRichard Cissee use ModuleListTrait; 6267992b6aSRichard Cissee 634b2f1dbbSGreg Roach protected const ROUTE_URL = '/tree/{tree}/place-list'; 644b2f1dbbSGreg Roach 654b2f1dbbSGreg Roach /** @var int The default access level for this module. It can be changed in the control panel. */ 664b2f1dbbSGreg Roach protected $access_level = Auth::PRIV_USER; 674b2f1dbbSGreg Roach 68c9c6f2ecSGreg Roach private LeafletJsService $leaflet_js_service; 69c9c6f2ecSGreg Roach 70c9c6f2ecSGreg Roach private ModuleService $module_service; 71c9c6f2ecSGreg Roach 72c9c6f2ecSGreg Roach private SearchService $search_service; 734b2f1dbbSGreg Roach 744b2f1dbbSGreg Roach /** 754b2f1dbbSGreg Roach * PlaceHierarchy constructor. 764b2f1dbbSGreg Roach * 77c9c6f2ecSGreg Roach * @param LeafletJsService $leaflet_js_service 78c9c6f2ecSGreg Roach * @param ModuleService $module_service 794b2f1dbbSGreg Roach * @param SearchService $search_service 804b2f1dbbSGreg Roach */ 81c9c6f2ecSGreg Roach public function __construct(LeafletJsService $leaflet_js_service, ModuleService $module_service, SearchService $search_service) 824b2f1dbbSGreg Roach { 83c9c6f2ecSGreg Roach $this->leaflet_js_service = $leaflet_js_service; 84c9c6f2ecSGreg Roach $this->module_service = $module_service; 854b2f1dbbSGreg Roach $this->search_service = $search_service; 864b2f1dbbSGreg Roach } 874b2f1dbbSGreg Roach 884b2f1dbbSGreg Roach /** 894b2f1dbbSGreg Roach * Initialization. 904b2f1dbbSGreg Roach * 914b2f1dbbSGreg Roach * @return void 924b2f1dbbSGreg Roach */ 934b2f1dbbSGreg Roach public function boot(): void 944b2f1dbbSGreg Roach { 954b2f1dbbSGreg Roach $router_container = app(RouterContainer::class); 964b2f1dbbSGreg Roach assert($router_container instanceof RouterContainer); 974b2f1dbbSGreg Roach 984b2f1dbbSGreg Roach $router_container->getMap() 994b2f1dbbSGreg Roach ->get(static::class, static::ROUTE_URL, $this); 1004b2f1dbbSGreg Roach } 1014b2f1dbbSGreg Roach 10267992b6aSRichard Cissee /** 1030cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 10467992b6aSRichard Cissee * 10567992b6aSRichard Cissee * @return string 10667992b6aSRichard Cissee */ 10767992b6aSRichard Cissee public function title(): string 10867992b6aSRichard Cissee { 10967992b6aSRichard Cissee /* I18N: Name of a module/list */ 11067992b6aSRichard Cissee return I18N::translate('Place hierarchy'); 11167992b6aSRichard Cissee } 11267992b6aSRichard Cissee 11367992b6aSRichard Cissee /** 11467992b6aSRichard Cissee * A sentence describing what this module does. 11567992b6aSRichard Cissee * 11667992b6aSRichard Cissee * @return string 11767992b6aSRichard Cissee */ 11867992b6aSRichard Cissee public function description(): string 11967992b6aSRichard Cissee { 1209e0868cbSGreg Roach /* I18N: Description of the “Place hierarchy” module */ 12167992b6aSRichard Cissee return I18N::translate('The place hierarchy.'); 12267992b6aSRichard Cissee } 12367992b6aSRichard Cissee 12467992b6aSRichard Cissee /** 12567992b6aSRichard Cissee * CSS class for the URL. 12667992b6aSRichard Cissee * 12767992b6aSRichard Cissee * @return string 12867992b6aSRichard Cissee */ 12967992b6aSRichard Cissee public function listMenuClass(): string 13067992b6aSRichard Cissee { 13167992b6aSRichard Cissee return 'menu-list-plac'; 13267992b6aSRichard Cissee } 13367992b6aSRichard Cissee 1344db4b4a9SGreg Roach /** 13524f2a3afSGreg Roach * @return array<string> 1364db4b4a9SGreg Roach */ 13767992b6aSRichard Cissee public function listUrlAttributes(): array 13867992b6aSRichard Cissee { 13967992b6aSRichard Cissee return []; 14067992b6aSRichard Cissee } 1414b2f1dbbSGreg Roach 1424b2f1dbbSGreg Roach /** 1434b2f1dbbSGreg Roach * @param Tree $tree 1444b2f1dbbSGreg Roach * 1454b2f1dbbSGreg Roach * @return bool 1464b2f1dbbSGreg Roach */ 1474b2f1dbbSGreg Roach public function listIsEmpty(Tree $tree): bool 1484b2f1dbbSGreg Roach { 1494b2f1dbbSGreg Roach return !DB::table('places') 1504b2f1dbbSGreg Roach ->where('p_file', '=', $tree->id()) 1514b2f1dbbSGreg Roach ->exists(); 1524b2f1dbbSGreg Roach } 1534b2f1dbbSGreg Roach 1544b2f1dbbSGreg Roach /** 1554b2f1dbbSGreg Roach * Handle URLs generated by older versions of webtrees 1564b2f1dbbSGreg Roach * 1574b2f1dbbSGreg Roach * @param ServerRequestInterface $request 1584b2f1dbbSGreg Roach * 1594b2f1dbbSGreg Roach * @return ResponseInterface 1604b2f1dbbSGreg Roach */ 1614b2f1dbbSGreg Roach public function getListAction(ServerRequestInterface $request): ResponseInterface 1624b2f1dbbSGreg Roach { 1634b2f1dbbSGreg Roach return redirect($this->listUrl($request->getAttribute('tree'), $request->getQueryParams())); 1644b2f1dbbSGreg Roach } 1654b2f1dbbSGreg Roach 1664b2f1dbbSGreg Roach /** 167c9c6f2ecSGreg Roach * @param Tree $tree 168c9c6f2ecSGreg Roach * @param array<mixed> $parameters 169c9c6f2ecSGreg Roach * 170c9c6f2ecSGreg Roach * @return string 171c9c6f2ecSGreg Roach */ 172c9c6f2ecSGreg Roach public function listUrl(Tree $tree, array $parameters = []): string 173c9c6f2ecSGreg Roach { 174c9c6f2ecSGreg Roach $parameters['tree'] = $tree->name(); 175c9c6f2ecSGreg Roach 176c9c6f2ecSGreg Roach return route(static::class, $parameters); 177c9c6f2ecSGreg Roach } 178c9c6f2ecSGreg Roach 179c9c6f2ecSGreg Roach /** 1804b2f1dbbSGreg Roach * @param ServerRequestInterface $request 1814b2f1dbbSGreg Roach * 1824b2f1dbbSGreg Roach * @return ResponseInterface 1834b2f1dbbSGreg Roach */ 1844b2f1dbbSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 1854b2f1dbbSGreg Roach { 1864b2f1dbbSGreg Roach $tree = $request->getAttribute('tree'); 1874b2f1dbbSGreg Roach assert($tree instanceof Tree); 1884b2f1dbbSGreg Roach 1894b2f1dbbSGreg Roach $user = $request->getAttribute('user'); 1904b2f1dbbSGreg Roach assert($user instanceof UserInterface); 1914b2f1dbbSGreg Roach 1924b2f1dbbSGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 1934b2f1dbbSGreg Roach 1944b2f1dbbSGreg Roach $action2 = $request->getQueryParams()['action2'] ?? 'hierarchy'; 1954b2f1dbbSGreg Roach $place_id = (int) ($request->getQueryParams()['place_id'] ?? 0); 1964b2f1dbbSGreg Roach $place = Place::find($place_id, $tree); 1974b2f1dbbSGreg Roach 1984b2f1dbbSGreg Roach // Request for a non-existent place? 1994b2f1dbbSGreg Roach if ($place_id !== $place->id()) { 2004b2f1dbbSGreg Roach return redirect($place->url()); 2014b2f1dbbSGreg Roach } 2024b2f1dbbSGreg Roach 203c9c6f2ecSGreg Roach $map_providers = $this->module_service->findByInterface(ModuleMapProviderInterface::class); 204c9c6f2ecSGreg Roach 2054b2f1dbbSGreg Roach $content = ''; 206c9c6f2ecSGreg Roach $showmap = $map_providers->isNotEmpty(); 2074b2f1dbbSGreg Roach $data = null; 2084b2f1dbbSGreg Roach 2094b2f1dbbSGreg Roach if ($showmap) { 2104b2f1dbbSGreg Roach $content .= view('modules/place-hierarchy/map', [ 2114b2f1dbbSGreg Roach 'data' => $this->mapData($tree, $place), 212c9c6f2ecSGreg Roach 'leaflet_config' => $this->leaflet_js_service->config(), 2134b2f1dbbSGreg Roach ]); 2144b2f1dbbSGreg Roach } 2154b2f1dbbSGreg Roach 2164b2f1dbbSGreg Roach switch ($action2) { 2174b2f1dbbSGreg Roach case 'list': 2184b2f1dbbSGreg Roach default: 2194b2f1dbbSGreg Roach $alt_link = I18N::translate('Show place hierarchy'); 2204b2f1dbbSGreg Roach $alt_url = $this->listUrl($tree, ['action2' => 'hierarchy', 'place_id' => $place_id]); 2214b2f1dbbSGreg Roach $content .= view('modules/place-hierarchy/list', ['columns' => $this->getList($tree)]); 2224b2f1dbbSGreg Roach break; 2234b2f1dbbSGreg Roach case 'hierarchy': 2244b2f1dbbSGreg Roach case 'hierarchy-e': 2254b2f1dbbSGreg Roach $alt_link = I18N::translate('Show all places in a list'); 2264b2f1dbbSGreg Roach $alt_url = $this->listUrl($tree, ['action2' => 'list', 'place_id' => 0]); 2274b2f1dbbSGreg Roach $data = $this->getHierarchy($place); 2284b2f1dbbSGreg Roach $content .= (null === $data || $showmap) ? '' : view('place-hierarchy', $data); 2294b2f1dbbSGreg Roach if (null === $data || $action2 === 'hierarchy-e') { 2304b2f1dbbSGreg Roach $content .= view('modules/place-hierarchy/events', [ 2314b2f1dbbSGreg Roach 'indilist' => $this->search_service->searchIndividualsInPlace($place), 2324b2f1dbbSGreg Roach 'famlist' => $this->search_service->searchFamiliesInPlace($place), 2334b2f1dbbSGreg Roach 'tree' => $place->tree(), 2344b2f1dbbSGreg Roach ]); 2354b2f1dbbSGreg Roach } 2364b2f1dbbSGreg Roach } 2374b2f1dbbSGreg Roach 2384b2f1dbbSGreg Roach if ($data !== null && $action2 !== 'hierarchy-e' && $place->gedcomName() !== '') { 2394b2f1dbbSGreg Roach $events_link = $this->listUrl($tree, ['action2' => 'hierarchy-e', 'place_id' => $place_id]); 2404b2f1dbbSGreg Roach } else { 2414b2f1dbbSGreg Roach $events_link = ''; 2424b2f1dbbSGreg Roach } 2434b2f1dbbSGreg Roach 2444b2f1dbbSGreg Roach $breadcrumbs = $this->breadcrumbs($place); 2454b2f1dbbSGreg Roach 2464b2f1dbbSGreg Roach return $this->viewResponse('modules/place-hierarchy/page', [ 2474b2f1dbbSGreg Roach 'alt_link' => $alt_link, 2484b2f1dbbSGreg Roach 'alt_url' => $alt_url, 2494b2f1dbbSGreg Roach 'breadcrumbs' => $breadcrumbs['breadcrumbs'], 2504b2f1dbbSGreg Roach 'content' => $content, 2514b2f1dbbSGreg Roach 'current' => $breadcrumbs['current'], 2524b2f1dbbSGreg Roach 'events_link' => $events_link, 2534b2f1dbbSGreg Roach 'place' => $place, 2544b2f1dbbSGreg Roach 'title' => I18N::translate('Place hierarchy'), 2554b2f1dbbSGreg Roach 'tree' => $tree, 256c9c6f2ecSGreg Roach 'world_url' => $this->listUrl($tree), 2574b2f1dbbSGreg Roach ]); 2584b2f1dbbSGreg Roach } 2594b2f1dbbSGreg Roach 2604b2f1dbbSGreg Roach /** 2614b2f1dbbSGreg Roach * @param Tree $tree 2624b2f1dbbSGreg Roach * @param Place $placeObj 2634b2f1dbbSGreg Roach * 2644b2f1dbbSGreg Roach * @return array<mixed> 2654b2f1dbbSGreg Roach */ 2664b2f1dbbSGreg Roach protected function mapData(Tree $tree, Place $placeObj): array 2674b2f1dbbSGreg Roach { 2684b2f1dbbSGreg Roach $places = $placeObj->getChildPlaces(); 2694b2f1dbbSGreg Roach $features = []; 2704b2f1dbbSGreg Roach $sidebar = ''; 2714b2f1dbbSGreg Roach $show_link = true; 2724b2f1dbbSGreg Roach 2734b2f1dbbSGreg Roach if ($places === []) { 2744b2f1dbbSGreg Roach $places[] = $placeObj; 2754b2f1dbbSGreg Roach $show_link = false; 2764b2f1dbbSGreg Roach } 2774b2f1dbbSGreg Roach 2784b2f1dbbSGreg Roach foreach ($places as $id => $place) { 2794b2f1dbbSGreg Roach $location = new PlaceLocation($place->gedcomName()); 2804b2f1dbbSGreg Roach 28190949315SGreg Roach if ($location->latitude() === null || $location->longitude() === null) { 2824b2f1dbbSGreg Roach $sidebar_class = 'unmapped'; 2834b2f1dbbSGreg Roach } else { 2844b2f1dbbSGreg Roach $sidebar_class = 'mapped'; 2854b2f1dbbSGreg Roach $features[] = [ 2864b2f1dbbSGreg Roach 'type' => 'Feature', 2874b2f1dbbSGreg Roach 'id' => $id, 2884b2f1dbbSGreg Roach 'geometry' => [ 2894b2f1dbbSGreg Roach 'type' => 'Point', 2904b2f1dbbSGreg Roach 'coordinates' => [$location->longitude(), $location->latitude()], 2914b2f1dbbSGreg Roach ], 2924b2f1dbbSGreg Roach 'properties' => [ 2934b2f1dbbSGreg Roach 'tooltip' => $place->gedcomName(), 2944b2f1dbbSGreg Roach 'popup' => view('modules/place-hierarchy/popup', [ 2954b2f1dbbSGreg Roach 'showlink' => $show_link, 2964b2f1dbbSGreg Roach 'place' => $place, 2974b2f1dbbSGreg Roach 'latitude' => $location->latitude(), 2984b2f1dbbSGreg Roach 'longitude' => $location->longitude(), 2994b2f1dbbSGreg Roach ]), 3004b2f1dbbSGreg Roach ], 3014b2f1dbbSGreg Roach ]; 3024b2f1dbbSGreg Roach } 3034b2f1dbbSGreg Roach 304*f78da678SGreg Roach $statistics = app(Statistics::class); 3054b2f1dbbSGreg Roach 3064b2f1dbbSGreg Roach //Stats 307c8db8a43SGreg Roach $stats = []; 308c8db8a43SGreg Roach foreach ([Individual::RECORD_TYPE, Family::RECORD_TYPE, Location::RECORD_TYPE] as $type) { 3094b2f1dbbSGreg Roach $tmp = $statistics->statsPlaces($type, '', $place->id()); 310c8db8a43SGreg Roach $stats[$type] = $tmp === [] ? 0 : $tmp[0]->tot; 3114b2f1dbbSGreg Roach } 3124b2f1dbbSGreg Roach $sidebar .= view('modules/place-hierarchy/sidebar', [ 3134b2f1dbbSGreg Roach 'showlink' => $show_link, 3144b2f1dbbSGreg Roach 'id' => $id, 3154b2f1dbbSGreg Roach 'place' => $place, 3164b2f1dbbSGreg Roach 'sidebar_class' => $sidebar_class, 317c8db8a43SGreg Roach 'stats' => $stats, 3184b2f1dbbSGreg Roach ]); 3194b2f1dbbSGreg Roach } 3204b2f1dbbSGreg Roach 3214b2f1dbbSGreg Roach return [ 3224b2f1dbbSGreg Roach 'bounds' => (new PlaceLocation($placeObj->gedcomName()))->boundingRectangle(), 3234b2f1dbbSGreg Roach 'sidebar' => $sidebar, 3244b2f1dbbSGreg Roach 'markers' => [ 3254b2f1dbbSGreg Roach 'type' => 'FeatureCollection', 3264b2f1dbbSGreg Roach 'features' => $features, 327c9c6f2ecSGreg Roach ], 328c9c6f2ecSGreg Roach ]; 329c9c6f2ecSGreg Roach } 330c9c6f2ecSGreg Roach 331c9c6f2ecSGreg Roach /** 332c9c6f2ecSGreg Roach * @param Tree $tree 333c9c6f2ecSGreg Roach * 334c9c6f2ecSGreg Roach * @return array<array<Place>> 335c9c6f2ecSGreg Roach */ 336c9c6f2ecSGreg Roach private function getList(Tree $tree): array 337c9c6f2ecSGreg Roach { 338c9c6f2ecSGreg Roach $places = $this->search_service->searchPlaces($tree, '') 339c9c6f2ecSGreg Roach ->sort(static function (Place $x, Place $y): int { 340c9c6f2ecSGreg Roach return $x->gedcomName() <=> $y->gedcomName(); 341c9c6f2ecSGreg Roach }) 342c9c6f2ecSGreg Roach ->all(); 343c9c6f2ecSGreg Roach 344c9c6f2ecSGreg Roach $count = count($places); 345c9c6f2ecSGreg Roach 346c9c6f2ecSGreg Roach if ($places === []) { 347c9c6f2ecSGreg Roach return []; 348c9c6f2ecSGreg Roach } 349c9c6f2ecSGreg Roach 350c9c6f2ecSGreg Roach $columns = $count > 20 ? 3 : 2; 351c9c6f2ecSGreg Roach 352c9c6f2ecSGreg Roach return array_chunk($places, (int) ceil($count / $columns)); 353c9c6f2ecSGreg Roach } 354c9c6f2ecSGreg Roach 355c9c6f2ecSGreg Roach /** 356c9c6f2ecSGreg Roach * @param Place $place 357c9c6f2ecSGreg Roach * 358c9c6f2ecSGreg Roach * @return array{'tree':Tree,'col_class':string,'columns':array<array<Place>>,'place':Place}|null 359c9c6f2ecSGreg Roach */ 360c9c6f2ecSGreg Roach private function getHierarchy(Place $place): ?array 361c9c6f2ecSGreg Roach { 362c9c6f2ecSGreg Roach $child_places = $place->getChildPlaces(); 363c9c6f2ecSGreg Roach $numfound = count($child_places); 364c9c6f2ecSGreg Roach 365c9c6f2ecSGreg Roach if ($numfound > 0) { 366c9c6f2ecSGreg Roach $divisor = $numfound > 20 ? 3 : 2; 367c9c6f2ecSGreg Roach 368c9c6f2ecSGreg Roach return [ 369c9c6f2ecSGreg Roach 'tree' => $place->tree(), 370c9c6f2ecSGreg Roach 'col_class' => 'w-' . ($divisor === 2 ? '25' : '50'), 371c9c6f2ecSGreg Roach 'columns' => array_chunk($child_places, (int) ceil($numfound / $divisor)), 372c9c6f2ecSGreg Roach 'place' => $place, 373c9c6f2ecSGreg Roach ]; 374c9c6f2ecSGreg Roach } 375c9c6f2ecSGreg Roach 376c9c6f2ecSGreg Roach return null; 377c9c6f2ecSGreg Roach } 378c9c6f2ecSGreg Roach 379c9c6f2ecSGreg Roach /** 380c9c6f2ecSGreg Roach * @param Place $place 381c9c6f2ecSGreg Roach * 382c9c6f2ecSGreg Roach * @return array{'breadcrumbs':array<Place>,'current':Place|null} 383c9c6f2ecSGreg Roach */ 384c9c6f2ecSGreg Roach private function breadcrumbs(Place $place): array 385c9c6f2ecSGreg Roach { 386c9c6f2ecSGreg Roach $breadcrumbs = []; 387c9c6f2ecSGreg Roach if ($place->gedcomName() !== '') { 388c9c6f2ecSGreg Roach $breadcrumbs[] = $place; 389c9c6f2ecSGreg Roach $parent_place = $place->parent(); 390c9c6f2ecSGreg Roach while ($parent_place->gedcomName() !== '') { 391c9c6f2ecSGreg Roach $breadcrumbs[] = $parent_place; 392c9c6f2ecSGreg Roach $parent_place = $parent_place->parent(); 393c9c6f2ecSGreg Roach } 394c9c6f2ecSGreg Roach $breadcrumbs = array_reverse($breadcrumbs); 395c9c6f2ecSGreg Roach $current = array_pop($breadcrumbs); 396c9c6f2ecSGreg Roach } else { 397c9c6f2ecSGreg Roach $current = null; 398c9c6f2ecSGreg Roach } 399c9c6f2ecSGreg Roach 400c9c6f2ecSGreg Roach return [ 401c9c6f2ecSGreg Roach 'breadcrumbs' => $breadcrumbs, 402c9c6f2ecSGreg Roach 'current' => $current, 4034b2f1dbbSGreg Roach ]; 4044b2f1dbbSGreg Roach } 40567992b6aSRichard Cissee} 406