xref: /webtrees/app/Family.php (revision c156e8f563be94a0ce9cac0af05ca20d19b86053)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach/**
3a25f0a04SGreg Roach * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
5a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
6a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
7a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8a25f0a04SGreg Roach * (at your option) any later version.
9a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
10a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12a25f0a04SGreg Roach * GNU General Public License for more details.
13a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
14a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15a25f0a04SGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
1876692c8bSGreg Roachnamespace Fisharebest\Webtrees;
19a25f0a04SGreg Roach
20886b77daSGreg Roachuse Closure;
212e5b4452SGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
22886b77daSGreg Roachuse stdClass;
232e5b4452SGreg Roach
24a25f0a04SGreg Roach/**
2576692c8bSGreg Roach * A GEDCOM family (FAM) object.
26a25f0a04SGreg Roach */
27c1010edaSGreg Roachclass Family extends GedcomRecord
28c1010edaSGreg Roach{
2916d6367aSGreg Roach    public const RECORD_TYPE = 'FAM';
3016d6367aSGreg Roach
3116d6367aSGreg Roach    protected const ROUTE_NAME = 'family';
32a25f0a04SGreg Roach
33a25f0a04SGreg Roach    /** @var Individual|null The husband (or first spouse for same-sex couples) */
34a25f0a04SGreg Roach    private $husb;
35a25f0a04SGreg Roach
36a25f0a04SGreg Roach    /** @var Individual|null The wife (or second spouse for same-sex couples) */
37a25f0a04SGreg Roach    private $wife;
38a25f0a04SGreg Roach
3976692c8bSGreg Roach    /**
4076692c8bSGreg Roach     * Create a GedcomRecord object from raw GEDCOM data.
4176692c8bSGreg Roach     *
4276692c8bSGreg Roach     * @param string      $xref
4376692c8bSGreg Roach     * @param string      $gedcom  an empty string for new/pending records
4476692c8bSGreg Roach     * @param string|null $pending null for a record with no pending edits,
4576692c8bSGreg Roach     *                             empty string for records with pending deletions
4676692c8bSGreg Roach     * @param Tree        $tree
4776692c8bSGreg Roach     */
4876f666f4SGreg Roach    public function __construct(string $xref, string $gedcom, $pending, Tree $tree)
49c1010edaSGreg Roach    {
5024ec66ceSGreg Roach        parent::__construct($xref, $gedcom, $pending, $tree);
51a25f0a04SGreg Roach
52395f0fe0SGreg Roach        // Fetch family members
53395f0fe0SGreg Roach        if (preg_match_all('/^1 (?:HUSB|WIFE|CHIL) @(.+)@/m', $gedcom . $pending, $match)) {
54395f0fe0SGreg Roach            Individual::load($tree, $match[1]);
55395f0fe0SGreg Roach        }
56395f0fe0SGreg Roach
57a25f0a04SGreg Roach        if (preg_match('/^1 HUSB @(.+)@/m', $gedcom . $pending, $match)) {
5824ec66ceSGreg Roach            $this->husb = Individual::getInstance($match[1], $tree);
59a25f0a04SGreg Roach        }
60a25f0a04SGreg Roach        if (preg_match('/^1 WIFE @(.+)@/m', $gedcom . $pending, $match)) {
6124ec66ceSGreg Roach            $this->wife = Individual::getInstance($match[1], $tree);
62a25f0a04SGreg Roach        }
63a25f0a04SGreg Roach    }
64a25f0a04SGreg Roach
6576692c8bSGreg Roach    /**
66886b77daSGreg Roach     * A closure which will create a record from a database row.
67886b77daSGreg Roach     *
68886b77daSGreg Roach     * @param Tree $tree
69886b77daSGreg Roach     *
70886b77daSGreg Roach     * @return Closure
71886b77daSGreg Roach     */
72886b77daSGreg Roach    public static function rowMapper(Tree $tree): Closure
73886b77daSGreg Roach    {
74886b77daSGreg Roach        return function (stdClass $row) use ($tree): Family {
75886b77daSGreg Roach            return Family::getInstance($row->f_id, $tree, $row->f_gedcom);
76886b77daSGreg Roach        };
77886b77daSGreg Roach    }
78886b77daSGreg Roach
79886b77daSGreg Roach    /**
80*c156e8f5SGreg Roach     * A closure which will compare families by marriage date.
81*c156e8f5SGreg Roach     *
82*c156e8f5SGreg Roach     * @return Closure
83*c156e8f5SGreg Roach     */
84*c156e8f5SGreg Roach    public static function marriageDateComparator(): Closure
85*c156e8f5SGreg Roach    {
86*c156e8f5SGreg Roach        return function (Family $x, Family $y): int
87*c156e8f5SGreg Roach        {
88*c156e8f5SGreg Roach            return Date::compare($x->getMarriageDate(), $y->getMarriageDate());
89*c156e8f5SGreg Roach        };
90*c156e8f5SGreg Roach    }
91*c156e8f5SGreg Roach
92*c156e8f5SGreg Roach    /**
93e71ef9d2SGreg Roach     * Get an instance of a family object. For single records,
94e71ef9d2SGreg Roach     * we just receive the XREF. For bulk records (such as lists
95e71ef9d2SGreg Roach     * and search results) we can receive the GEDCOM data as well.
96e71ef9d2SGreg Roach     *
97e71ef9d2SGreg Roach     * @param string      $xref
98e71ef9d2SGreg Roach     * @param Tree        $tree
99e71ef9d2SGreg Roach     * @param string|null $gedcom
100e71ef9d2SGreg Roach     *
101e71ef9d2SGreg Roach     * @throws \Exception
102e71ef9d2SGreg Roach     *
103e71ef9d2SGreg Roach     * @return Family|null
104e71ef9d2SGreg Roach     */
10576f666f4SGreg Roach    public static function getInstance(string $xref, Tree $tree, string $gedcom = null)
106c1010edaSGreg Roach    {
107e71ef9d2SGreg Roach        $record = parent::getInstance($xref, $tree, $gedcom);
108e71ef9d2SGreg Roach
109e71ef9d2SGreg Roach        if ($record instanceof Family) {
110e71ef9d2SGreg Roach            return $record;
111e71ef9d2SGreg Roach        }
112b2ce94c6SRico Sonntag
113b2ce94c6SRico Sonntag        return null;
114e71ef9d2SGreg Roach    }
115e71ef9d2SGreg Roach
116e71ef9d2SGreg Roach    /**
11776692c8bSGreg Roach     * Generate a private version of this record
11876692c8bSGreg Roach     *
11976692c8bSGreg Roach     * @param int $access_level
12076692c8bSGreg Roach     *
12176692c8bSGreg Roach     * @return string
12276692c8bSGreg Roach     */
1233c90ed31SGreg Roach    protected function createPrivateGedcomRecord(int $access_level): string
124c1010edaSGreg Roach    {
125d86cc606SGreg Roach        $SHOW_PRIVATE_RELATIONSHIPS = $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS');
126a25f0a04SGreg Roach
127a25f0a04SGreg Roach        $rec = '0 @' . $this->xref . '@ FAM';
128a25f0a04SGreg Roach        // Just show the 1 CHIL/HUSB/WIFE tag, not any subtags, which may contain private data
1298d0ebef0SGreg Roach        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches, PREG_SET_ORDER);
130a25f0a04SGreg Roach        foreach ($matches as $match) {
13124ec66ceSGreg Roach            $rela = Individual::getInstance($match[1], $this->tree);
132a25f0a04SGreg Roach            if ($rela && ($SHOW_PRIVATE_RELATIONSHIPS || $rela->canShow($access_level))) {
133a25f0a04SGreg Roach                $rec .= $match[0];
134a25f0a04SGreg Roach            }
135a25f0a04SGreg Roach        }
136a25f0a04SGreg Roach
137a25f0a04SGreg Roach        return $rec;
138a25f0a04SGreg Roach    }
139a25f0a04SGreg Roach
14076692c8bSGreg Roach    /**
14176692c8bSGreg Roach     * Fetch data from the database
14276692c8bSGreg Roach     *
14376692c8bSGreg Roach     * @param string $xref
14476692c8bSGreg Roach     * @param int    $tree_id
14576692c8bSGreg Roach     *
14676692c8bSGreg Roach     * @return null|string
14776692c8bSGreg Roach     */
14876f666f4SGreg Roach    protected static function fetchGedcomRecord(string $xref, int $tree_id)
149c1010edaSGreg Roach    {
1502e5b4452SGreg Roach        return DB::table('families')
1512e5b4452SGreg Roach            ->where('f_id', '=', $xref)
1522e5b4452SGreg Roach            ->where('f_file', '=', $tree_id)
1532e5b4452SGreg Roach            ->value('f_gedcom');
154a25f0a04SGreg Roach    }
155a25f0a04SGreg Roach
156a25f0a04SGreg Roach    /**
157a25f0a04SGreg Roach     * Get the male (or first female) partner of the family
158a25f0a04SGreg Roach     *
159e93111adSRico Sonntag     * @param int|null $access_level
160b3f49e6cSGreg Roach     *
161a25f0a04SGreg Roach     * @return Individual|null
162a25f0a04SGreg Roach     */
163c1010edaSGreg Roach    public function getHusband($access_level = null)
164c1010edaSGreg Roach    {
165b3f49e6cSGreg Roach        $SHOW_PRIVATE_RELATIONSHIPS = $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS');
166b3f49e6cSGreg Roach
167b3f49e6cSGreg Roach        if ($this->husb && ($SHOW_PRIVATE_RELATIONSHIPS || $this->husb->canShowName($access_level))) {
168a25f0a04SGreg Roach            return $this->husb;
169a25f0a04SGreg Roach        }
170b2ce94c6SRico Sonntag
171b2ce94c6SRico Sonntag        return null;
172a25f0a04SGreg Roach    }
173a25f0a04SGreg Roach
174a25f0a04SGreg Roach    /**
175a25f0a04SGreg Roach     * Get the female (or second male) partner of the family
176a25f0a04SGreg Roach     *
177e93111adSRico Sonntag     * @param int|null $access_level
178b3f49e6cSGreg Roach     *
179a25f0a04SGreg Roach     * @return Individual|null
180a25f0a04SGreg Roach     */
181c1010edaSGreg Roach    public function getWife($access_level = null)
182c1010edaSGreg Roach    {
183b3f49e6cSGreg Roach        $SHOW_PRIVATE_RELATIONSHIPS = $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS');
184b3f49e6cSGreg Roach
185b3f49e6cSGreg Roach        if ($this->wife && ($SHOW_PRIVATE_RELATIONSHIPS || $this->wife->canShowName($access_level))) {
186a25f0a04SGreg Roach            return $this->wife;
187a25f0a04SGreg Roach        }
188b2ce94c6SRico Sonntag
189b2ce94c6SRico Sonntag        return null;
190a25f0a04SGreg Roach    }
191a25f0a04SGreg Roach
19276692c8bSGreg Roach    /**
19376692c8bSGreg Roach     * Each object type may have its own special rules, and re-implement this function.
19476692c8bSGreg Roach     *
19576692c8bSGreg Roach     * @param int $access_level
19676692c8bSGreg Roach     *
19776692c8bSGreg Roach     * @return bool
19876692c8bSGreg Roach     */
19935584196SGreg Roach    protected function canShowByType(int $access_level): bool
200c1010edaSGreg Roach    {
201a25f0a04SGreg Roach        // Hide a family if any member is private
2028d0ebef0SGreg Roach        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches);
203a25f0a04SGreg Roach        foreach ($matches[1] as $match) {
20424ec66ceSGreg Roach            $person = Individual::getInstance($match, $this->tree);
205a25f0a04SGreg Roach            if ($person && !$person->canShow($access_level)) {
206a25f0a04SGreg Roach                return false;
207a25f0a04SGreg Roach            }
208a25f0a04SGreg Roach        }
209a25f0a04SGreg Roach
210a25f0a04SGreg Roach        return true;
211a25f0a04SGreg Roach    }
212a25f0a04SGreg Roach
21376692c8bSGreg Roach    /**
21476692c8bSGreg Roach     * Can the name of this record be shown?
21576692c8bSGreg Roach     *
21676692c8bSGreg Roach     * @param int|null $access_level
21776692c8bSGreg Roach     *
21876692c8bSGreg Roach     * @return bool
21976692c8bSGreg Roach     */
22035584196SGreg Roach    public function canShowName(int $access_level = null): bool
221c1010edaSGreg Roach    {
222a25f0a04SGreg Roach        // We can always see the name (Husband-name + Wife-name), however,
223a25f0a04SGreg Roach        // the name will often be "private + private"
224a25f0a04SGreg Roach        return true;
225a25f0a04SGreg Roach    }
226a25f0a04SGreg Roach
227a25f0a04SGreg Roach    /**
228a25f0a04SGreg Roach     * Find the spouse of a person.
229a25f0a04SGreg Roach     *
230a25f0a04SGreg Roach     * @param Individual $person
23113e3123bSGreg Roach     * @param int|null   $access_level
232a25f0a04SGreg Roach     *
233a25f0a04SGreg Roach     * @return Individual|null
234a25f0a04SGreg Roach     */
235c1010edaSGreg Roach    public function getSpouse(Individual $person, $access_level = null)
236c1010edaSGreg Roach    {
237a25f0a04SGreg Roach        if ($person === $this->wife) {
23813e3123bSGreg Roach            return $this->getHusband($access_level);
239a25f0a04SGreg Roach        }
240b2ce94c6SRico Sonntag
241b2ce94c6SRico Sonntag        return $this->getWife($access_level);
242a25f0a04SGreg Roach    }
243a25f0a04SGreg Roach
244a25f0a04SGreg Roach    /**
245a25f0a04SGreg Roach     * Get the (zero, one or two) spouses from this family.
246a25f0a04SGreg Roach     *
247cbc1590aSGreg Roach     * @param int|null $access_level
248a25f0a04SGreg Roach     *
249a25f0a04SGreg Roach     * @return Individual[]
250a25f0a04SGreg Roach     */
2518f53f488SRico Sonntag    public function getSpouses($access_level = null): array
252c1010edaSGreg Roach    {
25313abd6f3SGreg Roach        return array_filter([
254b3f49e6cSGreg Roach            $this->getHusband($access_level),
255b3f49e6cSGreg Roach            $this->getWife($access_level),
25613abd6f3SGreg Roach        ]);
257a25f0a04SGreg Roach    }
258a25f0a04SGreg Roach
259a25f0a04SGreg Roach    /**
260a25f0a04SGreg Roach     * Get a list of this family’s children.
261a25f0a04SGreg Roach     *
262cbc1590aSGreg Roach     * @param int|null $access_level
263a25f0a04SGreg Roach     *
264a25f0a04SGreg Roach     * @return Individual[]
265a25f0a04SGreg Roach     */
2668f53f488SRico Sonntag    public function getChildren($access_level = null): array
267c1010edaSGreg Roach    {
2684b9ff166SGreg Roach        if ($access_level === null) {
2694b9ff166SGreg Roach            $access_level = Auth::accessLevel($this->tree);
2704b9ff166SGreg Roach        }
2714b9ff166SGreg Roach
272845c3ce6SGreg Roach        $SHOW_PRIVATE_RELATIONSHIPS = (bool) $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS');
273a25f0a04SGreg Roach
27413abd6f3SGreg Roach        $children = [];
2758d0ebef0SGreg Roach        foreach ($this->facts(['CHIL'], false, $access_level, $SHOW_PRIVATE_RELATIONSHIPS) as $fact) {
276dc124885SGreg Roach            $child = $fact->target();
277e24444eeSGreg Roach            if ($child instanceof Individual && ($SHOW_PRIVATE_RELATIONSHIPS || $child->canShowName($access_level))) {
278a25f0a04SGreg Roach                $children[] = $child;
279a25f0a04SGreg Roach            }
280a25f0a04SGreg Roach        }
281a25f0a04SGreg Roach
282a25f0a04SGreg Roach        return $children;
283a25f0a04SGreg Roach    }
284a25f0a04SGreg Roach
285a25f0a04SGreg Roach    /**
286a25f0a04SGreg Roach     * Number of children - for the individual list
287a25f0a04SGreg Roach     *
288cbc1590aSGreg Roach     * @return int
289a25f0a04SGreg Roach     */
2908f53f488SRico Sonntag    public function getNumberOfChildren(): int
291c1010edaSGreg Roach    {
292a25f0a04SGreg Roach        $nchi = count($this->getChildren());
2938d0ebef0SGreg Roach        foreach ($this->facts(['NCHI']) as $fact) {
29484586c02SGreg Roach            $nchi = max($nchi, (int) $fact->value());
295a25f0a04SGreg Roach        }
296a25f0a04SGreg Roach
297a25f0a04SGreg Roach        return $nchi;
298a25f0a04SGreg Roach    }
299a25f0a04SGreg Roach
300a25f0a04SGreg Roach    /**
301a25f0a04SGreg Roach     * get the marriage event
302a25f0a04SGreg Roach     *
30366107289SGreg Roach     * @return Fact|null
304a25f0a04SGreg Roach     */
30566107289SGreg Roach    public function getMarriage()
306c1010edaSGreg Roach    {
307a25f0a04SGreg Roach        return $this->getFirstFact('MARR');
308a25f0a04SGreg Roach    }
309a25f0a04SGreg Roach
310a25f0a04SGreg Roach    /**
311a25f0a04SGreg Roach     * Get marriage date
312a25f0a04SGreg Roach     *
313a25f0a04SGreg Roach     * @return Date
314a25f0a04SGreg Roach     */
315c1010edaSGreg Roach    public function getMarriageDate()
316c1010edaSGreg Roach    {
317a25f0a04SGreg Roach        $marriage = $this->getMarriage();
318a25f0a04SGreg Roach        if ($marriage) {
3192decada7SGreg Roach            return $marriage->date();
320a25f0a04SGreg Roach        }
321b2ce94c6SRico Sonntag
322b2ce94c6SRico Sonntag        return new Date('');
323a25f0a04SGreg Roach    }
324a25f0a04SGreg Roach
325a25f0a04SGreg Roach    /**
326a25f0a04SGreg Roach     * Get the marriage year - displayed on lists of families
327a25f0a04SGreg Roach     *
328cbc1590aSGreg Roach     * @return int
329a25f0a04SGreg Roach     */
3308f53f488SRico Sonntag    public function getMarriageYear(): int
331c1010edaSGreg Roach    {
3324a83f5d7SGreg Roach        return $this->getMarriageDate()->minimumDate()->year;
333a25f0a04SGreg Roach    }
334a25f0a04SGreg Roach
335a25f0a04SGreg Roach    /**
336a25f0a04SGreg Roach     * Get the marriage place
337a25f0a04SGreg Roach     *
338a25f0a04SGreg Roach     * @return Place
339a25f0a04SGreg Roach     */
3408f53f488SRico Sonntag    public function getMarriagePlace(): Place
341c1010edaSGreg Roach    {
342a25f0a04SGreg Roach        $marriage = $this->getMarriage();
343a25f0a04SGreg Roach
3444fb14fcbSGreg Roach        return $marriage->place();
345a25f0a04SGreg Roach    }
346a25f0a04SGreg Roach
347a25f0a04SGreg Roach    /**
348a25f0a04SGreg Roach     * Get a list of all marriage dates - for the family lists.
349a25f0a04SGreg Roach     *
350a25f0a04SGreg Roach     * @return Date[]
351a25f0a04SGreg Roach     */
3528f53f488SRico Sonntag    public function getAllMarriageDates(): array
353c1010edaSGreg Roach    {
3548d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3558d0ebef0SGreg Roach            if ($array = $this->getAllEventDates([$event])) {
356a25f0a04SGreg Roach                return $array;
357a25f0a04SGreg Roach            }
358a25f0a04SGreg Roach        }
359a25f0a04SGreg Roach
36013abd6f3SGreg Roach        return [];
361a25f0a04SGreg Roach    }
362a25f0a04SGreg Roach
363a25f0a04SGreg Roach    /**
364a25f0a04SGreg Roach     * Get a list of all marriage places - for the family lists.
365a25f0a04SGreg Roach     *
3664080d558SGreg Roach     * @return Place[]
367a25f0a04SGreg Roach     */
3688f53f488SRico Sonntag    public function getAllMarriagePlaces(): array
369c1010edaSGreg Roach    {
3708d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3716e83554dSGreg Roach            $places = $this->getAllEventPlaces([$event]);
3724080d558SGreg Roach            if (!empty($places)) {
3734080d558SGreg Roach                return $places;
374a25f0a04SGreg Roach            }
375a25f0a04SGreg Roach        }
376a25f0a04SGreg Roach
37713abd6f3SGreg Roach        return [];
378a25f0a04SGreg Roach    }
379a25f0a04SGreg Roach
38076692c8bSGreg Roach    /**
38176692c8bSGreg Roach     * Derived classes should redefine this function, otherwise the object will have no name
38276692c8bSGreg Roach     *
38376692c8bSGreg Roach     * @return string[][]
38476692c8bSGreg Roach     */
3858f53f488SRico Sonntag    public function getAllNames(): array
386c1010edaSGreg Roach    {
3878f038c36SRico Sonntag        if ($this->getAllNames === null) {
388a25f0a04SGreg Roach            // Check the script used by each name, so we can match cyrillic with cyrillic, greek with greek, etc.
389e88674d4SGreg Roach            $husb_names = [];
390a25f0a04SGreg Roach            if ($this->husb) {
391492c7072SGreg Roach                $husb_names = array_filter($this->husb->getAllNames(), function (array $x): bool {
3928d68cabeSGreg Roach                    return $x['type'] !== '_MARNM';
3938d68cabeSGreg Roach                });
394e88674d4SGreg Roach            }
395e88674d4SGreg Roach            // If the individual only has married names, create a dummy birth name.
396e88674d4SGreg Roach            if (empty($husb_names)) {
397e88674d4SGreg Roach                $husb_names[] = [
398a25f0a04SGreg Roach                    'type' => 'BIRT',
399a25f0a04SGreg Roach                    'sort' => '@N.N.',
400ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
40113abd6f3SGreg Roach                ];
402a25f0a04SGreg Roach            }
403a25f0a04SGreg Roach            foreach ($husb_names as $n => $husb_name) {
404a25f0a04SGreg Roach                $husb_names[$n]['script'] = I18N::textScript($husb_name['full']);
405a25f0a04SGreg Roach            }
406e88674d4SGreg Roach
407e88674d4SGreg Roach            $wife_names = [];
408a25f0a04SGreg Roach            if ($this->wife) {
409492c7072SGreg Roach                $wife_names = array_filter($this->wife->getAllNames(), function (array $x): bool {
4108d68cabeSGreg Roach                    return $x['type'] !== '_MARNM';
4118d68cabeSGreg Roach                });
412e88674d4SGreg Roach            }
413e88674d4SGreg Roach            // If the individual only has married names, create a dummy birth name.
414e88674d4SGreg Roach            if (empty($wife_names)) {
415e88674d4SGreg Roach                $wife_names[] = [
416a25f0a04SGreg Roach                    'type' => 'BIRT',
417a25f0a04SGreg Roach                    'sort' => '@N.N.',
418ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
41913abd6f3SGreg Roach                ];
420a25f0a04SGreg Roach            }
421a25f0a04SGreg Roach            foreach ($wife_names as $n => $wife_name) {
422a25f0a04SGreg Roach                $wife_names[$n]['script'] = I18N::textScript($wife_name['full']);
423a25f0a04SGreg Roach            }
424e88674d4SGreg Roach
425a25f0a04SGreg Roach            // Add the matched names first
426a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
427a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
428e88674d4SGreg Roach                    if ($husb_name['script'] == $wife_name['script']) {
429bdb3725aSGreg Roach                        $this->getAllNames[] = [
430a25f0a04SGreg Roach                            'type' => $husb_name['type'],
431a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
432a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
433a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
43413abd6f3SGreg Roach                        ];
435a25f0a04SGreg Roach                    }
436a25f0a04SGreg Roach                }
437a25f0a04SGreg Roach            }
438e88674d4SGreg Roach
439a25f0a04SGreg Roach            // Add the unmatched names second (there may be no matched names)
440a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
441a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
442e88674d4SGreg Roach                    if ($husb_name['script'] != $wife_name['script']) {
443bdb3725aSGreg Roach                        $this->getAllNames[] = [
444a25f0a04SGreg Roach                            'type' => $husb_name['type'],
445a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
446a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
447a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
44813abd6f3SGreg Roach                        ];
449a25f0a04SGreg Roach                    }
450a25f0a04SGreg Roach                }
451a25f0a04SGreg Roach            }
452a25f0a04SGreg Roach        }
453a25f0a04SGreg Roach
454bdb3725aSGreg Roach        return $this->getAllNames;
455a25f0a04SGreg Roach    }
456a25f0a04SGreg Roach
45776692c8bSGreg Roach    /**
45876692c8bSGreg Roach     * This function should be redefined in derived classes to show any major
45976692c8bSGreg Roach     * identifying characteristics of this record.
46076692c8bSGreg Roach     *
46176692c8bSGreg Roach     * @return string
46276692c8bSGreg Roach     */
4638f53f488SRico Sonntag    public function formatListDetails(): string
464c1010edaSGreg Roach    {
465a25f0a04SGreg Roach        return
4668d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 1) .
4678d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 1);
468a25f0a04SGreg Roach    }
469a25f0a04SGreg Roach}
470