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