xref: /webtrees/app/Http/RequestHandlers/IndividualPage.php (revision 534324768cedfc260deb392aa6a125c6cffc46e8)
1852ede8cSGreg Roach<?php
2852ede8cSGreg Roach
3852ede8cSGreg Roach/**
4852ede8cSGreg Roach * webtrees: online genealogy
5852ede8cSGreg Roach * Copyright (C) 2019 webtrees development team
6852ede8cSGreg Roach * This program is free software: you can redistribute it and/or modify
7852ede8cSGreg Roach * it under the terms of the GNU General Public License as published by
8852ede8cSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9852ede8cSGreg Roach * (at your option) any later version.
10852ede8cSGreg Roach * This program is distributed in the hope that it will be useful,
11852ede8cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12852ede8cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13852ede8cSGreg Roach * GNU General Public License for more details.
14852ede8cSGreg Roach * You should have received a copy of the GNU General Public License
15852ede8cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16852ede8cSGreg Roach */
17852ede8cSGreg Roach
18852ede8cSGreg Roachdeclare(strict_types=1);
19852ede8cSGreg Roach
20852ede8cSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
21852ede8cSGreg Roach
22e5d858f5SGreg Roachuse Fig\Http\Message\StatusCodeInterface;
23054771e9SGreg Roachuse Fisharebest\Webtrees\Age;
24852ede8cSGreg Roachuse Fisharebest\Webtrees\Auth;
25852ede8cSGreg Roachuse Fisharebest\Webtrees\Date;
26852ede8cSGreg Roachuse Fisharebest\Webtrees\Fact;
27852ede8cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrint;
28852ede8cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
29852ede8cSGreg Roachuse Fisharebest\Webtrees\GedcomCode\GedcomCodeName;
30852ede8cSGreg Roachuse Fisharebest\Webtrees\GedcomTag;
31852ede8cSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait;
32852ede8cSGreg Roachuse Fisharebest\Webtrees\I18N;
33852ede8cSGreg Roachuse Fisharebest\Webtrees\Individual;
34852ede8cSGreg Roachuse Fisharebest\Webtrees\Media;
35852ede8cSGreg Roachuse Fisharebest\Webtrees\MediaFile;
36852ede8cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface;
37852ede8cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface;
38852ede8cSGreg Roachuse Fisharebest\Webtrees\Services\ClipboardService;
39852ede8cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
40852ede8cSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
41852ede8cSGreg Roachuse Fisharebest\Webtrees\Tree;
42852ede8cSGreg Roachuse Illuminate\Support\Collection;
43852ede8cSGreg Roachuse Psr\Http\Message\ResponseInterface;
44852ede8cSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
45852ede8cSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
46852ede8cSGreg Roachuse stdClass;
47852ede8cSGreg Roach
482406e0e0SGreg Roachuse function array_map;
49852ede8cSGreg Roachuse function assert;
502406e0e0SGreg Roachuse function date;
51852ede8cSGreg Roachuse function e;
52852ede8cSGreg Roachuse function explode;
532406e0e0SGreg Roachuse function implode;
54852ede8cSGreg Roachuse function is_string;
55852ede8cSGreg Roachuse function ob_get_clean;
56852ede8cSGreg Roachuse function ob_start;
57852ede8cSGreg Roachuse function preg_match_all;
58852ede8cSGreg Roachuse function preg_replace;
59852ede8cSGreg Roachuse function redirect;
60852ede8cSGreg Roachuse function route;
61852ede8cSGreg Roachuse function str_replace;
62852ede8cSGreg Roachuse function strpos;
632406e0e0SGreg Roachuse function strtoupper;
642406e0e0SGreg Roachuse function view;
652406e0e0SGreg Roach
662406e0e0SGreg Roachuse const PREG_SET_ORDER;
67852ede8cSGreg Roach
68852ede8cSGreg Roach/**
69852ede8cSGreg Roach * Show an individual's page.
70852ede8cSGreg Roach */
71852ede8cSGreg Roachclass IndividualPage implements RequestHandlerInterface
72852ede8cSGreg Roach{
73852ede8cSGreg Roach    use ViewResponseTrait;
74852ede8cSGreg Roach
75852ede8cSGreg Roach    /** @var ClipboardService */
76852ede8cSGreg Roach    private $clipboard_service;
77852ede8cSGreg Roach
78852ede8cSGreg Roach    /** @var ModuleService */
79852ede8cSGreg Roach    private $module_service;
80852ede8cSGreg Roach
81852ede8cSGreg Roach    /** @var UserService */
82852ede8cSGreg Roach    private $user_service;
83852ede8cSGreg Roach
84852ede8cSGreg Roach    /**
85aba707cdSGreg Roach     * IndividualPage constructor.
86852ede8cSGreg Roach     *
87852ede8cSGreg Roach     * @param ClipboardService $clipboard_service
88852ede8cSGreg Roach     * @param ModuleService    $module_service
89852ede8cSGreg Roach     * @param UserService      $user_service
90852ede8cSGreg Roach     */
91852ede8cSGreg Roach    public function __construct(ClipboardService $clipboard_service, ModuleService $module_service, UserService $user_service)
92852ede8cSGreg Roach    {
93852ede8cSGreg Roach        $this->clipboard_service = $clipboard_service;
94852ede8cSGreg Roach        $this->module_service    = $module_service;
95852ede8cSGreg Roach        $this->user_service      = $user_service;
96852ede8cSGreg Roach    }
97852ede8cSGreg Roach
98852ede8cSGreg Roach    /**
99852ede8cSGreg Roach     * @param ServerRequestInterface $request
100852ede8cSGreg Roach     *
101852ede8cSGreg Roach     * @return ResponseInterface
102852ede8cSGreg Roach     */
103852ede8cSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
104852ede8cSGreg Roach    {
105852ede8cSGreg Roach        $tree = $request->getAttribute('tree');
106852ede8cSGreg Roach        assert($tree instanceof Tree);
107852ede8cSGreg Roach
108852ede8cSGreg Roach        $xref = $request->getAttribute('xref');
109852ede8cSGreg Roach        assert(is_string($xref));
110852ede8cSGreg Roach
111852ede8cSGreg Roach        $individual = Individual::getInstance($xref, $tree);
112852ede8cSGreg Roach        $individual = Auth::checkIndividualAccess($individual);
113852ede8cSGreg Roach
114852ede8cSGreg Roach        // Redirect to correct xref/slug
115852ede8cSGreg Roach        if ($individual->xref() !== $xref || $request->getAttribute('slug') !== $individual->slug()) {
116e5d858f5SGreg Roach            return redirect($individual->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY);
117852ede8cSGreg Roach        }
118852ede8cSGreg Roach
119852ede8cSGreg Roach        // What is (was) the age of the individual
120852ede8cSGreg Roach        $bdate = $individual->getBirthDate();
121852ede8cSGreg Roach        $ddate = $individual->getDeathDate();
122054771e9SGreg Roach
123054771e9SGreg Roach        if ($individual->isDead()) {
124852ede8cSGreg Roach            // If dead, show age at death
125054771e9SGreg Roach            $age = (new Age($bdate, $ddate))->ageAtEvent(false);
126852ede8cSGreg Roach        } else {
127054771e9SGreg Roach            // If living, show age today
128*53432476SGreg Roach            $today = strtoupper(date('d M Y'));
129*53432476SGreg Roach            $age = (new Age($bdate, new Date($today)))->ageAtEvent(true);
130852ede8cSGreg Roach        }
131852ede8cSGreg Roach
132852ede8cSGreg Roach        // What images are linked to this individual
133852ede8cSGreg Roach        $individual_media = new Collection();
134852ede8cSGreg Roach        foreach ($individual->facts(['OBJE']) as $fact) {
135852ede8cSGreg Roach            $media_object = $fact->target();
136852ede8cSGreg Roach            if ($media_object instanceof Media) {
137852ede8cSGreg Roach                $media_file = $media_object->firstImageFile();
138852ede8cSGreg Roach                if ($media_file instanceof MediaFile) {
139852ede8cSGreg Roach                    $individual_media->add($media_file);
140852ede8cSGreg Roach                }
141852ede8cSGreg Roach            }
142852ede8cSGreg Roach        }
143852ede8cSGreg Roach
144852ede8cSGreg Roach        $name_records = new Collection();
145852ede8cSGreg Roach        foreach ($individual->facts(['NAME']) as $n => $name_fact) {
146852ede8cSGreg Roach            $name_records->add($this->formatNameRecord($tree, $n, $name_fact));
147852ede8cSGreg Roach        }
148852ede8cSGreg Roach
149852ede8cSGreg Roach        $sex_records = new Collection();
150852ede8cSGreg Roach        foreach ($individual->facts(['SEX']) as $n => $sex_fact) {
151852ede8cSGreg Roach            $sex_records->add($this->formatSexRecord($sex_fact));
152852ede8cSGreg Roach        }
153852ede8cSGreg Roach
154852ede8cSGreg Roach        // If this individual is linked to a user account, show the link
155852ede8cSGreg Roach        $user_link = '';
156852ede8cSGreg Roach        if (Auth::isAdmin()) {
157852ede8cSGreg Roach            $users = $this->user_service->findByIndividual($individual);
158852ede8cSGreg Roach            foreach ($users as $user) {
159852ede8cSGreg Roach                $user_link = ' —  <a href="' . e(route('admin-users', ['filter' => $user->email()])) . '">' . e($user->userName()) . '</a>';
160852ede8cSGreg Roach            }
161852ede8cSGreg Roach        }
162852ede8cSGreg Roach
163852ede8cSGreg Roach        return $this->viewResponse('individual-page', [
164852ede8cSGreg Roach            'age'              => $age,
165852ede8cSGreg Roach            'clipboard_facts'  => $this->clipboard_service->pastableFacts($individual, new Collection()),
166852ede8cSGreg Roach            'individual'       => $individual,
167852ede8cSGreg Roach            'individual_media' => $individual_media,
1682406e0e0SGreg Roach            'meta_description' => $this->metaDescription($individual),
169852ede8cSGreg Roach            'meta_robots'      => 'index,follow',
170852ede8cSGreg Roach            'name_records'     => $name_records,
171852ede8cSGreg Roach            'sex_records'      => $sex_records,
172852ede8cSGreg Roach            'sidebars'         => $this->getSidebars($individual),
173852ede8cSGreg Roach            'tabs'             => $this->getTabs($individual),
174852ede8cSGreg Roach            'significant'      => $this->significant($individual),
1755e6816beSGreg Roach            'title'            => $individual->fullName() . ' ' . $individual->lifespan(),
176852ede8cSGreg Roach            'tree'             => $tree,
177852ede8cSGreg Roach            'user_link'        => $user_link,
178852ede8cSGreg Roach        ]);
179852ede8cSGreg Roach    }
180852ede8cSGreg Roach
181852ede8cSGreg Roach    /**
1822406e0e0SGreg Roach     * @param Individual $individual
1832406e0e0SGreg Roach     *
1842406e0e0SGreg Roach     * @return string
1852406e0e0SGreg Roach     */
1862406e0e0SGreg Roach    private function metaDescription(Individual $individual): string
1872406e0e0SGreg Roach    {
1882406e0e0SGreg Roach        $meta_facts = [];
1892406e0e0SGreg Roach
1902406e0e0SGreg Roach        $birth_date  = $individual->getBirthDate();
1912406e0e0SGreg Roach        $birth_place = $individual->getBirthPlace();
1922406e0e0SGreg Roach
1932406e0e0SGreg Roach        if ($birth_date->isOK() || $birth_place->id() !== 0) {
1942406e0e0SGreg Roach            $meta_facts[] = I18N::translate('Birth') . ' ' .
1952406e0e0SGreg Roach                $birth_date->display(false, null, false) . ' ' .
1962406e0e0SGreg Roach                $birth_place->placeName();
1972406e0e0SGreg Roach        }
1982406e0e0SGreg Roach
1992406e0e0SGreg Roach        $death_date  = $individual->getDeathDate();
2002406e0e0SGreg Roach        $death_place = $individual->getDeathPlace();
2012406e0e0SGreg Roach
2022406e0e0SGreg Roach        if ($death_date->isOK() || $death_place->id() !== 0) {
2032406e0e0SGreg Roach            $meta_facts[] = I18N::translate('Death') . ' ' .
2042406e0e0SGreg Roach                $death_date->display(false, null, false) . ' ' .
2052406e0e0SGreg Roach                $death_place->placeName();
2062406e0e0SGreg Roach        }
2072406e0e0SGreg Roach
2082406e0e0SGreg Roach        foreach ($individual->childFamilies() as $family) {
2092406e0e0SGreg Roach            $meta_facts[] = I18N::translate('Parents') . ' ' . $family->fullName();
2102406e0e0SGreg Roach        }
2112406e0e0SGreg Roach
2122406e0e0SGreg Roach        foreach ($individual->spouseFamilies() as $family) {
2132406e0e0SGreg Roach            $spouse = $family->spouse($individual);
2142406e0e0SGreg Roach            if ($spouse instanceof Individual) {
2152406e0e0SGreg Roach                $meta_facts[] = I18N::translate('Spouse') . ' ' . $spouse->fullName();
2162406e0e0SGreg Roach            }
2172406e0e0SGreg Roach
2182406e0e0SGreg Roach            $child_names = $family->children()->map(static function (Individual $individual): string {
2192406e0e0SGreg Roach                return e($individual->getAllNames()[0]['givn']);
2202406e0e0SGreg Roach            })->implode(', ');
2212406e0e0SGreg Roach
2222406e0e0SGreg Roach
2232406e0e0SGreg Roach            if ($child_names !== '') {
2242406e0e0SGreg Roach                $meta_facts[] = I18N::translate('Children') . ' ' . $child_names;
2252406e0e0SGreg Roach            }
2262406e0e0SGreg Roach        }
2272406e0e0SGreg Roach
2282406e0e0SGreg Roach        $meta_facts = array_map('strip_tags', $meta_facts);
2292406e0e0SGreg Roach        $meta_facts = array_map('trim', $meta_facts);
2302406e0e0SGreg Roach
2312406e0e0SGreg Roach        return implode(', ', $meta_facts);
2322406e0e0SGreg Roach    }
2332406e0e0SGreg Roach
2342406e0e0SGreg Roach    /**
235852ede8cSGreg Roach     * Format a name record
236852ede8cSGreg Roach     *
237852ede8cSGreg Roach     * @param Tree $tree
238852ede8cSGreg Roach     * @param int  $n
239852ede8cSGreg Roach     * @param Fact $fact
240852ede8cSGreg Roach     *
241852ede8cSGreg Roach     * @return string
242852ede8cSGreg Roach     */
243852ede8cSGreg Roach    private function formatNameRecord(Tree $tree, $n, Fact $fact): string
244852ede8cSGreg Roach    {
245852ede8cSGreg Roach        $individual = $fact->record();
246852ede8cSGreg Roach
247852ede8cSGreg Roach        // Create a dummy record, so we can extract the formatted NAME value from it.
248852ede8cSGreg Roach        $dummy = new Individual(
249852ede8cSGreg Roach            'xref',
250852ede8cSGreg Roach            "0 @xref@ INDI\n1 DEAT Y\n" . $fact->gedcom(),
251852ede8cSGreg Roach            null,
252852ede8cSGreg Roach            $individual->tree()
253852ede8cSGreg Roach        );
254852ede8cSGreg Roach        $dummy->setPrimaryName(0); // Make sure we use the name from "1 NAME"
255852ede8cSGreg Roach
256852ede8cSGreg Roach        $container_class = 'card';
257852ede8cSGreg Roach        $content_class   = 'collapse';
258852ede8cSGreg Roach        $aria            = 'false';
259852ede8cSGreg Roach
260852ede8cSGreg Roach        if ($n === 0) {
261852ede8cSGreg Roach            $content_class = 'collapse show';
262852ede8cSGreg Roach            $aria          = 'true';
263852ede8cSGreg Roach        }
264852ede8cSGreg Roach        if ($fact->isPendingDeletion()) {
265852ede8cSGreg Roach            $container_class .= ' wt-old';
266852ede8cSGreg Roach        } elseif ($fact->isPendingAddition()) {
267852ede8cSGreg Roach            $container_class .= ' wt-new';
268852ede8cSGreg Roach        }
269852ede8cSGreg Roach
270852ede8cSGreg Roach        ob_start();
27160a3f275SGreg Roach        echo '<dl class="row mb-0"><dt class="col-md-4 col-lg-3">', I18N::translate('Name'), '</dt>';
27260a3f275SGreg Roach        echo '<dd class="col-md-8 col-lg-9">', $dummy->fullName(), '</dd>';
273852ede8cSGreg Roach        $ct = preg_match_all('/\n2 (\w+) (.*)/', $fact->gedcom(), $nmatch, PREG_SET_ORDER);
274852ede8cSGreg Roach        for ($i = 0; $i < $ct; $i++) {
275852ede8cSGreg Roach            $tag = $nmatch[$i][1];
276852ede8cSGreg Roach            if ($tag !== 'SOUR' && $tag !== 'NOTE' && $tag !== 'SPFX') {
27760a3f275SGreg Roach                echo '<dt class="col-md-4 col-lg-3">', GedcomTag::getLabel($tag, $individual), '</dt>';
27860a3f275SGreg Roach                echo '<dd class="col-md-8 col-lg-9">'; // Before using dir="auto" on this field, note that Gecko treats this as an inline element but WebKit treats it as a block element
279852ede8cSGreg Roach                if (isset($nmatch[$i][2])) {
280852ede8cSGreg Roach                    $name = e($nmatch[$i][2]);
281852ede8cSGreg Roach                    $name = str_replace('/', '', $name);
282852ede8cSGreg Roach                    $name = preg_replace('/(\S*)\*/', '<span class="starredname">\\1</span>', $name);
283852ede8cSGreg Roach                    switch ($tag) {
284852ede8cSGreg Roach                        case 'TYPE':
285852ede8cSGreg Roach                            echo GedcomCodeName::getValue($name, $individual);
286852ede8cSGreg Roach                            break;
287852ede8cSGreg Roach                        case 'SURN':
288852ede8cSGreg Roach                            // The SURN field is not necessarily the surname.
289852ede8cSGreg Roach                            // Where it is not a substring of the real surname, show it after the real surname.
290852ede8cSGreg Roach                            $surname = e($dummy->getAllNames()[0]['surname']);
291852ede8cSGreg Roach                            $surns   = preg_replace('/, */', ' ', $nmatch[$i][2]);
292852ede8cSGreg Roach                            if (strpos($dummy->getAllNames()[0]['surname'], $surns) !== false) {
293852ede8cSGreg Roach                                echo '<span dir="auto">' . $surname . '</span>';
294852ede8cSGreg Roach                            } else {
295852ede8cSGreg Roach                                echo I18N::translate('%1$s (%2$s)', '<span dir="auto">' . $surname . '</span>', '<span dir="auto">' . $name . '</span>');
296852ede8cSGreg Roach                            }
297852ede8cSGreg Roach                            break;
298852ede8cSGreg Roach                        default:
299852ede8cSGreg Roach                            echo '<span dir="auto">' . $name . '</span>';
300852ede8cSGreg Roach                            break;
301852ede8cSGreg Roach                    }
302852ede8cSGreg Roach                }
303852ede8cSGreg Roach                echo '</dd>';
304852ede8cSGreg Roach            }
305852ede8cSGreg Roach        }
306852ede8cSGreg Roach        echo '</dl>';
307852ede8cSGreg Roach        if (strpos($fact->gedcom(), "\n2 SOUR") !== false) {
308852ede8cSGreg Roach            echo '<div id="indi_sour" class="clearfix">', FunctionsPrintFacts::printFactSources($tree, $fact->gedcom(), 2), '</div>';
309852ede8cSGreg Roach        }
310852ede8cSGreg Roach        if (strpos($fact->gedcom(), "\n2 NOTE") !== false) {
311852ede8cSGreg Roach            echo '<div id="indi_note" class="clearfix">', FunctionsPrint::printFactNotes($tree, $fact->gedcom(), 2), '</div>';
312852ede8cSGreg Roach        }
313852ede8cSGreg Roach        $content = ob_get_clean();
314852ede8cSGreg Roach
315852ede8cSGreg Roach        if ($fact->canEdit()) {
316852ede8cSGreg Roach            $edit_links =
317852ede8cSGreg Roach                '<a class="btn btn-link" href="#" data-confirm="' . I18N::translate('Are you sure you want to delete this fact?') . '" data-post-url="' . e(route(DeleteFact::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'fact_id' => $fact->id()])) . '" title="' . I18N::translate('Delete this name') . '">' . view('icons/delete') . '<span class="sr-only">' . I18N::translate('Delete this name') . '</span></a>' .
318852ede8cSGreg Roach                '<a class="btn btn-link" href="' . e(route('edit-name', ['xref' => $individual->xref(), 'fact_id' => $fact->id(), 'tree' => $individual->tree()->name()])) . '" title="' . I18N::translate('Edit the name') . '">' . view('icons/edit') . '<span class="sr-only">' . I18N::translate('Edit the name') . '</span></a>';
319852ede8cSGreg Roach        } else {
320852ede8cSGreg Roach            $edit_links = '';
321852ede8cSGreg Roach        }
322852ede8cSGreg Roach
323852ede8cSGreg Roach        return '
324852ede8cSGreg Roach			<div class="' . $container_class . '">
325852ede8cSGreg Roach        <div class="card-header" role="tab" id="name-header-' . $n . '">
326852ede8cSGreg Roach		        <a data-toggle="collapse" data-parent="#individual-names" href="#name-content-' . $n . '" aria-expanded="' . $aria . '" aria-controls="name-content-' . $n . '">' . $dummy->fullName() . '</a>
327852ede8cSGreg Roach		      ' . $edit_links . '
328852ede8cSGreg Roach        </div>
329852ede8cSGreg Roach		    <div id="name-content-' . $n . '" class="' . $content_class . '" role="tabpanel" aria-labelledby="name-header-' . $n . '">
330852ede8cSGreg Roach		      <div class="card-body">' . $content . '</div>
331852ede8cSGreg Roach        </div>
332852ede8cSGreg Roach      </div>';
333852ede8cSGreg Roach    }
334852ede8cSGreg Roach
335852ede8cSGreg Roach    /**
336852ede8cSGreg Roach     * print information for a sex record
337852ede8cSGreg Roach     *
338852ede8cSGreg Roach     * @param Fact $fact
339852ede8cSGreg Roach     *
340852ede8cSGreg Roach     * @return string
341852ede8cSGreg Roach     */
342852ede8cSGreg Roach    private function formatSexRecord(Fact $fact): string
343852ede8cSGreg Roach    {
344852ede8cSGreg Roach        $individual = $fact->record();
345852ede8cSGreg Roach
346852ede8cSGreg Roach        switch ($fact->value()) {
347852ede8cSGreg Roach            case 'M':
348852ede8cSGreg Roach                $sex = I18N::translate('Male');
349852ede8cSGreg Roach                break;
350852ede8cSGreg Roach            case 'F':
351852ede8cSGreg Roach                $sex = I18N::translate('Female');
352852ede8cSGreg Roach                break;
353852ede8cSGreg Roach            default:
354852ede8cSGreg Roach                $sex = I18N::translateContext('unknown gender', 'Unknown');
355852ede8cSGreg Roach                break;
356852ede8cSGreg Roach        }
357852ede8cSGreg Roach
358852ede8cSGreg Roach        $container_class = 'card';
359852ede8cSGreg Roach        if ($fact->isPendingDeletion()) {
360852ede8cSGreg Roach            $container_class .= ' wt-old';
361852ede8cSGreg Roach        } elseif ($fact->isPendingAddition()) {
362852ede8cSGreg Roach            $container_class .= ' wt-new';
363852ede8cSGreg Roach        }
364852ede8cSGreg Roach
365852ede8cSGreg Roach        if ($individual->canEdit()) {
366852ede8cSGreg Roach            $edit_links = '<a class="btn btn-link" href="' . e(route(EditFact::class, ['xref' => $individual->xref(), 'fact_id' => $fact->id(), 'tree' => $individual->tree()->name()])) . '" title="' . I18N::translate('Edit the gender') . '">' . view('icons/edit') . '<span class="sr-only">' . I18N::translate('Edit the gender') . '</span></a>';
367852ede8cSGreg Roach        } else {
368852ede8cSGreg Roach            $edit_links = '';
369852ede8cSGreg Roach        }
370852ede8cSGreg Roach
371852ede8cSGreg Roach        return '
372852ede8cSGreg Roach		<div class="' . $container_class . '">
373852ede8cSGreg Roach			<div class="card-header" role="tab" id="name-header-add">
374852ede8cSGreg Roach				<div class="card-title mb-0">
375852ede8cSGreg Roach					<b>' . I18N::translate('Gender') . '</b> ' . $sex . $edit_links . '
376852ede8cSGreg Roach				</div>
377852ede8cSGreg Roach			</div>
378852ede8cSGreg Roach		</div>';
379852ede8cSGreg Roach    }
380852ede8cSGreg Roach
381852ede8cSGreg Roach    /**
382852ede8cSGreg Roach     * Which tabs should we show on this individual's page.
383852ede8cSGreg Roach     * We don't show empty tabs.
384852ede8cSGreg Roach     *
385852ede8cSGreg Roach     * @param Individual $individual
386852ede8cSGreg Roach     *
387b5c8fd7eSGreg Roach     * @return Collection<ModuleSidebarInterface>
388852ede8cSGreg Roach     */
389852ede8cSGreg Roach    public function getSidebars(Individual $individual): Collection
390852ede8cSGreg Roach    {
391852ede8cSGreg Roach        return $this->module_service->findByComponent(ModuleSidebarInterface::class, $individual->tree(), Auth::user())
392852ede8cSGreg Roach            ->filter(static function (ModuleSidebarInterface $sidebar) use ($individual): bool {
393852ede8cSGreg Roach                return $sidebar->hasSidebarContent($individual);
394852ede8cSGreg Roach            });
395852ede8cSGreg Roach    }
396852ede8cSGreg Roach
397852ede8cSGreg Roach    /**
398852ede8cSGreg Roach     * Which tabs should we show on this individual's page.
399852ede8cSGreg Roach     * We don't show empty tabs.
400852ede8cSGreg Roach     *
401852ede8cSGreg Roach     * @param Individual $individual
402852ede8cSGreg Roach     *
403b5c8fd7eSGreg Roach     * @return Collection<ModuleTabInterface>
404852ede8cSGreg Roach     */
405852ede8cSGreg Roach    public function getTabs(Individual $individual): Collection
406852ede8cSGreg Roach    {
407852ede8cSGreg Roach        return $this->module_service->findByComponent(ModuleTabInterface::class, $individual->tree(), Auth::user())
408852ede8cSGreg Roach            ->filter(static function (ModuleTabInterface $tab) use ($individual): bool {
409852ede8cSGreg Roach                return $tab->hasTabContent($individual);
410852ede8cSGreg Roach            });
411852ede8cSGreg Roach    }
412852ede8cSGreg Roach
413852ede8cSGreg Roach    /**
414852ede8cSGreg Roach     * What are the significant elements of this page?
415852ede8cSGreg Roach     * The layout will need them to generate URLs for charts and reports.
416852ede8cSGreg Roach     *
417852ede8cSGreg Roach     * @param Individual $individual
418852ede8cSGreg Roach     *
419852ede8cSGreg Roach     * @return stdClass
420852ede8cSGreg Roach     */
421852ede8cSGreg Roach    private function significant(Individual $individual): stdClass
422852ede8cSGreg Roach    {
423852ede8cSGreg Roach        [$surname] = explode(',', $individual->sortName());
424852ede8cSGreg Roach
425852ede8cSGreg Roach        $family = $individual->childFamilies()->merge($individual->spouseFamilies())->first();
426852ede8cSGreg Roach
427852ede8cSGreg Roach        return (object) [
428852ede8cSGreg Roach            'family'     => $family,
429852ede8cSGreg Roach            'individual' => $individual,
430852ede8cSGreg Roach            'surname'    => $surname,
431852ede8cSGreg Roach        ];
432852ede8cSGreg Roach    }
433852ede8cSGreg Roach}
434