xref: /webtrees/app/Module/RelativesTabModule.php (revision e873f434551745f888937263ff89e80db3b0f785)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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\Auth;
23use Fisharebest\Webtrees\I18N;
24use Fisharebest\Webtrees\Individual;
25use Illuminate\Support\Collection;
26
27/**
28 * Class RelativesTabModule
29 */
30class RelativesTabModule extends AbstractModule implements ModuleTabInterface
31{
32    use ModuleTabTrait;
33
34    /**
35     * How should this module be identified in the control panel, etc.?
36     *
37     * @return string
38     */
39    public function title(): string
40    {
41        /* I18N: Name of a module */
42        return I18N::translate('Families');
43    }
44
45    public function description(): string
46    {
47        /* I18N: Description of the “Families” module */
48        return I18N::translate('A tab showing the close relatives of an individual.');
49    }
50
51    /**
52     * The default position for this tab.  It can be changed in the control panel.
53     *
54     * @return int
55     */
56    public function defaultTabOrder(): int
57    {
58        return 2;
59    }
60
61    /**
62     * Generate the HTML content of this tab.
63     *
64     * @param Individual $individual
65     *
66     * @return string
67     */
68    public function getTabContent(Individual $individual): string
69    {
70        $tree = $individual->tree();
71        if ($tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
72            $fam_access_level = Auth::PRIV_HIDE;
73        } else {
74            $fam_access_level = Auth::accessLevel($tree);
75        }
76
77        return view('modules/relatives/tab', [
78            'fam_access_level'     => $fam_access_level,
79            'can_edit'             => $individual->canEdit(),
80            'individual'           => $individual,
81            'parent_families'      => $individual->childFamilies(),
82            'spouse_families'      => $individual->spouseFamilies(),
83            'step_child_families'  => $individual->spouseStepFamilies(),
84            'step_parent_families' => $individual->childStepFamilies(),
85        ]);
86    }
87
88    /**
89     * Is this tab empty? If so, we don't always need to display it.
90     *
91     * @param Individual $individual
92     *
93     * @return bool
94     */
95    public function hasTabContent(Individual $individual): bool
96    {
97        return $individual->canEdit() || $individual->facts(['FAMC', 'FAMS'], false, null, true)->isNotEmpty();
98    }
99
100    /**
101     * A greyed out tab has no actual content, but may perhaps have
102     * options to create content.
103     *
104     * @param Individual $individual
105     *
106     * @return bool
107     */
108    public function isGrayedOut(Individual $individual): bool
109    {
110        return false;
111    }
112
113    /**
114     * Can this tab load asynchronously?
115     *
116     * @return bool
117     */
118    public function canLoadAjax(): bool
119    {
120        return false;
121    }
122
123    /**
124     * This module handles the following facts - so don't show them on the "Facts and events" tab.
125     *
126     * @return Collection<int,string>
127     */
128    public function supportedFacts(): Collection
129    {
130        return new Collection(['INDI:FAMC', 'INDI:FAMS', 'FAM:HUSB', 'FAM:WIFE', 'FAM:CHIL']);
131    }
132}
133