xref: /webtrees/app/Module/RelativesTabModule.php (revision d0889c636ab33113e71c9804803ddb055453ed50)
18c2e8227SGreg Roach<?php
23976b470SGreg Roach
38c2e8227SGreg Roach/**
48c2e8227SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
68c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
78c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
88c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
98c2e8227SGreg Roach * (at your option) any later version.
108c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
118c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
128c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138c2e8227SGreg Roach * GNU General Public License for more details.
148c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
168c2e8227SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
2176692c8bSGreg Roach
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
240e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual;
258eaf8709SGreg Roachuse Illuminate\Support\Collection;
268c2e8227SGreg Roach
278c2e8227SGreg Roach/**
288c2e8227SGreg Roach * Class RelativesTabModule
298c2e8227SGreg Roach */
3037eb8894SGreg Roachclass RelativesTabModule extends AbstractModule implements ModuleTabInterface
31c1010edaSGreg Roach{
3249a243cbSGreg Roach    use ModuleTabTrait;
3349a243cbSGreg Roach
3476692c8bSGreg Roach    /**
350cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
3676692c8bSGreg Roach     *
3776692c8bSGreg Roach     * @return string
3876692c8bSGreg Roach     */
3949a243cbSGreg Roach    public function title(): string
40c1010edaSGreg Roach    {
41bbb76c12SGreg Roach        /* I18N: Name of a module */
42bbb76c12SGreg Roach        return I18N::translate('Families');
438c2e8227SGreg Roach    }
448c2e8227SGreg Roach
4576692c8bSGreg Roach    /**
4676692c8bSGreg Roach     * A sentence describing what this module does.
4776692c8bSGreg Roach     *
4876692c8bSGreg Roach     * @return string
4976692c8bSGreg Roach     */
5049a243cbSGreg Roach    public function description(): string
51c1010edaSGreg Roach    {
52bbb76c12SGreg Roach        /* I18N: Description of the “Families” module */
53bbb76c12SGreg Roach        return I18N::translate('A tab showing the close relatives of an individual.');
548c2e8227SGreg Roach    }
558c2e8227SGreg Roach
5676692c8bSGreg Roach    /**
5749a243cbSGreg Roach     * The default position for this tab.  It can be changed in the control panel.
5876692c8bSGreg Roach     *
5976692c8bSGreg Roach     * @return int
6076692c8bSGreg Roach     */
61cbf4b7faSGreg Roach    public function defaultTabOrder(): int
62cbf4b7faSGreg Roach    {
63fb7a0427SGreg Roach        return 2;
648c2e8227SGreg Roach    }
658c2e8227SGreg Roach
663caaa4d2SGreg Roach    /**
673caaa4d2SGreg Roach     * Generate the HTML content of this tab.
683caaa4d2SGreg Roach     *
693caaa4d2SGreg Roach     * @param Individual $individual
703caaa4d2SGreg Roach     *
713caaa4d2SGreg Roach     * @return string
723caaa4d2SGreg Roach     */
739b34404bSGreg Roach    public function getTabContent(Individual $individual): string
74c1010edaSGreg Roach    {
75f4afa648SGreg Roach        $tree = $individual->tree();
76d9e083e7SGreg Roach        if ($tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
77225e381fSGreg Roach            $fam_access_level = Auth::PRIV_HIDE;
788c2e8227SGreg Roach        } else {
79225e381fSGreg Roach            $fam_access_level = Auth::accessLevel($tree);
808c2e8227SGreg Roach        }
818c2e8227SGreg Roach
82a8cd57e1SGreg Roach        return view('modules/relatives/tab', [
83225e381fSGreg Roach            'fam_access_level'     => $fam_access_level,
84225e381fSGreg Roach            'can_edit'             => $individual->canEdit(),
85225e381fSGreg Roach            'individual'           => $individual,
8639ca88baSGreg Roach            'parent_families'      => $individual->childFamilies(),
8739ca88baSGreg Roach            'spouse_families'      => $individual->spouseFamilies(),
88fceda430SGreg Roach            'step_child_families'  => $individual->spouseStepFamilies(),
8939ca88baSGreg Roach            'step_parent_families' => $individual->childStepFamilies(),
90225e381fSGreg Roach        ]);
918c2e8227SGreg Roach    }
928c2e8227SGreg Roach
933caaa4d2SGreg Roach    /**
943caaa4d2SGreg Roach     * Is this tab empty? If so, we don't always need to display it.
953caaa4d2SGreg Roach     *
963caaa4d2SGreg Roach     * @param Individual $individual
973caaa4d2SGreg Roach     *
983caaa4d2SGreg Roach     * @return bool
993caaa4d2SGreg Roach     */
1008f53f488SRico Sonntag    public function hasTabContent(Individual $individual): bool
101c1010edaSGreg Roach    {
10276092b6cSGreg Roach        return $individual->canEdit() || $individual->facts(['FAMC', 'FAMS'], false, null, true)->isNotEmpty();
1038c2e8227SGreg Roach    }
104c1010edaSGreg Roach
1053caaa4d2SGreg Roach    /**
1063caaa4d2SGreg Roach     * A greyed out tab has no actual content, but may perhaps have
1073caaa4d2SGreg Roach     * options to create content.
1083caaa4d2SGreg Roach     *
1093caaa4d2SGreg Roach     * @param Individual $individual
1103caaa4d2SGreg Roach     *
1113caaa4d2SGreg Roach     * @return bool
1123caaa4d2SGreg Roach     */
1138f53f488SRico Sonntag    public function isGrayedOut(Individual $individual): bool
114c1010edaSGreg Roach    {
1158c2e8227SGreg Roach        return false;
1168c2e8227SGreg Roach    }
117c1010edaSGreg Roach
1183caaa4d2SGreg Roach    /**
1193caaa4d2SGreg Roach     * Can this tab load asynchronously?
1203caaa4d2SGreg Roach     *
1213caaa4d2SGreg Roach     * @return bool
1223caaa4d2SGreg Roach     */
1238f53f488SRico Sonntag    public function canLoadAjax(): bool
124c1010edaSGreg Roach    {
12515d603e7SGreg Roach        return false;
1268c2e8227SGreg Roach    }
1278eaf8709SGreg Roach
1288eaf8709SGreg Roach    /**
1298eaf8709SGreg Roach     * This module handles the following facts - so don't show them on the "Facts and events" tab.
1308eaf8709SGreg Roach     *
131b5c8fd7eSGreg Roach     * @return Collection<string>
1328eaf8709SGreg Roach     */
1338eaf8709SGreg Roach    public function supportedFacts(): Collection
1348eaf8709SGreg Roach    {
135*d0889c63SGreg Roach        return new Collection(['INDI:FAMC', 'INDI:FAMS', 'FAM:HUSB', 'FAM:WIFE', 'FAM:CHIL']);
1368eaf8709SGreg Roach    }
1378c2e8227SGreg Roach}
138