xref: /webtrees/app/Family.php (revision 33c746f164b5e3569fa2f04ddf7d547bd89852ee)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 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;
248091bfd1SGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
25820b62dfSGreg Roachuse Illuminate\Support\Collection;
262e5b4452SGreg Roach
27a25f0a04SGreg Roach/**
2876692c8bSGreg Roach * A GEDCOM family (FAM) object.
29a25f0a04SGreg Roach */
30c1010edaSGreg Roachclass Family extends GedcomRecord
31c1010edaSGreg Roach{
3216d6367aSGreg Roach    public const RECORD_TYPE = 'FAM';
3316d6367aSGreg Roach
34d7daee59SGreg Roach    protected const ROUTE_NAME = FamilyPage::class;
35a25f0a04SGreg Roach
36*33c746f1SGreg Roach    // The husband (or first spouse for same-sex couples)
37*33c746f1SGreg Roach    private ?Individual $husb;
38a25f0a04SGreg Roach
39*33c746f1SGreg Roach    // The wife (or second spouse for same-sex couples)
40*33c746f1SGreg Roach    private ?Individual $wife;
41a25f0a04SGreg Roach
4276692c8bSGreg Roach    /**
4376692c8bSGreg Roach     * Create a GedcomRecord object from raw GEDCOM data.
4476692c8bSGreg Roach     *
4576692c8bSGreg Roach     * @param string      $xref
4676692c8bSGreg Roach     * @param string      $gedcom  an empty string for new/pending records
4776692c8bSGreg Roach     * @param string|null $pending null for a record with no pending edits,
4876692c8bSGreg Roach     *                             empty string for records with pending deletions
4976692c8bSGreg Roach     * @param Tree        $tree
5076692c8bSGreg Roach     */
51e364afe4SGreg Roach    public function __construct(string $xref, string $gedcom, ?string $pending, Tree $tree)
52c1010edaSGreg Roach    {
5324ec66ceSGreg Roach        parent::__construct($xref, $gedcom, $pending, $tree);
54a25f0a04SGreg Roach
5514239cc9SGreg Roach        // Make sure we find records in pending records.
5614239cc9SGreg Roach        $gedcom_pending = $gedcom . "\n" . $pending;
5714239cc9SGreg Roach
5814239cc9SGreg Roach        if (preg_match('/\n1 HUSB @(.+)@/', $gedcom_pending, $match)) {
596b9cb339SGreg Roach            $this->husb = Registry::individualFactory()->make($match[1], $tree);
60a25f0a04SGreg Roach        }
6114239cc9SGreg Roach        if (preg_match('/\n1 WIFE @(.+)@/', $gedcom_pending, $match)) {
626b9cb339SGreg Roach            $this->wife = Registry::individualFactory()->make($match[1], $tree);
63a25f0a04SGreg Roach        }
64a25f0a04SGreg Roach    }
65a25f0a04SGreg Roach
6676692c8bSGreg Roach    /**
67c156e8f5SGreg Roach     * A closure which will compare families by marriage date.
68c156e8f5SGreg Roach     *
69c156e8f5SGreg Roach     * @return Closure
70c156e8f5SGreg Roach     */
71c156e8f5SGreg Roach    public static function marriageDateComparator(): Closure
72c156e8f5SGreg Roach    {
736c2179e2SGreg Roach        return static function (Family $x, Family $y): int {
74c156e8f5SGreg Roach            return Date::compare($x->getMarriageDate(), $y->getMarriageDate());
75c156e8f5SGreg Roach        };
76c156e8f5SGreg Roach    }
77c156e8f5SGreg Roach
78c156e8f5SGreg Roach    /**
7976692c8bSGreg Roach     * Generate a private version of this record
8076692c8bSGreg Roach     *
8176692c8bSGreg Roach     * @param int $access_level
8276692c8bSGreg Roach     *
8376692c8bSGreg Roach     * @return string
8476692c8bSGreg Roach     */
853c90ed31SGreg Roach    protected function createPrivateGedcomRecord(int $access_level): string
86c1010edaSGreg Roach    {
87d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
88d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
89d9e083e7SGreg Roach        }
90a25f0a04SGreg Roach
91a25f0a04SGreg Roach        $rec = '0 @' . $this->xref . '@ FAM';
92a25f0a04SGreg Roach        // Just show the 1 CHIL/HUSB/WIFE tag, not any subtags, which may contain private data
938d0ebef0SGreg Roach        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches, PREG_SET_ORDER);
94a25f0a04SGreg Roach        foreach ($matches as $match) {
956b9cb339SGreg Roach            $rela = Registry::individualFactory()->make($match[1], $this->tree);
96d9e083e7SGreg Roach            if ($rela instanceof Individual && $rela->canShow($access_level)) {
97a25f0a04SGreg Roach                $rec .= $match[0];
98a25f0a04SGreg Roach            }
99a25f0a04SGreg Roach        }
100a25f0a04SGreg Roach
101a25f0a04SGreg Roach        return $rec;
102a25f0a04SGreg Roach    }
103a25f0a04SGreg Roach
10476692c8bSGreg Roach    /**
105a25f0a04SGreg Roach     * Get the male (or first female) partner of the family
106a25f0a04SGreg Roach     *
107e93111adSRico Sonntag     * @param int|null $access_level
108b3f49e6cSGreg Roach     *
109a25f0a04SGreg Roach     * @return Individual|null
110a25f0a04SGreg Roach     */
11173d58381SGreg Roach    public function husband(int $access_level = null): ?Individual
112c1010edaSGreg Roach    {
113d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
114d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
115d9e083e7SGreg Roach        }
116b3f49e6cSGreg Roach
117d9e083e7SGreg Roach        if ($this->husb instanceof Individual && $this->husb->canShowName($access_level)) {
118a25f0a04SGreg Roach            return $this->husb;
119a25f0a04SGreg Roach        }
120b2ce94c6SRico Sonntag
121b2ce94c6SRico Sonntag        return null;
122a25f0a04SGreg Roach    }
123a25f0a04SGreg Roach
124a25f0a04SGreg Roach    /**
125a25f0a04SGreg Roach     * Get the female (or second male) partner of the family
126a25f0a04SGreg Roach     *
127e93111adSRico Sonntag     * @param int|null $access_level
128b3f49e6cSGreg Roach     *
129a25f0a04SGreg Roach     * @return Individual|null
130a25f0a04SGreg Roach     */
13173d58381SGreg Roach    public function wife(int $access_level = null): ?Individual
132c1010edaSGreg Roach    {
133d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
134d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
135d9e083e7SGreg Roach        }
136b3f49e6cSGreg Roach
137d9e083e7SGreg Roach        if ($this->wife instanceof Individual && $this->wife->canShowName($access_level)) {
138a25f0a04SGreg Roach            return $this->wife;
139a25f0a04SGreg Roach        }
140b2ce94c6SRico Sonntag
141b2ce94c6SRico Sonntag        return null;
142a25f0a04SGreg Roach    }
143a25f0a04SGreg Roach
14476692c8bSGreg Roach    /**
14576692c8bSGreg Roach     * Each object type may have its own special rules, and re-implement this function.
14676692c8bSGreg Roach     *
14776692c8bSGreg Roach     * @param int $access_level
14876692c8bSGreg Roach     *
14976692c8bSGreg Roach     * @return bool
15076692c8bSGreg Roach     */
15135584196SGreg Roach    protected function canShowByType(int $access_level): bool
152c1010edaSGreg Roach    {
153a25f0a04SGreg Roach        // Hide a family if any member is private
1548d0ebef0SGreg Roach        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches);
155a25f0a04SGreg Roach        foreach ($matches[1] as $match) {
1566b9cb339SGreg Roach            $person = Registry::individualFactory()->make($match, $this->tree);
157a25f0a04SGreg Roach            if ($person && !$person->canShow($access_level)) {
158a25f0a04SGreg Roach                return false;
159a25f0a04SGreg Roach            }
160a25f0a04SGreg Roach        }
161a25f0a04SGreg Roach
162a25f0a04SGreg Roach        return true;
163a25f0a04SGreg Roach    }
164a25f0a04SGreg Roach
16576692c8bSGreg Roach    /**
16676692c8bSGreg Roach     * Can the name of this record be shown?
16776692c8bSGreg Roach     *
16876692c8bSGreg Roach     * @param int|null $access_level
16976692c8bSGreg Roach     *
17076692c8bSGreg Roach     * @return bool
17176692c8bSGreg Roach     */
17235584196SGreg Roach    public function canShowName(int $access_level = null): bool
173c1010edaSGreg Roach    {
174a25f0a04SGreg Roach        // We can always see the name (Husband-name + Wife-name), however,
175a25f0a04SGreg Roach        // the name will often be "private + private"
176a25f0a04SGreg Roach        return true;
177a25f0a04SGreg Roach    }
178a25f0a04SGreg Roach
179a25f0a04SGreg Roach    /**
180a25f0a04SGreg Roach     * Find the spouse of a person.
181a25f0a04SGreg Roach     *
182a25f0a04SGreg Roach     * @param Individual $person
18313e3123bSGreg Roach     * @param int|null   $access_level
184a25f0a04SGreg Roach     *
185a25f0a04SGreg Roach     * @return Individual|null
186a25f0a04SGreg Roach     */
18773d58381SGreg Roach    public function spouse(Individual $person, int $access_level = null): ?Individual
188c1010edaSGreg Roach    {
189a25f0a04SGreg Roach        if ($person === $this->wife) {
19039ca88baSGreg Roach            return $this->husband($access_level);
191a25f0a04SGreg Roach        }
192b2ce94c6SRico Sonntag
19339ca88baSGreg Roach        return $this->wife($access_level);
194a25f0a04SGreg Roach    }
195a25f0a04SGreg Roach
196a25f0a04SGreg Roach    /**
197a25f0a04SGreg Roach     * Get the (zero, one or two) spouses from this family.
198a25f0a04SGreg Roach     *
199cbc1590aSGreg Roach     * @param int|null $access_level
200a25f0a04SGreg Roach     *
201b5c8fd7eSGreg Roach     * @return Collection<Individual>
202a25f0a04SGreg Roach     */
20373d58381SGreg Roach    public function spouses(int $access_level = null): Collection
204c1010edaSGreg Roach    {
205820b62dfSGreg Roach        $spouses = new Collection([
20639ca88baSGreg Roach            $this->husband($access_level),
20739ca88baSGreg Roach            $this->wife($access_level),
20813abd6f3SGreg Roach        ]);
209820b62dfSGreg Roach
210820b62dfSGreg Roach        return $spouses->filter();
211a25f0a04SGreg Roach    }
212a25f0a04SGreg Roach
213a25f0a04SGreg Roach    /**
214a25f0a04SGreg Roach     * Get a list of this family’s children.
215a25f0a04SGreg Roach     *
216cbc1590aSGreg Roach     * @param int|null $access_level
217a25f0a04SGreg Roach     *
218b5c8fd7eSGreg Roach     * @return Collection<Individual>
219a25f0a04SGreg Roach     */
22073d58381SGreg Roach    public function children(int $access_level = null): Collection
221c1010edaSGreg Roach    {
222d9e083e7SGreg Roach        $access_level = $access_level ?? Auth::accessLevel($this->tree);
2234b9ff166SGreg Roach
224d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
225d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
226d9e083e7SGreg Roach        }
227a25f0a04SGreg Roach
228820b62dfSGreg Roach        $children = new Collection();
229820b62dfSGreg Roach
230d9e083e7SGreg Roach        foreach ($this->facts(['CHIL'], false, $access_level) as $fact) {
231dc124885SGreg Roach            $child = $fact->target();
232820b62dfSGreg Roach
233d9e083e7SGreg Roach            if ($child instanceof Individual && $child->canShowName($access_level)) {
234820b62dfSGreg Roach                $children->push($child);
235a25f0a04SGreg Roach            }
236a25f0a04SGreg Roach        }
237a25f0a04SGreg Roach
238a25f0a04SGreg Roach        return $children;
239a25f0a04SGreg Roach    }
240a25f0a04SGreg Roach
241a25f0a04SGreg Roach    /**
242a25f0a04SGreg Roach     * Number of children - for the individual list
243a25f0a04SGreg Roach     *
244cbc1590aSGreg Roach     * @return int
245a25f0a04SGreg Roach     */
24639ca88baSGreg Roach    public function numberOfChildren(): int
247c1010edaSGreg Roach    {
248820b62dfSGreg Roach        $nchi = $this->children()->count();
249820b62dfSGreg Roach
2508d0ebef0SGreg Roach        foreach ($this->facts(['NCHI']) as $fact) {
25184586c02SGreg Roach            $nchi = max($nchi, (int) $fact->value());
252a25f0a04SGreg Roach        }
253a25f0a04SGreg Roach
254a25f0a04SGreg Roach        return $nchi;
255a25f0a04SGreg Roach    }
256a25f0a04SGreg Roach
257a25f0a04SGreg Roach    /**
258a25f0a04SGreg Roach     * get the marriage event
259a25f0a04SGreg Roach     *
26066107289SGreg Roach     * @return Fact|null
261a25f0a04SGreg Roach     */
262820b62dfSGreg Roach    public function getMarriage(): ?Fact
263c1010edaSGreg Roach    {
264820b62dfSGreg Roach        return $this->facts(['MARR'])->first();
265a25f0a04SGreg Roach    }
266a25f0a04SGreg Roach
267a25f0a04SGreg Roach    /**
268a25f0a04SGreg Roach     * Get marriage date
269a25f0a04SGreg Roach     *
270a25f0a04SGreg Roach     * @return Date
271a25f0a04SGreg Roach     */
272820b62dfSGreg Roach    public function getMarriageDate(): Date
273c1010edaSGreg Roach    {
274a25f0a04SGreg Roach        $marriage = $this->getMarriage();
275a25f0a04SGreg Roach        if ($marriage) {
2762decada7SGreg Roach            return $marriage->date();
277a25f0a04SGreg Roach        }
278b2ce94c6SRico Sonntag
279b2ce94c6SRico Sonntag        return new Date('');
280a25f0a04SGreg Roach    }
281a25f0a04SGreg Roach
282a25f0a04SGreg Roach    /**
283a25f0a04SGreg Roach     * Get the marriage year - displayed on lists of families
284a25f0a04SGreg Roach     *
285cbc1590aSGreg Roach     * @return int
286a25f0a04SGreg Roach     */
2878f53f488SRico Sonntag    public function getMarriageYear(): int
288c1010edaSGreg Roach    {
2894a83f5d7SGreg Roach        return $this->getMarriageDate()->minimumDate()->year;
290a25f0a04SGreg Roach    }
291a25f0a04SGreg Roach
292a25f0a04SGreg Roach    /**
293a25f0a04SGreg Roach     * Get the marriage place
294a25f0a04SGreg Roach     *
295a25f0a04SGreg Roach     * @return Place
296a25f0a04SGreg Roach     */
2978f53f488SRico Sonntag    public function getMarriagePlace(): Place
298c1010edaSGreg Roach    {
299a25f0a04SGreg Roach        $marriage = $this->getMarriage();
300a25f0a04SGreg Roach
3017abafad0SGreg Roach        if ($marriage instanceof Fact) {
3024fb14fcbSGreg Roach            return $marriage->place();
303a25f0a04SGreg Roach        }
304a25f0a04SGreg Roach
3057abafad0SGreg Roach        return new Place('', $this->tree);
3067abafad0SGreg Roach    }
3077abafad0SGreg Roach
308a25f0a04SGreg Roach    /**
309a25f0a04SGreg Roach     * Get a list of all marriage dates - for the family lists.
310a25f0a04SGreg Roach     *
31109482a55SGreg Roach     * @return array<Date>
312a25f0a04SGreg Roach     */
3138f53f488SRico Sonntag    public function getAllMarriageDates(): array
314c1010edaSGreg Roach    {
3158d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3167abafad0SGreg Roach            $array = $this->getAllEventDates([$event]);
3178af3e5c1SGreg Roach
31854c1ab5eSGreg Roach            if ($array !== []) {
319a25f0a04SGreg Roach                return $array;
320a25f0a04SGreg Roach            }
321a25f0a04SGreg Roach        }
322a25f0a04SGreg Roach
32313abd6f3SGreg Roach        return [];
324a25f0a04SGreg Roach    }
325a25f0a04SGreg Roach
326a25f0a04SGreg Roach    /**
327a25f0a04SGreg Roach     * Get a list of all marriage places - for the family lists.
328a25f0a04SGreg Roach     *
32909482a55SGreg Roach     * @return array<Place>
330a25f0a04SGreg Roach     */
3318f53f488SRico Sonntag    public function getAllMarriagePlaces(): array
332c1010edaSGreg Roach    {
3338d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3346e83554dSGreg Roach            $places = $this->getAllEventPlaces([$event]);
33554c1ab5eSGreg Roach            if ($places !== []) {
3364080d558SGreg Roach                return $places;
337a25f0a04SGreg Roach            }
338a25f0a04SGreg Roach        }
339a25f0a04SGreg Roach
34013abd6f3SGreg Roach        return [];
341a25f0a04SGreg Roach    }
342a25f0a04SGreg Roach
34376692c8bSGreg Roach    /**
34476692c8bSGreg Roach     * Derived classes should redefine this function, otherwise the object will have no name
34576692c8bSGreg Roach     *
346870ec5a3SGreg Roach     * @return array<int,array<string,string>>
34776692c8bSGreg Roach     */
3488f53f488SRico Sonntag    public function getAllNames(): array
349c1010edaSGreg Roach    {
3509599771eSGreg Roach        if ($this->getAllNames === []) {
351a25f0a04SGreg Roach            // Check the script used by each name, so we can match cyrillic with cyrillic, greek with greek, etc.
352e88674d4SGreg Roach            $husb_names = [];
353a25f0a04SGreg Roach            if ($this->husb) {
3540b5fd0a6SGreg Roach                $husb_names = array_filter($this->husb->getAllNames(), static function (array $x): bool {
3558d68cabeSGreg Roach                    return $x['type'] !== '_MARNM';
3568d68cabeSGreg Roach                });
357e88674d4SGreg Roach            }
3581f244d77SGreg Roach            // If the individual only has married names, create a fake birth name.
35954c1ab5eSGreg Roach            if ($husb_names === []) {
360e88674d4SGreg Roach                $husb_names[] = [
361a25f0a04SGreg Roach                    'type' => 'BIRT',
3628fb4e87cSGreg Roach                    'sort' => Individual::NOMEN_NESCIO,
363ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
36413abd6f3SGreg Roach                ];
365a25f0a04SGreg Roach            }
366a25f0a04SGreg Roach            foreach ($husb_names as $n => $husb_name) {
367a25f0a04SGreg Roach                $husb_names[$n]['script'] = I18N::textScript($husb_name['full']);
368a25f0a04SGreg Roach            }
369e88674d4SGreg Roach
370e88674d4SGreg Roach            $wife_names = [];
371a25f0a04SGreg Roach            if ($this->wife) {
3720b5fd0a6SGreg Roach                $wife_names = array_filter($this->wife->getAllNames(), static function (array $x): bool {
3738d68cabeSGreg Roach                    return $x['type'] !== '_MARNM';
3748d68cabeSGreg Roach                });
375e88674d4SGreg Roach            }
3761f244d77SGreg Roach            // If the individual only has married names, create a fake birth name.
37754c1ab5eSGreg Roach            if ($wife_names === []) {
378e88674d4SGreg Roach                $wife_names[] = [
379a25f0a04SGreg Roach                    'type' => 'BIRT',
3808fb4e87cSGreg Roach                    'sort' => Individual::NOMEN_NESCIO,
381ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
38213abd6f3SGreg Roach                ];
383a25f0a04SGreg Roach            }
384a25f0a04SGreg Roach            foreach ($wife_names as $n => $wife_name) {
385a25f0a04SGreg Roach                $wife_names[$n]['script'] = I18N::textScript($wife_name['full']);
386a25f0a04SGreg Roach            }
387e88674d4SGreg Roach
388a25f0a04SGreg Roach            // Add the matched names first
389a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
390a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
391e364afe4SGreg Roach                    if ($husb_name['script'] === $wife_name['script']) {
392bdb3725aSGreg Roach                        $this->getAllNames[] = [
393a25f0a04SGreg Roach                            'type' => $husb_name['type'],
394a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
395a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
396a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
39713abd6f3SGreg Roach                        ];
398a25f0a04SGreg Roach                    }
399a25f0a04SGreg Roach                }
400a25f0a04SGreg Roach            }
401e88674d4SGreg Roach
402a25f0a04SGreg Roach            // Add the unmatched names second (there may be no matched names)
403a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
404a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
405e364afe4SGreg Roach                    if ($husb_name['script'] !== $wife_name['script']) {
406bdb3725aSGreg Roach                        $this->getAllNames[] = [
407a25f0a04SGreg Roach                            'type' => $husb_name['type'],
408a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
409a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
410a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
41113abd6f3SGreg Roach                        ];
412a25f0a04SGreg Roach                    }
413a25f0a04SGreg Roach                }
414a25f0a04SGreg Roach            }
415a25f0a04SGreg Roach        }
416a25f0a04SGreg Roach
417bdb3725aSGreg Roach        return $this->getAllNames;
418a25f0a04SGreg Roach    }
419a25f0a04SGreg Roach
42076692c8bSGreg Roach    /**
42176692c8bSGreg Roach     * This function should be redefined in derived classes to show any major
42276692c8bSGreg Roach     * identifying characteristics of this record.
42376692c8bSGreg Roach     *
42476692c8bSGreg Roach     * @return string
42576692c8bSGreg Roach     */
4268f53f488SRico Sonntag    public function formatListDetails(): string
427c1010edaSGreg Roach    {
428a25f0a04SGreg Roach        return
4298d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 1) .
4308d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 1);
431a25f0a04SGreg Roach    }
4328091bfd1SGreg Roach
4338091bfd1SGreg Roach    /**
4348091bfd1SGreg Roach     * Lock the database row, to prevent concurrent edits.
4358091bfd1SGreg Roach     */
4368091bfd1SGreg Roach    public function lock(): void
4378091bfd1SGreg Roach    {
4388091bfd1SGreg Roach        DB::table('families')
4398091bfd1SGreg Roach            ->where('f_file', '=', $this->tree->id())
4408091bfd1SGreg Roach            ->where('f_id', '=', $this->xref())
4418091bfd1SGreg Roach            ->lockForUpdate()
4428091bfd1SGreg Roach            ->get();
4438091bfd1SGreg Roach    }
444a25f0a04SGreg Roach}
445