xref: /webtrees/app/Module/IndividualMetadataModule.php (revision a3148b03cff68ac7a179d4636354b8e1c00044ca)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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\Functions\FunctionsPrintFacts;
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        '_WEBTAG',
49    ];
50
51    /**
52     * How should this module be identified in the control panel, etc.?
53     *
54     * @return string
55     */
56    public function title(): string
57    {
58        /* I18N: Name of a module/sidebar */
59        return I18N::translate('Extra information');
60    }
61
62    /**
63     * A sentence describing what this module does.
64     *
65     * @return string
66     */
67    public function description(): string
68    {
69        /* I18N: Description of the “Extra information” module */
70        return I18N::translate('A sidebar showing non-genealogy information about an individual.');
71    }
72
73    /**
74     * The default position for this sidebar.  It can be changed in the control panel.
75     *
76     * @return int
77     */
78    public function defaultSidebarOrder(): int
79    {
80        return 1;
81    }
82
83    /**
84     * @param Individual $individual
85     *
86     * @return bool
87     */
88    public function hasSidebarContent(Individual $individual): bool
89    {
90        return $individual->facts(static::HANDLED_FACTS)->isNotEmpty();
91    }
92
93    /**
94     * Load this sidebar synchronously.
95     *
96     * @param Individual $individual
97     *
98     * @return string
99     */
100    public function getSidebarContent(Individual $individual): string
101    {
102        ob_start();
103
104        foreach ($individual->facts(static::HANDLED_FACTS) as $fact) {
105            FunctionsPrintFacts::printFact($fact, $individual);
106        }
107
108        $html = ob_get_clean();
109
110        return strip_tags($html, '<a><div><span><i>');
111    }
112
113    /**
114     * This module handles the following facts - so don't show them on the "Facts and events" tab.
115     *
116     * @return Collection<string>
117     */
118    public function supportedFacts(): Collection
119    {
120        return new Collection(array_map(fn (string $tag): string => 'INDI:' . $tag, static::HANDLED_FACTS));
121    }
122}
123