xref: /webtrees/app/Family.php (revision f25fc0f929f69ab8124cf0cecde45e457db7574a)
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)
36eec9de3fSGreg Roach    private ?Individual $husb = null;
37a25f0a04SGreg Roach
3833c746f1SGreg Roach    // The wife (or second spouse for same-sex couples)
39eec9de3fSGreg Roach    private ?Individual $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     */
50e364afe4SGreg Roach    public function __construct(string $xref, string $gedcom, ?string $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    {
72*f25fc0f9SGreg 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     */
1082c6f1bd5SGreg Roach    public function husband(int|null $access_level = null): ?Individual
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     */
1282c6f1bd5SGreg Roach    public function wife(int|null $access_level = null): ?Individual
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     */
1842c6f1bd5SGreg Roach    public function spouse(Individual $person, int|null $access_level = null): ?Individual
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     *
25766107289SGreg Roach     * @return Fact|null
258a25f0a04SGreg Roach     */
259820b62dfSGreg Roach    public function getMarriage(): ?Fact
260c1010edaSGreg Roach    {
261820b62dfSGreg Roach        return $this->facts(['MARR'])->first();
262a25f0a04SGreg Roach    }
263a25f0a04SGreg Roach
264a25f0a04SGreg Roach    /**
265a25f0a04SGreg Roach     * Get marriage date
266a25f0a04SGreg Roach     *
267a25f0a04SGreg Roach     * @return Date
268a25f0a04SGreg Roach     */
269820b62dfSGreg Roach    public function getMarriageDate(): Date
270c1010edaSGreg Roach    {
271a25f0a04SGreg Roach        $marriage = $this->getMarriage();
272b6ec1ccfSGreg Roach        if ($marriage instanceof Fact) {
2732decada7SGreg Roach            return $marriage->date();
274a25f0a04SGreg Roach        }
275b2ce94c6SRico Sonntag
276b2ce94c6SRico Sonntag        return new Date('');
277a25f0a04SGreg Roach    }
278a25f0a04SGreg Roach
279a25f0a04SGreg Roach    /**
280a25f0a04SGreg Roach     * Get the marriage year - displayed on lists of families
281a25f0a04SGreg Roach     *
282cbc1590aSGreg Roach     * @return int
283a25f0a04SGreg Roach     */
2848f53f488SRico Sonntag    public function getMarriageYear(): int
285c1010edaSGreg Roach    {
2864a83f5d7SGreg Roach        return $this->getMarriageDate()->minimumDate()->year;
287a25f0a04SGreg Roach    }
288a25f0a04SGreg Roach
289a25f0a04SGreg Roach    /**
290a25f0a04SGreg Roach     * Get the marriage place
291a25f0a04SGreg Roach     *
292a25f0a04SGreg Roach     * @return Place
293a25f0a04SGreg Roach     */
2948f53f488SRico Sonntag    public function getMarriagePlace(): Place
295c1010edaSGreg Roach    {
296a25f0a04SGreg Roach        $marriage = $this->getMarriage();
297a25f0a04SGreg Roach
2987abafad0SGreg Roach        if ($marriage instanceof Fact) {
2994fb14fcbSGreg Roach            return $marriage->place();
300a25f0a04SGreg Roach        }
301a25f0a04SGreg Roach
3027abafad0SGreg Roach        return new Place('', $this->tree);
3037abafad0SGreg Roach    }
3047abafad0SGreg Roach
305a25f0a04SGreg Roach    /**
306a25f0a04SGreg Roach     * Get a list of all marriage dates - for the family lists.
307a25f0a04SGreg Roach     *
30809482a55SGreg Roach     * @return array<Date>
309a25f0a04SGreg Roach     */
3108f53f488SRico Sonntag    public function getAllMarriageDates(): array
311c1010edaSGreg Roach    {
3128d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3137abafad0SGreg Roach            $array = $this->getAllEventDates([$event]);
3148af3e5c1SGreg Roach
31554c1ab5eSGreg Roach            if ($array !== []) {
316a25f0a04SGreg Roach                return $array;
317a25f0a04SGreg Roach            }
318a25f0a04SGreg Roach        }
319a25f0a04SGreg Roach
32013abd6f3SGreg Roach        return [];
321a25f0a04SGreg Roach    }
322a25f0a04SGreg Roach
323a25f0a04SGreg Roach    /**
324a25f0a04SGreg Roach     * Get a list of all marriage places - for the family lists.
325a25f0a04SGreg Roach     *
32609482a55SGreg Roach     * @return array<Place>
327a25f0a04SGreg Roach     */
3288f53f488SRico Sonntag    public function getAllMarriagePlaces(): array
329c1010edaSGreg Roach    {
3308d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3316e83554dSGreg Roach            $places = $this->getAllEventPlaces([$event]);
33254c1ab5eSGreg Roach            if ($places !== []) {
3334080d558SGreg Roach                return $places;
334a25f0a04SGreg Roach            }
335a25f0a04SGreg Roach        }
336a25f0a04SGreg Roach
33713abd6f3SGreg Roach        return [];
338a25f0a04SGreg Roach    }
339a25f0a04SGreg Roach
34076692c8bSGreg Roach    /**
34176692c8bSGreg Roach     * Derived classes should redefine this function, otherwise the object will have no name
34276692c8bSGreg Roach     *
343870ec5a3SGreg Roach     * @return array<int,array<string,string>>
34476692c8bSGreg Roach     */
3458f53f488SRico Sonntag    public function getAllNames(): array
346c1010edaSGreg Roach    {
3479599771eSGreg Roach        if ($this->getAllNames === []) {
348a25f0a04SGreg Roach            // Check the script used by each name, so we can match cyrillic with cyrillic, greek with greek, etc.
349e88674d4SGreg Roach            $husb_names = [];
350b6ec1ccfSGreg Roach            if ($this->husb instanceof Individual) {
351*f25fc0f9SGreg Roach                $husb_names = array_filter($this->husb->getAllNames(), static fn(array $x): bool => $x['type'] !== '_MARNM');
352e88674d4SGreg Roach            }
3531f244d77SGreg Roach            // If the individual only has married names, create a fake birth name.
35454c1ab5eSGreg Roach            if ($husb_names === []) {
355e88674d4SGreg Roach                $husb_names[] = [
356a25f0a04SGreg Roach                    'type' => 'BIRT',
3578fb4e87cSGreg Roach                    'sort' => Individual::NOMEN_NESCIO,
358ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
35913abd6f3SGreg Roach                ];
360a25f0a04SGreg Roach            }
361a25f0a04SGreg Roach            foreach ($husb_names as $n => $husb_name) {
362a25f0a04SGreg Roach                $husb_names[$n]['script'] = I18N::textScript($husb_name['full']);
363a25f0a04SGreg Roach            }
364e88674d4SGreg Roach
365e88674d4SGreg Roach            $wife_names = [];
366b6ec1ccfSGreg Roach            if ($this->wife instanceof Individual) {
367*f25fc0f9SGreg Roach                $wife_names = array_filter($this->wife->getAllNames(), static fn(array $x): bool => $x['type'] !== '_MARNM');
368e88674d4SGreg Roach            }
3691f244d77SGreg Roach            // If the individual only has married names, create a fake birth name.
37054c1ab5eSGreg Roach            if ($wife_names === []) {
371e88674d4SGreg Roach                $wife_names[] = [
372a25f0a04SGreg Roach                    'type' => 'BIRT',
3738fb4e87cSGreg Roach                    'sort' => Individual::NOMEN_NESCIO,
374ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
37513abd6f3SGreg Roach                ];
376a25f0a04SGreg Roach            }
377a25f0a04SGreg Roach            foreach ($wife_names as $n => $wife_name) {
378a25f0a04SGreg Roach                $wife_names[$n]['script'] = I18N::textScript($wife_name['full']);
379a25f0a04SGreg Roach            }
380e88674d4SGreg Roach
381a25f0a04SGreg Roach            // Add the matched names first
382a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
383a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
384e364afe4SGreg Roach                    if ($husb_name['script'] === $wife_name['script']) {
385bdb3725aSGreg Roach                        $this->getAllNames[] = [
386a25f0a04SGreg Roach                            'type' => $husb_name['type'],
387a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
388a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
389a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
39013abd6f3SGreg Roach                        ];
391a25f0a04SGreg Roach                    }
392a25f0a04SGreg Roach                }
393a25f0a04SGreg Roach            }
394e88674d4SGreg Roach
395a25f0a04SGreg Roach            // Add the unmatched names second (there may be no matched names)
396a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
397a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
398e364afe4SGreg Roach                    if ($husb_name['script'] !== $wife_name['script']) {
399bdb3725aSGreg Roach                        $this->getAllNames[] = [
400a25f0a04SGreg Roach                            'type' => $husb_name['type'],
401a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
402a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
403a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
40413abd6f3SGreg Roach                        ];
405a25f0a04SGreg Roach                    }
406a25f0a04SGreg Roach                }
407a25f0a04SGreg Roach            }
408a25f0a04SGreg Roach        }
409a25f0a04SGreg Roach
410bdb3725aSGreg Roach        return $this->getAllNames;
411a25f0a04SGreg Roach    }
412a25f0a04SGreg Roach
41376692c8bSGreg Roach    /**
41476692c8bSGreg Roach     * This function should be redefined in derived classes to show any major
41576692c8bSGreg Roach     * identifying characteristics of this record.
41676692c8bSGreg Roach     *
41776692c8bSGreg Roach     * @return string
41876692c8bSGreg Roach     */
4198f53f488SRico Sonntag    public function formatListDetails(): string
420c1010edaSGreg Roach    {
421a25f0a04SGreg Roach        return
4228d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 1) .
4238d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 1);
424a25f0a04SGreg Roach    }
4258091bfd1SGreg Roach
4268091bfd1SGreg Roach    /**
4278091bfd1SGreg Roach     * Lock the database row, to prevent concurrent edits.
4288091bfd1SGreg Roach     */
4298091bfd1SGreg Roach    public function lock(): void
4308091bfd1SGreg Roach    {
4318091bfd1SGreg Roach        DB::table('families')
4328091bfd1SGreg Roach            ->where('f_file', '=', $this->tree->id())
4338091bfd1SGreg Roach            ->where('f_id', '=', $this->xref())
4348091bfd1SGreg Roach            ->lockForUpdate()
4358091bfd1SGreg Roach            ->get();
4368091bfd1SGreg Roach    }
437a25f0a04SGreg Roach}
438