167992b6aSRichard Cissee<?php 23976b470SGreg Roach 367992b6aSRichard Cissee/** 467992b6aSRichard Cissee * webtrees: online genealogy 5*5bfc6897SGreg Roach * Copyright (C) 2022 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; 24c8db8a43SGreg Roachuse Fisharebest\Webtrees\Family; 2567992b6aSRichard Cisseeuse Fisharebest\Webtrees\I18N; 26c8db8a43SGreg Roachuse Fisharebest\Webtrees\Individual; 27c8db8a43SGreg Roachuse Fisharebest\Webtrees\Location; 284b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Place; 294b2f1dbbSGreg Roachuse Fisharebest\Webtrees\PlaceLocation; 30158900c2SGreg Roachuse Fisharebest\Webtrees\Registry; 31c9c6f2ecSGreg Roachuse Fisharebest\Webtrees\Services\LeafletJsService; 324b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 334b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Services\SearchService; 344b2f1dbbSGreg Roachuse Fisharebest\Webtrees\Statistics; 355229eadeSGreg Roachuse Fisharebest\Webtrees\Tree; 36b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 374b2f1dbbSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 386ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 396ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 404b2f1dbbSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 41f3874e19SGreg Roach 42f78da678SGreg Roachuse function app; 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. */ 6333c746f1SGreg Roach protected int $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 { 92158900c2SGreg Roach Registry::routeFactory()->routeMap() 934b2f1dbbSGreg Roach ->get(static::class, static::ROUTE_URL, $this); 944b2f1dbbSGreg Roach } 954b2f1dbbSGreg Roach 9667992b6aSRichard Cissee /** 970cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 9867992b6aSRichard Cissee * 9967992b6aSRichard Cissee * @return string 10067992b6aSRichard Cissee */ 10167992b6aSRichard Cissee public function title(): string 10267992b6aSRichard Cissee { 10367992b6aSRichard Cissee /* I18N: Name of a module/list */ 10467992b6aSRichard Cissee return I18N::translate('Place hierarchy'); 10567992b6aSRichard Cissee } 10667992b6aSRichard Cissee 10767992b6aSRichard Cissee /** 10867992b6aSRichard Cissee * A sentence describing what this module does. 10967992b6aSRichard Cissee * 11067992b6aSRichard Cissee * @return string 11167992b6aSRichard Cissee */ 11267992b6aSRichard Cissee public function description(): string 11367992b6aSRichard Cissee { 1149e0868cbSGreg Roach /* I18N: Description of the “Place hierarchy” module */ 11567992b6aSRichard Cissee return I18N::translate('The place hierarchy.'); 11667992b6aSRichard Cissee } 11767992b6aSRichard Cissee 11867992b6aSRichard Cissee /** 11967992b6aSRichard Cissee * CSS class for the URL. 12067992b6aSRichard Cissee * 12167992b6aSRichard Cissee * @return string 12267992b6aSRichard Cissee */ 12367992b6aSRichard Cissee public function listMenuClass(): string 12467992b6aSRichard Cissee { 12567992b6aSRichard Cissee return 'menu-list-plac'; 12667992b6aSRichard Cissee } 12767992b6aSRichard Cissee 1284db4b4a9SGreg Roach /** 12924f2a3afSGreg Roach * @return array<string> 1304db4b4a9SGreg Roach */ 13167992b6aSRichard Cissee public function listUrlAttributes(): array 13267992b6aSRichard Cissee { 13367992b6aSRichard Cissee return []; 13467992b6aSRichard Cissee } 1354b2f1dbbSGreg Roach 1364b2f1dbbSGreg Roach /** 1374b2f1dbbSGreg Roach * @param Tree $tree 1384b2f1dbbSGreg Roach * 1394b2f1dbbSGreg Roach * @return bool 1404b2f1dbbSGreg Roach */ 1414b2f1dbbSGreg Roach public function listIsEmpty(Tree $tree): bool 1424b2f1dbbSGreg Roach { 1434b2f1dbbSGreg Roach return !DB::table('places') 1444b2f1dbbSGreg Roach ->where('p_file', '=', $tree->id()) 1454b2f1dbbSGreg Roach ->exists(); 1464b2f1dbbSGreg Roach } 1474b2f1dbbSGreg Roach 1484b2f1dbbSGreg Roach /** 1494b2f1dbbSGreg Roach * Handle URLs generated by older versions of webtrees 1504b2f1dbbSGreg Roach * 1514b2f1dbbSGreg Roach * @param ServerRequestInterface $request 1524b2f1dbbSGreg Roach * 1534b2f1dbbSGreg Roach * @return ResponseInterface 1544b2f1dbbSGreg Roach */ 1554b2f1dbbSGreg Roach public function getListAction(ServerRequestInterface $request): ResponseInterface 1564b2f1dbbSGreg Roach { 157b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 158b55cbc6bSGreg Roach 159b55cbc6bSGreg Roach return redirect($this->listUrl($tree, $request->getQueryParams())); 1604b2f1dbbSGreg Roach } 1614b2f1dbbSGreg Roach 1624b2f1dbbSGreg Roach /** 163c9c6f2ecSGreg Roach * @param Tree $tree 16476d39c55SGreg Roach * @param array<bool|int|string|array<string>|null> $parameters 165c9c6f2ecSGreg Roach * 166c9c6f2ecSGreg Roach * @return string 167c9c6f2ecSGreg Roach */ 168c9c6f2ecSGreg Roach public function listUrl(Tree $tree, array $parameters = []): string 169c9c6f2ecSGreg Roach { 170c9c6f2ecSGreg Roach $parameters['tree'] = $tree->name(); 171c9c6f2ecSGreg Roach 172c9c6f2ecSGreg Roach return route(static::class, $parameters); 173c9c6f2ecSGreg Roach } 174c9c6f2ecSGreg Roach 175c9c6f2ecSGreg Roach /** 1764b2f1dbbSGreg Roach * @param ServerRequestInterface $request 1774b2f1dbbSGreg Roach * 1784b2f1dbbSGreg Roach * @return ResponseInterface 1794b2f1dbbSGreg Roach */ 1804b2f1dbbSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 1814b2f1dbbSGreg Roach { 182b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 183b55cbc6bSGreg Roach $user = Validator::attributes($request)->user(); 1844b2f1dbbSGreg Roach 1854b2f1dbbSGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 1864b2f1dbbSGreg Roach 1874b2f1dbbSGreg Roach $action2 = $request->getQueryParams()['action2'] ?? 'hierarchy'; 1884b2f1dbbSGreg Roach $place_id = (int) ($request->getQueryParams()['place_id'] ?? 0); 1894b2f1dbbSGreg Roach $place = Place::find($place_id, $tree); 1904b2f1dbbSGreg Roach 1914b2f1dbbSGreg Roach // Request for a non-existent place? 1924b2f1dbbSGreg Roach if ($place_id !== $place->id()) { 1934b2f1dbbSGreg Roach return redirect($place->url()); 1944b2f1dbbSGreg Roach } 1954b2f1dbbSGreg Roach 196c9c6f2ecSGreg Roach $map_providers = $this->module_service->findByInterface(ModuleMapProviderInterface::class); 197c9c6f2ecSGreg Roach 1984b2f1dbbSGreg Roach $content = ''; 199c9c6f2ecSGreg Roach $showmap = $map_providers->isNotEmpty(); 2004b2f1dbbSGreg Roach $data = null; 2014b2f1dbbSGreg Roach 2024b2f1dbbSGreg Roach if ($showmap) { 2034b2f1dbbSGreg Roach $content .= view('modules/place-hierarchy/map', [ 2044b2f1dbbSGreg Roach 'data' => $this->mapData($tree, $place), 205c9c6f2ecSGreg Roach 'leaflet_config' => $this->leaflet_js_service->config(), 2064b2f1dbbSGreg Roach ]); 2074b2f1dbbSGreg Roach } 2084b2f1dbbSGreg Roach 2094b2f1dbbSGreg Roach switch ($action2) { 2104b2f1dbbSGreg Roach case 'list': 2114b2f1dbbSGreg Roach default: 2124b2f1dbbSGreg Roach $alt_link = I18N::translate('Show place hierarchy'); 2134b2f1dbbSGreg Roach $alt_url = $this->listUrl($tree, ['action2' => 'hierarchy', 'place_id' => $place_id]); 2144b2f1dbbSGreg Roach $content .= view('modules/place-hierarchy/list', ['columns' => $this->getList($tree)]); 2154b2f1dbbSGreg Roach break; 2164b2f1dbbSGreg Roach case 'hierarchy': 2174b2f1dbbSGreg Roach case 'hierarchy-e': 2184b2f1dbbSGreg Roach $alt_link = I18N::translate('Show all places in a list'); 2194b2f1dbbSGreg Roach $alt_url = $this->listUrl($tree, ['action2' => 'list', 'place_id' => 0]); 2204b2f1dbbSGreg Roach $data = $this->getHierarchy($place); 2214b2f1dbbSGreg Roach $content .= (null === $data || $showmap) ? '' : view('place-hierarchy', $data); 2224b2f1dbbSGreg Roach if (null === $data || $action2 === 'hierarchy-e') { 2234b2f1dbbSGreg Roach $content .= view('modules/place-hierarchy/events', [ 2244b2f1dbbSGreg Roach 'indilist' => $this->search_service->searchIndividualsInPlace($place), 2254b2f1dbbSGreg Roach 'famlist' => $this->search_service->searchFamiliesInPlace($place), 2264b2f1dbbSGreg Roach 'tree' => $place->tree(), 2274b2f1dbbSGreg Roach ]); 2284b2f1dbbSGreg Roach } 2294b2f1dbbSGreg Roach } 2304b2f1dbbSGreg Roach 2314b2f1dbbSGreg Roach if ($data !== null && $action2 !== 'hierarchy-e' && $place->gedcomName() !== '') { 2324b2f1dbbSGreg Roach $events_link = $this->listUrl($tree, ['action2' => 'hierarchy-e', 'place_id' => $place_id]); 2334b2f1dbbSGreg Roach } else { 2344b2f1dbbSGreg Roach $events_link = ''; 2354b2f1dbbSGreg Roach } 2364b2f1dbbSGreg Roach 2374b2f1dbbSGreg Roach $breadcrumbs = $this->breadcrumbs($place); 2384b2f1dbbSGreg Roach 2394b2f1dbbSGreg Roach return $this->viewResponse('modules/place-hierarchy/page', [ 2404b2f1dbbSGreg Roach 'alt_link' => $alt_link, 2414b2f1dbbSGreg Roach 'alt_url' => $alt_url, 2424b2f1dbbSGreg Roach 'breadcrumbs' => $breadcrumbs['breadcrumbs'], 2434b2f1dbbSGreg Roach 'content' => $content, 2444b2f1dbbSGreg Roach 'current' => $breadcrumbs['current'], 2454b2f1dbbSGreg Roach 'events_link' => $events_link, 2464b2f1dbbSGreg Roach 'place' => $place, 2474b2f1dbbSGreg Roach 'title' => I18N::translate('Place hierarchy'), 2484b2f1dbbSGreg Roach 'tree' => $tree, 249c9c6f2ecSGreg Roach 'world_url' => $this->listUrl($tree), 2504b2f1dbbSGreg Roach ]); 2514b2f1dbbSGreg Roach } 2524b2f1dbbSGreg Roach 2534b2f1dbbSGreg Roach /** 2544b2f1dbbSGreg Roach * @param Tree $tree 2554b2f1dbbSGreg Roach * @param Place $placeObj 2564b2f1dbbSGreg Roach * 2574b2f1dbbSGreg Roach * @return array<mixed> 2584b2f1dbbSGreg Roach */ 2594b2f1dbbSGreg Roach protected function mapData(Tree $tree, Place $placeObj): array 2604b2f1dbbSGreg Roach { 2614b2f1dbbSGreg Roach $places = $placeObj->getChildPlaces(); 2624b2f1dbbSGreg Roach $features = []; 2634b2f1dbbSGreg Roach $sidebar = ''; 2644b2f1dbbSGreg Roach $show_link = true; 2654b2f1dbbSGreg Roach 2664b2f1dbbSGreg Roach if ($places === []) { 2674b2f1dbbSGreg Roach $places[] = $placeObj; 2684b2f1dbbSGreg Roach $show_link = false; 2694b2f1dbbSGreg Roach } 2704b2f1dbbSGreg Roach 2714b2f1dbbSGreg Roach foreach ($places as $id => $place) { 2724b2f1dbbSGreg Roach $location = new PlaceLocation($place->gedcomName()); 2734b2f1dbbSGreg Roach 27490949315SGreg Roach if ($location->latitude() === null || $location->longitude() === null) { 2754b2f1dbbSGreg Roach $sidebar_class = 'unmapped'; 2764b2f1dbbSGreg Roach } else { 2774b2f1dbbSGreg Roach $sidebar_class = 'mapped'; 2784b2f1dbbSGreg Roach $features[] = [ 2794b2f1dbbSGreg Roach 'type' => 'Feature', 2804b2f1dbbSGreg Roach 'id' => $id, 2814b2f1dbbSGreg Roach 'geometry' => [ 2824b2f1dbbSGreg Roach 'type' => 'Point', 2834b2f1dbbSGreg Roach 'coordinates' => [$location->longitude(), $location->latitude()], 2844b2f1dbbSGreg Roach ], 2854b2f1dbbSGreg Roach 'properties' => [ 2864b2f1dbbSGreg Roach 'tooltip' => $place->gedcomName(), 2874b2f1dbbSGreg Roach 'popup' => view('modules/place-hierarchy/popup', [ 2884b2f1dbbSGreg Roach 'showlink' => $show_link, 2894b2f1dbbSGreg Roach 'place' => $place, 2904b2f1dbbSGreg Roach 'latitude' => $location->latitude(), 2914b2f1dbbSGreg Roach 'longitude' => $location->longitude(), 2924b2f1dbbSGreg Roach ]), 2934b2f1dbbSGreg Roach ], 2944b2f1dbbSGreg Roach ]; 2954b2f1dbbSGreg Roach } 2964b2f1dbbSGreg Roach 297f78da678SGreg Roach $statistics = app(Statistics::class); 2984b2f1dbbSGreg Roach 2994b2f1dbbSGreg Roach //Stats 300c8db8a43SGreg Roach $stats = []; 301c8db8a43SGreg Roach foreach ([Individual::RECORD_TYPE, Family::RECORD_TYPE, Location::RECORD_TYPE] as $type) { 3024b2f1dbbSGreg Roach $tmp = $statistics->statsPlaces($type, '', $place->id()); 303c8db8a43SGreg Roach $stats[$type] = $tmp === [] ? 0 : $tmp[0]->tot; 3044b2f1dbbSGreg Roach } 3054b2f1dbbSGreg Roach $sidebar .= view('modules/place-hierarchy/sidebar', [ 3064b2f1dbbSGreg Roach 'showlink' => $show_link, 3074b2f1dbbSGreg Roach 'id' => $id, 3084b2f1dbbSGreg Roach 'place' => $place, 3094b2f1dbbSGreg Roach 'sidebar_class' => $sidebar_class, 310c8db8a43SGreg Roach 'stats' => $stats, 3114b2f1dbbSGreg Roach ]); 3124b2f1dbbSGreg Roach } 3134b2f1dbbSGreg Roach 3144b2f1dbbSGreg Roach return [ 3154b2f1dbbSGreg Roach 'bounds' => (new PlaceLocation($placeObj->gedcomName()))->boundingRectangle(), 3164b2f1dbbSGreg Roach 'sidebar' => $sidebar, 3174b2f1dbbSGreg Roach 'markers' => [ 3184b2f1dbbSGreg Roach 'type' => 'FeatureCollection', 3194b2f1dbbSGreg Roach 'features' => $features, 320c9c6f2ecSGreg Roach ], 321c9c6f2ecSGreg Roach ]; 322c9c6f2ecSGreg Roach } 323c9c6f2ecSGreg Roach 324c9c6f2ecSGreg Roach /** 325c9c6f2ecSGreg Roach * @param Tree $tree 326c9c6f2ecSGreg Roach * 327c9c6f2ecSGreg Roach * @return array<array<Place>> 328c9c6f2ecSGreg Roach */ 329c9c6f2ecSGreg Roach private function getList(Tree $tree): array 330c9c6f2ecSGreg Roach { 331c9c6f2ecSGreg Roach $places = $this->search_service->searchPlaces($tree, '') 332c9c6f2ecSGreg Roach ->sort(static function (Place $x, Place $y): int { 333c9c6f2ecSGreg Roach return $x->gedcomName() <=> $y->gedcomName(); 334c9c6f2ecSGreg Roach }) 335c9c6f2ecSGreg Roach ->all(); 336c9c6f2ecSGreg Roach 337c9c6f2ecSGreg Roach $count = count($places); 338c9c6f2ecSGreg Roach 339c9c6f2ecSGreg Roach if ($places === []) { 340c9c6f2ecSGreg Roach return []; 341c9c6f2ecSGreg Roach } 342c9c6f2ecSGreg Roach 343c9c6f2ecSGreg Roach $columns = $count > 20 ? 3 : 2; 344c9c6f2ecSGreg Roach 345c9c6f2ecSGreg Roach return array_chunk($places, (int) ceil($count / $columns)); 346c9c6f2ecSGreg Roach } 347c9c6f2ecSGreg Roach 348c9c6f2ecSGreg Roach /** 349c9c6f2ecSGreg Roach * @param Place $place 350c9c6f2ecSGreg Roach * 351c9c6f2ecSGreg Roach * @return array{'tree':Tree,'col_class':string,'columns':array<array<Place>>,'place':Place}|null 352c9c6f2ecSGreg Roach */ 353c9c6f2ecSGreg Roach private function getHierarchy(Place $place): ?array 354c9c6f2ecSGreg Roach { 355c9c6f2ecSGreg Roach $child_places = $place->getChildPlaces(); 356c9c6f2ecSGreg Roach $numfound = count($child_places); 357c9c6f2ecSGreg Roach 358c9c6f2ecSGreg Roach if ($numfound > 0) { 359c9c6f2ecSGreg Roach $divisor = $numfound > 20 ? 3 : 2; 360c9c6f2ecSGreg Roach 361c9c6f2ecSGreg Roach return [ 362c9c6f2ecSGreg Roach 'tree' => $place->tree(), 363c9c6f2ecSGreg Roach 'col_class' => 'w-' . ($divisor === 2 ? '25' : '50'), 364c9c6f2ecSGreg Roach 'columns' => array_chunk($child_places, (int) ceil($numfound / $divisor)), 365c9c6f2ecSGreg Roach 'place' => $place, 366c9c6f2ecSGreg Roach ]; 367c9c6f2ecSGreg Roach } 368c9c6f2ecSGreg Roach 369c9c6f2ecSGreg Roach return null; 370c9c6f2ecSGreg Roach } 371c9c6f2ecSGreg Roach 372c9c6f2ecSGreg Roach /** 373c9c6f2ecSGreg Roach * @param Place $place 374c9c6f2ecSGreg Roach * 375c9c6f2ecSGreg Roach * @return array{'breadcrumbs':array<Place>,'current':Place|null} 376c9c6f2ecSGreg Roach */ 377c9c6f2ecSGreg Roach private function breadcrumbs(Place $place): array 378c9c6f2ecSGreg Roach { 379c9c6f2ecSGreg Roach $breadcrumbs = []; 380c9c6f2ecSGreg Roach if ($place->gedcomName() !== '') { 381c9c6f2ecSGreg Roach $breadcrumbs[] = $place; 382c9c6f2ecSGreg Roach $parent_place = $place->parent(); 383c9c6f2ecSGreg Roach while ($parent_place->gedcomName() !== '') { 384c9c6f2ecSGreg Roach $breadcrumbs[] = $parent_place; 385c9c6f2ecSGreg Roach $parent_place = $parent_place->parent(); 386c9c6f2ecSGreg Roach } 387c9c6f2ecSGreg Roach $breadcrumbs = array_reverse($breadcrumbs); 388c9c6f2ecSGreg Roach $current = array_pop($breadcrumbs); 389c9c6f2ecSGreg Roach } else { 390c9c6f2ecSGreg Roach $current = null; 391c9c6f2ecSGreg Roach } 392c9c6f2ecSGreg Roach 393c9c6f2ecSGreg Roach return [ 394c9c6f2ecSGreg Roach 'breadcrumbs' => $breadcrumbs, 395c9c6f2ecSGreg Roach 'current' => $current, 3964b2f1dbbSGreg Roach ]; 3974b2f1dbbSGreg Roach } 39867992b6aSRichard Cissee} 399