xref: /webtrees/app/Module/IndividualMetadataModule.php (revision 22c135fa2a9d8aaf68a70032269940d5314a9818)
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    ];
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    /**
81     * @param Individual $individual
82     *
83     * @return bool
84     */
85    public function hasSidebarContent(Individual $individual): bool
86    {
87        return $individual->facts(static::HANDLED_FACTS)->isNotEmpty();
88    }
89
90    /**
91     * Load this sidebar synchronously.
92     *
93     * @param Individual $individual
94     *
95     * @return string
96     */
97    public function getSidebarContent(Individual $individual): string
98    {
99        ob_start();
100
101        foreach ($individual->facts(static::HANDLED_FACTS) as $fact) {
102            FunctionsPrintFacts::printFact($fact, $individual);
103        }
104
105        $html = ob_get_clean();
106
107        return strip_tags($html, '<a><div><span><i>');
108    }
109
110    /**
111     * This module handles the following facts - so don't show them on the "Facts and events" tab.
112     *
113     * @return Collection<string>
114     */
115    public function supportedFacts(): Collection
116    {
117        return new Collection(static::HANDLED_FACTS);
118    }
119}
120