fisharebest /
webtrees
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * webtrees: online genealogy |
||
| 5 | * Copyright (C) 2025 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 <https://www.gnu.org/licenses/>. |
||
| 16 | */ |
||
| 17 | |||
| 18 | declare(strict_types=1); |
||
| 19 | |||
| 20 | namespace Fisharebest\Webtrees\Module; |
||
| 21 | |||
| 22 | use Fisharebest\Webtrees\Fact; |
||
| 23 | use Fisharebest\Webtrees\I18N; |
||
| 24 | use Fisharebest\Webtrees\Individual; |
||
| 25 | use Illuminate\Support\Collection; |
||
| 26 | |||
| 27 | use function array_map; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Class ExtraInformationModule |
||
| 31 | * A sidebar to show non-genealogy information about an individual |
||
| 32 | */ |
||
| 33 | class IndividualMetadataModule extends AbstractModule implements ModuleSidebarInterface |
||
| 34 | { |
||
| 35 | use ModuleSidebarTrait; |
||
| 36 | |||
| 37 | // A list of facts that are handled by this module. |
||
| 38 | protected const array HANDLED_FACTS = [ |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 39 | 'AFN', |
||
| 40 | 'ANCI', |
||
| 41 | 'CHAN', |
||
| 42 | 'DESI', |
||
| 43 | 'IDNO', |
||
| 44 | 'REFN', |
||
| 45 | 'RESN', |
||
| 46 | 'RFN', |
||
| 47 | 'RIN', |
||
| 48 | 'SSN', |
||
| 49 | 'SUBM', |
||
| 50 | '_UID', |
||
| 51 | '_FSFTID', |
||
| 52 | '_WEBTAG', |
||
| 53 | ]; |
||
| 54 | |||
| 55 | public function title(): string |
||
| 56 | { |
||
| 57 | /* I18N: Name of a module/sidebar */ |
||
| 58 | return I18N::translate('Extra information'); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function description(): string |
||
| 62 | { |
||
| 63 | /* I18N: Description of the “Extra information” module */ |
||
| 64 | return I18N::translate('A sidebar showing non-genealogy information about an individual.'); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * The default position for this sidebar. It can be changed in the control panel. |
||
| 69 | * |
||
| 70 | * @return int |
||
| 71 | */ |
||
| 72 | public function defaultSidebarOrder(): int |
||
| 73 | { |
||
| 74 | return 1; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param Individual $individual |
||
| 79 | * |
||
| 80 | * @return bool |
||
| 81 | */ |
||
| 82 | public function hasSidebarContent(Individual $individual): bool |
||
| 83 | { |
||
| 84 | return $individual->facts(static::HANDLED_FACTS)->isNotEmpty(); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Load this sidebar synchronously. |
||
| 89 | * |
||
| 90 | * @param Individual $individual |
||
| 91 | * |
||
| 92 | * @return string |
||
| 93 | */ |
||
| 94 | public function getSidebarContent(Individual $individual): string |
||
| 95 | { |
||
| 96 | $html = $individual->facts(static::HANDLED_FACTS) |
||
| 97 | ->map(static fn (Fact $fact): string => view('fact', ['fact' => $fact, 'record' => $individual])) |
||
| 98 | ->implode('<hr>'); |
||
| 99 | |||
| 100 | return strip_tags($html, ['a', 'div', 'span', 'i', 'hr', 'br']); |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * This module handles the following facts - so don't show them on the "Facts and events" tab. |
||
| 105 | * |
||
| 106 | * @return Collection<int,string> |
||
| 107 | */ |
||
| 108 | public function supportedFacts(): Collection |
||
| 109 | { |
||
| 110 | return new Collection(array_map(static fn (string $tag): string => 'INDI:' . $tag, static::HANDLED_FACTS)); |
||
| 111 | } |
||
| 112 | } |
||
| 113 |