xref: /webtrees/app/Module/IndividualMetadataModule.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\Module;
20
21use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
22use Fisharebest\Webtrees\I18N;
23use Fisharebest\Webtrees\Individual;
24use Illuminate\Support\Collection;
25
26/**
27 * Class ExtraInformationModule
28 * A sidebar to show non-genealogy information about an individual
29 */
30class IndividualMetadataModule extends AbstractModule implements ModuleSidebarInterface
31{
32    use ModuleSidebarTrait;
33
34    // A list of facts that are handled by this module.
35    protected const HANDLED_FACTS = [
36        'AFN',
37        'CHAN',
38        'IDNO',
39        'REFN',
40        'RESN',
41        'RFN',
42        'RIN',
43        'SSN',
44        '_UID',
45    ];
46
47    /**
48     * How should this module be identified in the control panel, etc.?
49     *
50     * @return string
51     */
52    public function title(): string
53    {
54        /* I18N: Name of a module/sidebar */
55        return I18N::translate('Extra information');
56    }
57
58    /**
59     * A sentence describing what this module does.
60     *
61     * @return string
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    /** {@inheritdoc} */
80    public function hasSidebarContent(Individual $individual): bool
81    {
82        return $individual->facts(static::HANDLED_FACTS)->isNotEmpty();
83    }
84
85    /**
86     * Load this sidebar synchronously.
87     *
88     * @param Individual $individual
89     *
90     * @return string
91     */
92    public function getSidebarContent(Individual $individual): string
93    {
94        ob_start();
95
96        foreach ($individual->facts(static::HANDLED_FACTS) as $fact) {
97            FunctionsPrintFacts::printFact($fact, $individual);
98        }
99
100        $html = ob_get_clean();
101
102        return strip_tags($html, '<a><div><span>');
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
109     */
110    public function supportedFacts(): Collection
111    {
112        return new Collection(static::HANDLED_FACTS);
113    }
114}
115