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