18eaf8709SGreg Roach<?php 23976b470SGreg Roach 38eaf8709SGreg Roach/** 48eaf8709SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 68eaf8709SGreg Roach * This program is free software: you can redistribute it and/or modify 78eaf8709SGreg Roach * it under the terms of the GNU General Public License as published by 88eaf8709SGreg Roach * the Free Software Foundation, either version 3 of the License, or 98eaf8709SGreg Roach * (at your option) any later version. 108eaf8709SGreg Roach * This program is distributed in the hope that it will be useful, 118eaf8709SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 128eaf8709SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138eaf8709SGreg Roach * GNU General Public License for more details. 148eaf8709SGreg Roach * 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/>. 168eaf8709SGreg Roach */ 17fcfa147eSGreg Roach 188eaf8709SGreg Roachdeclare(strict_types=1); 198eaf8709SGreg Roach 208eaf8709SGreg Roachnamespace Fisharebest\Webtrees\Module; 218eaf8709SGreg Roach 22b315f3e1SGreg Roachuse Fisharebest\Webtrees\Fact; 238eaf8709SGreg Roachuse Fisharebest\Webtrees\I18N; 248eaf8709SGreg Roachuse Fisharebest\Webtrees\Individual; 258eaf8709SGreg Roachuse Illuminate\Support\Collection; 268eaf8709SGreg Roach 27048659daSGreg Roachuse function array_map; 28048659daSGreg Roach 298eaf8709SGreg Roach/** 308eaf8709SGreg Roach * Class ExtraInformationModule 318eaf8709SGreg Roach * A sidebar to show non-genealogy information about an individual 328eaf8709SGreg Roach */ 338eaf8709SGreg Roachclass IndividualMetadataModule extends AbstractModule implements ModuleSidebarInterface 348eaf8709SGreg Roach{ 358eaf8709SGreg Roach use ModuleSidebarTrait; 368eaf8709SGreg Roach 378eaf8709SGreg Roach // A list of facts that are handled by this module. 388eaf8709SGreg Roach protected const HANDLED_FACTS = [ 39048659daSGreg Roach 'AFN', 40048659daSGreg Roach 'CHAN', 41048659daSGreg Roach 'IDNO', 42048659daSGreg Roach 'REFN', 43048659daSGreg Roach 'RESN', 44048659daSGreg Roach 'RFN', 45048659daSGreg Roach 'RIN', 46048659daSGreg Roach 'SSN', 47048659daSGreg Roach '_UID', 4894f299e1SGreg Roach '_FSFTID', 49048659daSGreg Roach '_WEBTAG', 508eaf8709SGreg Roach ]; 518eaf8709SGreg Roach 528eaf8709SGreg Roach /** 530cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 548eaf8709SGreg Roach * 558eaf8709SGreg Roach * @return string 568eaf8709SGreg Roach */ 578eaf8709SGreg Roach public function title(): string 588eaf8709SGreg Roach { 598eaf8709SGreg Roach /* I18N: Name of a module/sidebar */ 608eaf8709SGreg Roach return I18N::translate('Extra information'); 618eaf8709SGreg Roach } 628eaf8709SGreg Roach 638eaf8709SGreg Roach public function description(): string 648eaf8709SGreg Roach { 658eaf8709SGreg Roach /* I18N: Description of the “Extra information” module */ 668eaf8709SGreg Roach return I18N::translate('A sidebar showing non-genealogy information about an individual.'); 678eaf8709SGreg Roach } 688eaf8709SGreg Roach 698eaf8709SGreg Roach /** 708eaf8709SGreg Roach * The default position for this sidebar. It can be changed in the control panel. 718eaf8709SGreg Roach * 728eaf8709SGreg Roach * @return int 738eaf8709SGreg Roach */ 748eaf8709SGreg Roach public function defaultSidebarOrder(): int 758eaf8709SGreg Roach { 768eaf8709SGreg Roach return 1; 778eaf8709SGreg Roach } 788eaf8709SGreg Roach 790dcd9387SGreg Roach /** 800dcd9387SGreg Roach * @param Individual $individual 810dcd9387SGreg Roach * 820dcd9387SGreg Roach * @return bool 830dcd9387SGreg Roach */ 848eaf8709SGreg Roach public function hasSidebarContent(Individual $individual): bool 858eaf8709SGreg Roach { 86d697893cSGreg Roach return $individual->facts(static::HANDLED_FACTS)->isNotEmpty(); 878eaf8709SGreg Roach } 888eaf8709SGreg Roach 898eaf8709SGreg Roach /** 908eaf8709SGreg Roach * Load this sidebar synchronously. 918eaf8709SGreg Roach * 928eaf8709SGreg Roach * @param Individual $individual 938eaf8709SGreg Roach * 948eaf8709SGreg Roach * @return string 958eaf8709SGreg Roach */ 968eaf8709SGreg Roach public function getSidebarContent(Individual $individual): string 978eaf8709SGreg Roach { 98b315f3e1SGreg Roach $html = $individual->facts(static::HANDLED_FACTS) 99b315f3e1SGreg Roach ->map(static fn (Fact $fact): string => view('fact', ['fact' => $fact, 'record' => $individual])) 10069e77fbeSGreg Roach ->implode('<hr>'); 1018eaf8709SGreg Roach 10269e77fbeSGreg Roach return strip_tags($html, ['a', 'div', 'span', 'i', 'hr', 'br']); 1038eaf8709SGreg Roach } 1048eaf8709SGreg Roach 1058eaf8709SGreg Roach /** 1068eaf8709SGreg Roach * This module handles the following facts - so don't show them on the "Facts and events" tab. 1078eaf8709SGreg Roach * 10836779af1SGreg Roach * @return Collection<int,string> 1098eaf8709SGreg Roach */ 1108eaf8709SGreg Roach public function supportedFacts(): Collection 1118eaf8709SGreg Roach { 11205babb96SGreg Roach return new Collection(array_map(static fn (string $tag): string => 'INDI:' . $tag, static::HANDLED_FACTS)); 1138eaf8709SGreg Roach } 1148eaf8709SGreg Roach} 115