xref: /webtrees/app/Family.php (revision 1ff45046fabc22237b5d0d8e489c96f031fc598d)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a25f0a04SGreg Roach * (at your option) any later version.
10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a25f0a04SGreg Roach * GNU General Public License for more details.
14a25f0a04SGreg 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/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees;
21a25f0a04SGreg Roach
22886b77daSGreg Roachuse Closure;
23d7daee59SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\FamilyPage;
24820b62dfSGreg Roachuse Illuminate\Support\Collection;
252e5b4452SGreg Roach
26a25f0a04SGreg Roach/**
2776692c8bSGreg Roach * A GEDCOM family (FAM) object.
28a25f0a04SGreg Roach */
29c1010edaSGreg Roachclass Family extends GedcomRecord
30c1010edaSGreg Roach{
3116d6367aSGreg Roach    public const RECORD_TYPE = 'FAM';
3216d6367aSGreg Roach
33d7daee59SGreg Roach    protected const ROUTE_NAME = FamilyPage::class;
34a25f0a04SGreg Roach
3533c746f1SGreg Roach    // The husband (or first spouse for same-sex couples)
36*1ff45046SGreg Roach    private Individual|null $husb = null;
37a25f0a04SGreg Roach
3833c746f1SGreg Roach    // The wife (or second spouse for same-sex couples)
39*1ff45046SGreg Roach    private Individual|null $wife = null;
40a25f0a04SGreg Roach
4176692c8bSGreg Roach    /**
4276692c8bSGreg Roach     * Create a GedcomRecord object from raw GEDCOM data.
4376692c8bSGreg Roach     *
4476692c8bSGreg Roach     * @param string      $xref
4576692c8bSGreg Roach     * @param string      $gedcom  an empty string for new/pending records
4676692c8bSGreg Roach     * @param string|null $pending null for a record with no pending edits,
4776692c8bSGreg Roach     *                             empty string for records with pending deletions
4876692c8bSGreg Roach     * @param Tree        $tree
4976692c8bSGreg Roach     */
50*1ff45046SGreg Roach    public function __construct(string $xref, string $gedcom, string|null $pending, Tree $tree)
51c1010edaSGreg Roach    {
5224ec66ceSGreg Roach        parent::__construct($xref, $gedcom, $pending, $tree);
53a25f0a04SGreg Roach
5414239cc9SGreg Roach        // Make sure we find records in pending records.
5514239cc9SGreg Roach        $gedcom_pending = $gedcom . "\n" . $pending;
5614239cc9SGreg Roach
5714239cc9SGreg Roach        if (preg_match('/\n1 HUSB @(.+)@/', $gedcom_pending, $match)) {
586b9cb339SGreg Roach            $this->husb = Registry::individualFactory()->make($match[1], $tree);
59a25f0a04SGreg Roach        }
6014239cc9SGreg Roach        if (preg_match('/\n1 WIFE @(.+)@/', $gedcom_pending, $match)) {
616b9cb339SGreg Roach            $this->wife = Registry::individualFactory()->make($match[1], $tree);
62a25f0a04SGreg Roach        }
63a25f0a04SGreg Roach    }
64a25f0a04SGreg Roach
6576692c8bSGreg Roach    /**
66c156e8f5SGreg Roach     * A closure which will compare families by marriage date.
67c156e8f5SGreg Roach     *
68c6921a17SGreg Roach     * @return Closure(Family,Family):int
69c156e8f5SGreg Roach     */
70c156e8f5SGreg Roach    public static function marriageDateComparator(): Closure
71c156e8f5SGreg Roach    {
72f25fc0f9SGreg Roach        return static fn(Family $x, Family $y): int => Date::compare($x->getMarriageDate(), $y->getMarriageDate());
73c156e8f5SGreg Roach    }
74c156e8f5SGreg Roach
75c156e8f5SGreg Roach    /**
7676692c8bSGreg Roach     * Generate a private version of this record
7776692c8bSGreg Roach     *
7876692c8bSGreg Roach     * @param int $access_level
7976692c8bSGreg Roach     *
8076692c8bSGreg Roach     * @return string
8176692c8bSGreg Roach     */
823c90ed31SGreg Roach    protected function createPrivateGedcomRecord(int $access_level): string
83c1010edaSGreg Roach    {
84d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
85d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
86d9e083e7SGreg Roach        }
87a25f0a04SGreg Roach
88a25f0a04SGreg Roach        $rec = '0 @' . $this->xref . '@ FAM';
89a25f0a04SGreg Roach        // Just show the 1 CHIL/HUSB/WIFE tag, not any subtags, which may contain private data
908d0ebef0SGreg Roach        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches, PREG_SET_ORDER);
91a25f0a04SGreg Roach        foreach ($matches as $match) {
926b9cb339SGreg Roach            $rela = Registry::individualFactory()->make($match[1], $this->tree);
93d9e083e7SGreg Roach            if ($rela instanceof Individual && $rela->canShow($access_level)) {
94a25f0a04SGreg Roach                $rec .= $match[0];
95a25f0a04SGreg Roach            }
96a25f0a04SGreg Roach        }
97a25f0a04SGreg Roach
98a25f0a04SGreg Roach        return $rec;
99a25f0a04SGreg Roach    }
100a25f0a04SGreg Roach
10176692c8bSGreg Roach    /**
102a25f0a04SGreg Roach     * Get the male (or first female) partner of the family
103a25f0a04SGreg Roach     *
104e93111adSRico Sonntag     * @param int|null $access_level
105b3f49e6cSGreg Roach     *
106a25f0a04SGreg Roach     * @return Individual|null
107a25f0a04SGreg Roach     */
108*1ff45046SGreg Roach    public function husband(int|null $access_level = null): Individual|null
109c1010edaSGreg Roach    {
110d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
111d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
112d9e083e7SGreg Roach        }
113b3f49e6cSGreg Roach
114d9e083e7SGreg Roach        if ($this->husb instanceof Individual && $this->husb->canShowName($access_level)) {
115a25f0a04SGreg Roach            return $this->husb;
116a25f0a04SGreg Roach        }
117b2ce94c6SRico Sonntag
118b2ce94c6SRico Sonntag        return null;
119a25f0a04SGreg Roach    }
120a25f0a04SGreg Roach
121a25f0a04SGreg Roach    /**
122a25f0a04SGreg Roach     * Get the female (or second male) partner of the family
123a25f0a04SGreg Roach     *
124e93111adSRico Sonntag     * @param int|null $access_level
125b3f49e6cSGreg Roach     *
126a25f0a04SGreg Roach     * @return Individual|null
127a25f0a04SGreg Roach     */
128*1ff45046SGreg Roach    public function wife(int|null $access_level = null): Individual|null
129c1010edaSGreg Roach    {
130d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
131d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
132d9e083e7SGreg Roach        }
133b3f49e6cSGreg Roach
134d9e083e7SGreg Roach        if ($this->wife instanceof Individual && $this->wife->canShowName($access_level)) {
135a25f0a04SGreg Roach            return $this->wife;
136a25f0a04SGreg Roach        }
137b2ce94c6SRico Sonntag
138b2ce94c6SRico Sonntag        return null;
139a25f0a04SGreg Roach    }
140a25f0a04SGreg Roach
14176692c8bSGreg Roach    /**
14276692c8bSGreg Roach     * Each object type may have its own special rules, and re-implement this function.
14376692c8bSGreg Roach     *
14476692c8bSGreg Roach     * @param int $access_level
14576692c8bSGreg Roach     *
14676692c8bSGreg Roach     * @return bool
14776692c8bSGreg Roach     */
14835584196SGreg Roach    protected function canShowByType(int $access_level): bool
149c1010edaSGreg Roach    {
150a25f0a04SGreg Roach        // Hide a family if any member is private
1518d0ebef0SGreg Roach        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches);
152a25f0a04SGreg Roach        foreach ($matches[1] as $match) {
1536b9cb339SGreg Roach            $person = Registry::individualFactory()->make($match, $this->tree);
154a25f0a04SGreg Roach            if ($person && !$person->canShow($access_level)) {
155a25f0a04SGreg Roach                return false;
156a25f0a04SGreg Roach            }
157a25f0a04SGreg Roach        }
158a25f0a04SGreg Roach
159a25f0a04SGreg Roach        return true;
160a25f0a04SGreg Roach    }
161a25f0a04SGreg Roach
16276692c8bSGreg Roach    /**
16376692c8bSGreg Roach     * Can the name of this record be shown?
16476692c8bSGreg Roach     *
16576692c8bSGreg Roach     * @param int|null $access_level
16676692c8bSGreg Roach     *
16776692c8bSGreg Roach     * @return bool
16876692c8bSGreg Roach     */
1692c6f1bd5SGreg Roach    public function canShowName(int|null $access_level = null): bool
170c1010edaSGreg Roach    {
171a25f0a04SGreg Roach        // We can always see the name (Husband-name + Wife-name), however,
172a25f0a04SGreg Roach        // the name will often be "private + private"
173a25f0a04SGreg Roach        return true;
174a25f0a04SGreg Roach    }
175a25f0a04SGreg Roach
176a25f0a04SGreg Roach    /**
177a25f0a04SGreg Roach     * Find the spouse of a person.
178a25f0a04SGreg Roach     *
179a25f0a04SGreg Roach     * @param Individual $person
18013e3123bSGreg Roach     * @param int|null   $access_level
181a25f0a04SGreg Roach     *
182a25f0a04SGreg Roach     * @return Individual|null
183a25f0a04SGreg Roach     */
184*1ff45046SGreg Roach    public function spouse(Individual $person, int|null $access_level = null): Individual|null
185c1010edaSGreg Roach    {
186a25f0a04SGreg Roach        if ($person === $this->wife) {
18739ca88baSGreg Roach            return $this->husband($access_level);
188a25f0a04SGreg Roach        }
189b2ce94c6SRico Sonntag
19039ca88baSGreg Roach        return $this->wife($access_level);
191a25f0a04SGreg Roach    }
192a25f0a04SGreg Roach
193a25f0a04SGreg Roach    /**
194a25f0a04SGreg Roach     * Get the (zero, one or two) spouses from this family.
195a25f0a04SGreg Roach     *
196cbc1590aSGreg Roach     * @param int|null $access_level
197a25f0a04SGreg Roach     *
19836779af1SGreg Roach     * @return Collection<int,Individual>
199a25f0a04SGreg Roach     */
2002c6f1bd5SGreg Roach    public function spouses(int|null $access_level = null): Collection
201c1010edaSGreg Roach    {
202820b62dfSGreg Roach        $spouses = new Collection([
20339ca88baSGreg Roach            $this->husband($access_level),
20439ca88baSGreg Roach            $this->wife($access_level),
20513abd6f3SGreg Roach        ]);
206820b62dfSGreg Roach
207820b62dfSGreg Roach        return $spouses->filter();
208a25f0a04SGreg Roach    }
209a25f0a04SGreg Roach
210a25f0a04SGreg Roach    /**
211a25f0a04SGreg Roach     * Get a list of this family’s children.
212a25f0a04SGreg Roach     *
213cbc1590aSGreg Roach     * @param int|null $access_level
214a25f0a04SGreg Roach     *
21536779af1SGreg Roach     * @return Collection<int,Individual>
216a25f0a04SGreg Roach     */
2172c6f1bd5SGreg Roach    public function children(int|null $access_level = null): Collection
218c1010edaSGreg Roach    {
2193529c469SGreg Roach        $access_level ??= Auth::accessLevel($this->tree);
2204b9ff166SGreg Roach
221d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
222d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
223d9e083e7SGreg Roach        }
224a25f0a04SGreg Roach
225820b62dfSGreg Roach        $children = new Collection();
226820b62dfSGreg Roach
227d9e083e7SGreg Roach        foreach ($this->facts(['CHIL'], false, $access_level) as $fact) {
228dc124885SGreg Roach            $child = $fact->target();
229820b62dfSGreg Roach
230d9e083e7SGreg Roach            if ($child instanceof Individual && $child->canShowName($access_level)) {
231820b62dfSGreg Roach                $children->push($child);
232a25f0a04SGreg Roach            }
233a25f0a04SGreg Roach        }
234a25f0a04SGreg Roach
235a25f0a04SGreg Roach        return $children;
236a25f0a04SGreg Roach    }
237a25f0a04SGreg Roach
238a25f0a04SGreg Roach    /**
239a25f0a04SGreg Roach     * Number of children - for the individual list
240a25f0a04SGreg Roach     *
241cbc1590aSGreg Roach     * @return int
242a25f0a04SGreg Roach     */
24339ca88baSGreg Roach    public function numberOfChildren(): int
244c1010edaSGreg Roach    {
245820b62dfSGreg Roach        $nchi = $this->children()->count();
246820b62dfSGreg Roach
2478d0ebef0SGreg Roach        foreach ($this->facts(['NCHI']) as $fact) {
24884586c02SGreg Roach            $nchi = max($nchi, (int) $fact->value());
249a25f0a04SGreg Roach        }
250a25f0a04SGreg Roach
251a25f0a04SGreg Roach        return $nchi;
252a25f0a04SGreg Roach    }
253a25f0a04SGreg Roach
254a25f0a04SGreg Roach    /**
255a25f0a04SGreg Roach     * get the marriage event
256a25f0a04SGreg Roach     */
257*1ff45046SGreg Roach    public function getMarriage(): Fact|null
258c1010edaSGreg Roach    {
259820b62dfSGreg Roach        return $this->facts(['MARR'])->first();
260a25f0a04SGreg Roach    }
261a25f0a04SGreg Roach
262a25f0a04SGreg Roach    /**
263a25f0a04SGreg Roach     * Get marriage date
264a25f0a04SGreg Roach     *
265a25f0a04SGreg Roach     * @return Date
266a25f0a04SGreg Roach     */
267820b62dfSGreg Roach    public function getMarriageDate(): Date
268c1010edaSGreg Roach    {
269a25f0a04SGreg Roach        $marriage = $this->getMarriage();
270b6ec1ccfSGreg Roach        if ($marriage instanceof Fact) {
2712decada7SGreg Roach            return $marriage->date();
272a25f0a04SGreg Roach        }
273b2ce94c6SRico Sonntag
274b2ce94c6SRico Sonntag        return new Date('');
275a25f0a04SGreg Roach    }
276a25f0a04SGreg Roach
277a25f0a04SGreg Roach    /**
278a25f0a04SGreg Roach     * Get the marriage year - displayed on lists of families
279a25f0a04SGreg Roach     *
280cbc1590aSGreg Roach     * @return int
281a25f0a04SGreg Roach     */
2828f53f488SRico Sonntag    public function getMarriageYear(): int
283c1010edaSGreg Roach    {
2844a83f5d7SGreg Roach        return $this->getMarriageDate()->minimumDate()->year;
285a25f0a04SGreg Roach    }
286a25f0a04SGreg Roach
287a25f0a04SGreg Roach    /**
288a25f0a04SGreg Roach     * Get the marriage place
289a25f0a04SGreg Roach     *
290a25f0a04SGreg Roach     * @return Place
291a25f0a04SGreg Roach     */
2928f53f488SRico Sonntag    public function getMarriagePlace(): Place
293c1010edaSGreg Roach    {
294a25f0a04SGreg Roach        $marriage = $this->getMarriage();
295a25f0a04SGreg Roach
2967abafad0SGreg Roach        if ($marriage instanceof Fact) {
2974fb14fcbSGreg Roach            return $marriage->place();
298a25f0a04SGreg Roach        }
299a25f0a04SGreg Roach
3007abafad0SGreg Roach        return new Place('', $this->tree);
3017abafad0SGreg Roach    }
3027abafad0SGreg Roach
303a25f0a04SGreg Roach    /**
304a25f0a04SGreg Roach     * Get a list of all marriage dates - for the family lists.
305a25f0a04SGreg Roach     *
30609482a55SGreg Roach     * @return array<Date>
307a25f0a04SGreg Roach     */
3088f53f488SRico Sonntag    public function getAllMarriageDates(): array
309c1010edaSGreg Roach    {
3108d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3117abafad0SGreg Roach            $array = $this->getAllEventDates([$event]);
3128af3e5c1SGreg Roach
31354c1ab5eSGreg Roach            if ($array !== []) {
314a25f0a04SGreg Roach                return $array;
315a25f0a04SGreg Roach            }
316a25f0a04SGreg Roach        }
317a25f0a04SGreg Roach
31813abd6f3SGreg Roach        return [];
319a25f0a04SGreg Roach    }
320a25f0a04SGreg Roach
321a25f0a04SGreg Roach    /**
322a25f0a04SGreg Roach     * Get a list of all marriage places - for the family lists.
323a25f0a04SGreg Roach     *
32409482a55SGreg Roach     * @return array<Place>
325a25f0a04SGreg Roach     */
3268f53f488SRico Sonntag    public function getAllMarriagePlaces(): array
327c1010edaSGreg Roach    {
3288d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3296e83554dSGreg Roach            $places = $this->getAllEventPlaces([$event]);
33054c1ab5eSGreg Roach            if ($places !== []) {
3314080d558SGreg Roach                return $places;
332a25f0a04SGreg Roach            }
333a25f0a04SGreg Roach        }
334a25f0a04SGreg Roach
33513abd6f3SGreg Roach        return [];
336a25f0a04SGreg Roach    }
337a25f0a04SGreg Roach
33876692c8bSGreg Roach    /**
33976692c8bSGreg Roach     * Derived classes should redefine this function, otherwise the object will have no name
34076692c8bSGreg Roach     *
341870ec5a3SGreg Roach     * @return array<int,array<string,string>>
34276692c8bSGreg Roach     */
3438f53f488SRico Sonntag    public function getAllNames(): array
344c1010edaSGreg Roach    {
3459599771eSGreg Roach        if ($this->getAllNames === []) {
346a25f0a04SGreg Roach            // Check the script used by each name, so we can match cyrillic with cyrillic, greek with greek, etc.
347e88674d4SGreg Roach            $husb_names = [];
348b6ec1ccfSGreg Roach            if ($this->husb instanceof Individual) {
349f25fc0f9SGreg Roach                $husb_names = array_filter($this->husb->getAllNames(), static fn(array $x): bool => $x['type'] !== '_MARNM');
350e88674d4SGreg Roach            }
3511f244d77SGreg Roach            // If the individual only has married names, create a fake birth name.
35254c1ab5eSGreg Roach            if ($husb_names === []) {
353e88674d4SGreg Roach                $husb_names[] = [
354a25f0a04SGreg Roach                    'type' => 'BIRT',
3558fb4e87cSGreg Roach                    'sort' => Individual::NOMEN_NESCIO,
356ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
35713abd6f3SGreg Roach                ];
358a25f0a04SGreg Roach            }
359a25f0a04SGreg Roach            foreach ($husb_names as $n => $husb_name) {
360a25f0a04SGreg Roach                $husb_names[$n]['script'] = I18N::textScript($husb_name['full']);
361a25f0a04SGreg Roach            }
362e88674d4SGreg Roach
363e88674d4SGreg Roach            $wife_names = [];
364b6ec1ccfSGreg Roach            if ($this->wife instanceof Individual) {
365f25fc0f9SGreg Roach                $wife_names = array_filter($this->wife->getAllNames(), static fn(array $x): bool => $x['type'] !== '_MARNM');
366e88674d4SGreg Roach            }
3671f244d77SGreg Roach            // If the individual only has married names, create a fake birth name.
36854c1ab5eSGreg Roach            if ($wife_names === []) {
369e88674d4SGreg Roach                $wife_names[] = [
370a25f0a04SGreg Roach                    'type' => 'BIRT',
3718fb4e87cSGreg Roach                    'sort' => Individual::NOMEN_NESCIO,
372ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
37313abd6f3SGreg Roach                ];
374a25f0a04SGreg Roach            }
375a25f0a04SGreg Roach            foreach ($wife_names as $n => $wife_name) {
376a25f0a04SGreg Roach                $wife_names[$n]['script'] = I18N::textScript($wife_name['full']);
377a25f0a04SGreg Roach            }
378e88674d4SGreg Roach
379a25f0a04SGreg Roach            // Add the matched names first
380a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
381a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
382e364afe4SGreg Roach                    if ($husb_name['script'] === $wife_name['script']) {
383bdb3725aSGreg Roach                        $this->getAllNames[] = [
384a25f0a04SGreg Roach                            'type' => $husb_name['type'],
385a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
386a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
387a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
38813abd6f3SGreg Roach                        ];
389a25f0a04SGreg Roach                    }
390a25f0a04SGreg Roach                }
391a25f0a04SGreg Roach            }
392e88674d4SGreg Roach
393a25f0a04SGreg Roach            // Add the unmatched names second (there may be no matched names)
394a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
395a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
396e364afe4SGreg Roach                    if ($husb_name['script'] !== $wife_name['script']) {
397bdb3725aSGreg Roach                        $this->getAllNames[] = [
398a25f0a04SGreg Roach                            'type' => $husb_name['type'],
399a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
400a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
401a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
40213abd6f3SGreg Roach                        ];
403a25f0a04SGreg Roach                    }
404a25f0a04SGreg Roach                }
405a25f0a04SGreg Roach            }
406a25f0a04SGreg Roach        }
407a25f0a04SGreg Roach
408bdb3725aSGreg Roach        return $this->getAllNames;
409a25f0a04SGreg Roach    }
410a25f0a04SGreg Roach
41176692c8bSGreg Roach    /**
41276692c8bSGreg Roach     * This function should be redefined in derived classes to show any major
41376692c8bSGreg Roach     * identifying characteristics of this record.
41476692c8bSGreg Roach     *
41576692c8bSGreg Roach     * @return string
41676692c8bSGreg Roach     */
4178f53f488SRico Sonntag    public function formatListDetails(): string
418c1010edaSGreg Roach    {
419a25f0a04SGreg Roach        return
4208d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 1) .
4218d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 1);
422a25f0a04SGreg Roach    }
4238091bfd1SGreg Roach
4248091bfd1SGreg Roach    /**
4258091bfd1SGreg Roach     * Lock the database row, to prevent concurrent edits.
4268091bfd1SGreg Roach     */
4278091bfd1SGreg Roach    public function lock(): void
4288091bfd1SGreg Roach    {
4298091bfd1SGreg Roach        DB::table('families')
4308091bfd1SGreg Roach            ->where('f_file', '=', $this->tree->id())
4318091bfd1SGreg Roach            ->where('f_id', '=', $this->xref())
4328091bfd1SGreg Roach            ->lockForUpdate()
4338091bfd1SGreg Roach            ->get();
4348091bfd1SGreg Roach    }
435a25f0a04SGreg Roach}
436