1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Module; 21 22use Fisharebest\Webtrees\Functions\FunctionsPrintFacts; 23use Fisharebest\Webtrees\I18N; 24use Fisharebest\Webtrees\Individual; 25use Illuminate\Support\Collection; 26 27/** 28 * Class ExtraInformationModule 29 * A sidebar to show non-genealogy information about an individual 30 */ 31class IndividualMetadataModule extends AbstractModule implements ModuleSidebarInterface 32{ 33 use ModuleSidebarTrait; 34 35 // A list of facts that are handled by this module. 36 protected const HANDLED_FACTS = [ 37 'AFN', 38 'CHAN', 39 'IDNO', 40 'REFN', 41 'RESN', 42 'RFN', 43 'RIN', 44 'SSN', 45 '_UID', 46 ]; 47 48 /** 49 * How should this module be identified in the control panel, etc.? 50 * 51 * @return string 52 */ 53 public function title(): string 54 { 55 /* I18N: Name of a module/sidebar */ 56 return I18N::translate('Extra information'); 57 } 58 59 /** 60 * A sentence describing what this module does. 61 * 62 * @return string 63 */ 64 public function description(): string 65 { 66 /* I18N: Description of the “Extra information” module */ 67 return I18N::translate('A sidebar showing non-genealogy information about an individual.'); 68 } 69 70 /** 71 * The default position for this sidebar. It can be changed in the control panel. 72 * 73 * @return int 74 */ 75 public function defaultSidebarOrder(): int 76 { 77 return 1; 78 } 79 80 /** {@inheritdoc} */ 81 public function hasSidebarContent(Individual $individual): bool 82 { 83 return $individual->facts(static::HANDLED_FACTS)->isNotEmpty(); 84 } 85 86 /** 87 * Load this sidebar synchronously. 88 * 89 * @param Individual $individual 90 * 91 * @return string 92 */ 93 public function getSidebarContent(Individual $individual): string 94 { 95 ob_start(); 96 97 foreach ($individual->facts(static::HANDLED_FACTS) as $fact) { 98 FunctionsPrintFacts::printFact($fact, $individual); 99 } 100 101 $html = ob_get_clean(); 102 103 return strip_tags($html, '<a><div><span>'); 104 } 105 106 /** 107 * This module handles the following facts - so don't show them on the "Facts and events" tab. 108 * 109 * @return Collection 110 */ 111 public function supportedFacts(): Collection 112 { 113 return new Collection(static::HANDLED_FACTS); 114 } 115} 116