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