xref: /webtrees/app/Module/IndividualMetadataModule.php (revision 89f7189b61a494347591c99bdb92afb7d8b66e1b)
18eaf8709SGreg Roach<?php
23976b470SGreg Roach
38eaf8709SGreg Roach/**
48eaf8709SGreg Roach * webtrees: online genealogy
5*89f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
68eaf8709SGreg Roach * This program is free software: you can redistribute it and/or modify
78eaf8709SGreg Roach * it under the terms of the GNU General Public License as published by
88eaf8709SGreg Roach * the Free Software Foundation, either version 3 of the License, or
98eaf8709SGreg Roach * (at your option) any later version.
108eaf8709SGreg Roach * This program is distributed in the hope that it will be useful,
118eaf8709SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
128eaf8709SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138eaf8709SGreg Roach * GNU General Public License for more details.
148eaf8709SGreg Roach * You should have received a copy of the GNU General Public License
15*89f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
168eaf8709SGreg Roach */
17fcfa147eSGreg Roach
188eaf8709SGreg Roachdeclare(strict_types=1);
198eaf8709SGreg Roach
208eaf8709SGreg Roachnamespace Fisharebest\Webtrees\Module;
218eaf8709SGreg Roach
228eaf8709SGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
238eaf8709SGreg Roachuse Fisharebest\Webtrees\I18N;
248eaf8709SGreg Roachuse Fisharebest\Webtrees\Individual;
258eaf8709SGreg Roachuse Illuminate\Support\Collection;
268eaf8709SGreg Roach
278eaf8709SGreg Roach/**
288eaf8709SGreg Roach * Class ExtraInformationModule
298eaf8709SGreg Roach * A sidebar to show non-genealogy information about an individual
308eaf8709SGreg Roach */
318eaf8709SGreg Roachclass IndividualMetadataModule extends AbstractModule implements ModuleSidebarInterface
328eaf8709SGreg Roach{
338eaf8709SGreg Roach    use ModuleSidebarTrait;
348eaf8709SGreg Roach
358eaf8709SGreg Roach    // A list of facts that are handled by this module.
368eaf8709SGreg Roach    protected const HANDLED_FACTS = [
378eaf8709SGreg Roach        'AFN',
388eaf8709SGreg Roach        'CHAN',
398eaf8709SGreg Roach        'IDNO',
408eaf8709SGreg Roach        'REFN',
418eaf8709SGreg Roach        'RESN',
428eaf8709SGreg Roach        'RFN',
438eaf8709SGreg Roach        'RIN',
448eaf8709SGreg Roach        'SSN',
458eaf8709SGreg Roach        '_UID',
468eaf8709SGreg Roach    ];
478eaf8709SGreg Roach
488eaf8709SGreg Roach    /**
490cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
508eaf8709SGreg Roach     *
518eaf8709SGreg Roach     * @return string
528eaf8709SGreg Roach     */
538eaf8709SGreg Roach    public function title(): string
548eaf8709SGreg Roach    {
558eaf8709SGreg Roach        /* I18N: Name of a module/sidebar */
568eaf8709SGreg Roach        return I18N::translate('Extra information');
578eaf8709SGreg Roach    }
588eaf8709SGreg Roach
598eaf8709SGreg Roach    /**
608eaf8709SGreg Roach     * A sentence describing what this module does.
618eaf8709SGreg Roach     *
628eaf8709SGreg Roach     * @return string
638eaf8709SGreg Roach     */
648eaf8709SGreg Roach    public function description(): string
658eaf8709SGreg Roach    {
668eaf8709SGreg Roach        /* I18N: Description of the “Extra information” module */
678eaf8709SGreg Roach        return I18N::translate('A sidebar showing non-genealogy information about an individual.');
688eaf8709SGreg Roach    }
698eaf8709SGreg Roach
708eaf8709SGreg Roach    /**
718eaf8709SGreg Roach     * The default position for this sidebar.  It can be changed in the control panel.
728eaf8709SGreg Roach     *
738eaf8709SGreg Roach     * @return int
748eaf8709SGreg Roach     */
758eaf8709SGreg Roach    public function defaultSidebarOrder(): int
768eaf8709SGreg Roach    {
778eaf8709SGreg Roach        return 1;
788eaf8709SGreg Roach    }
798eaf8709SGreg Roach
800dcd9387SGreg Roach    /**
810dcd9387SGreg Roach     * @param Individual $individual
820dcd9387SGreg Roach     *
830dcd9387SGreg Roach     * @return bool
840dcd9387SGreg Roach     */
858eaf8709SGreg Roach    public function hasSidebarContent(Individual $individual): bool
868eaf8709SGreg Roach    {
87d697893cSGreg Roach        return $individual->facts(static::HANDLED_FACTS)->isNotEmpty();
888eaf8709SGreg Roach    }
898eaf8709SGreg Roach
908eaf8709SGreg Roach    /**
918eaf8709SGreg Roach     * Load this sidebar synchronously.
928eaf8709SGreg Roach     *
938eaf8709SGreg Roach     * @param Individual $individual
948eaf8709SGreg Roach     *
958eaf8709SGreg Roach     * @return string
968eaf8709SGreg Roach     */
978eaf8709SGreg Roach    public function getSidebarContent(Individual $individual): string
988eaf8709SGreg Roach    {
998eaf8709SGreg Roach        ob_start();
100d697893cSGreg Roach
101d697893cSGreg Roach        foreach ($individual->facts(static::HANDLED_FACTS) as $fact) {
1028eaf8709SGreg Roach            FunctionsPrintFacts::printFact($fact, $individual);
1038eaf8709SGreg Roach        }
1048eaf8709SGreg Roach
105d697893cSGreg Roach        $html = ob_get_clean();
1068eaf8709SGreg Roach
107d697893cSGreg Roach        return strip_tags($html, '<a><div><span>');
1088eaf8709SGreg Roach    }
1098eaf8709SGreg Roach
1108eaf8709SGreg Roach    /**
1118eaf8709SGreg Roach     * This module handles the following facts - so don't show them on the "Facts and events" tab.
1128eaf8709SGreg Roach     *
113b5c8fd7eSGreg Roach     * @return Collection<string>
1148eaf8709SGreg Roach     */
1158eaf8709SGreg Roach    public function supportedFacts(): Collection
1168eaf8709SGreg Roach    {
1178eaf8709SGreg Roach        return new Collection(static::HANDLED_FACTS);
1188eaf8709SGreg Roach    }
1198eaf8709SGreg Roach}
120