xref: /webtrees/app/Module/IndividualMetadataModule.php (revision 4a1f1d433794f86f893b59883147e57af4e94374)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Module;
19
20use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
21use Fisharebest\Webtrees\I18N;
22use Fisharebest\Webtrees\Individual;
23use Illuminate\Support\Collection;
24
25/**
26 * Class ExtraInformationModule
27 * A sidebar to show non-genealogy information about an individual
28 */
29class IndividualMetadataModule extends AbstractModule implements ModuleSidebarInterface
30{
31    use ModuleSidebarTrait;
32
33    // A list of facts that are handled by this module.
34    protected const HANDLED_FACTS = [
35        'AFN',
36        'CHAN',
37        'IDNO',
38        'REFN',
39        'RESN',
40        'RFN',
41        'RIN',
42        'SSN',
43        '_UID',
44    ];
45
46    /**
47     * How should this module be identified in the control panel, etc.?
48     *
49     * @return string
50     */
51    public function title(): string
52    {
53        /* I18N: Name of a module/sidebar */
54        return I18N::translate('Extra information');
55    }
56
57    /**
58     * A sentence describing what this module does.
59     *
60     * @return string
61     */
62    public function description(): string
63    {
64        /* I18N: Description of the “Extra information” module */
65        return I18N::translate('A sidebar showing non-genealogy information about an individual.');
66    }
67
68    /**
69     * The default position for this sidebar.  It can be changed in the control panel.
70     *
71     * @return int
72     */
73    public function defaultSidebarOrder(): int
74    {
75        return 1;
76    }
77
78    /** {@inheritdoc} */
79    public function hasSidebarContent(Individual $individual): bool
80    {
81        return $individual->facts(static::HANDLED_FACTS)->isNotEmpty();
82    }
83
84    /**
85     * Load this sidebar synchronously.
86     *
87     * @param Individual $individual
88     *
89     * @return string
90     */
91    public function getSidebarContent(Individual $individual): string
92    {
93        ob_start();
94
95        foreach ($individual->facts(static::HANDLED_FACTS) as $fact) {
96            FunctionsPrintFacts::printFact($fact, $individual);
97        }
98
99        $html = ob_get_clean();
100
101        return strip_tags($html, '<a><div><span>');
102    }
103
104    /**
105     * This module handles the following facts - so don't show them on the "Facts and events" tab.
106     *
107     * @return Collection
108     */
109    public function supportedFacts(): Collection
110    {
111        return new Collection(static::HANDLED_FACTS);
112    }
113}
114