Passed
Push — master ( 4d2b9c...c2ed51 )
by Greg
06:41
created

FunctionsPrint::printAddNewFact()   B

Complexity

Conditions 8
Paths 13

Size

Total Lines 59
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 46
c 0
b 0
f 0
nc 13
nop 3
dl 0
loc 59
rs 7.9337

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2021 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Functions;
21
22
use Fisharebest\Webtrees\Age;
23
use Fisharebest\Webtrees\Date;
24
use Fisharebest\Webtrees\Fact;
25
use Fisharebest\Webtrees\Family;
26
use Fisharebest\Webtrees\Filter;
27
use Fisharebest\Webtrees\Gedcom;
28
use Fisharebest\Webtrees\GedcomCode\GedcomCodeStat;
29
use Fisharebest\Webtrees\GedcomCode\GedcomCodeTemp;
30
use Fisharebest\Webtrees\GedcomRecord;
31
use Fisharebest\Webtrees\GedcomTag;
32
use Fisharebest\Webtrees\Header;
33
use Fisharebest\Webtrees\I18N;
34
use Fisharebest\Webtrees\Individual;
35
use Fisharebest\Webtrees\Media;
36
use Fisharebest\Webtrees\Note;
37
use Fisharebest\Webtrees\Place;
38
use Fisharebest\Webtrees\Registry;
39
use Fisharebest\Webtrees\Repository;
40
use Fisharebest\Webtrees\Source;
41
use Fisharebest\Webtrees\Submission;
42
use Fisharebest\Webtrees\Submitter;
43
use Fisharebest\Webtrees\Tree;
44
use Illuminate\Support\Collection;
45
use Illuminate\Support\Str;
46
use LogicException;
47
use Ramsey\Uuid\Uuid;
48
49
use function array_filter;
50
use function array_intersect;
51
use function array_merge;
52
use function array_search;
53
use function e;
54
use function explode;
55
use function in_array;
56
use function preg_match;
57
use function preg_match_all;
58
use function preg_replace_callback;
59
use function preg_split;
60
use function str_contains;
61
use function strip_tags;
62
use function strlen;
63
use function strpos;
64
use function strtoupper;
65
use function substr;
66
use function trim;
67
use function uasort;
68
use function view;
69
70
use const PREG_SET_ORDER;
71
use const PREG_SPLIT_NO_EMPTY;
72
73
/**
74
 * Class FunctionsPrint - common functions
75
 *
76
 * @deprecated since 2.0.6.  Will be removed in 2.1.0
77
 */
78
class FunctionsPrint
79
{
80
    /**
81
     * print a note record
82
     *
83
     * @param Tree   $tree
84
     * @param string $text
85
     * @param int    $nlevel the level of the note record
86
     * @param string $nrec   the note record to print
87
     *
88
     * @return string
89
     */
90
    private static function printNoteRecord(Tree $tree, $text, $nlevel, $nrec): string
91
    {
92
        $text .= Functions::getCont($nlevel, $nrec);
93
94
        if (preg_match('/^0 @(' . Gedcom::REGEX_XREF . ')@ NOTE/', $nrec, $match)) {
95
            // Shared note.
96
            $note = Registry::noteFactory()->make($match[1], $tree);
97
            // It must exist.
98
            assert($note instanceof Note);
99
100
            $label      = I18N::translate('Shared note');
101
            $html       = Filter::formatText($note->getNote(), $tree);
102
            $first_line = '<a href="' . e($note->url()) . '">' . $note->fullName() . '</a>';
103
        } else {
104
            // Inline note.
105
            $label = I18N::translate('Note');
106
            $html  = Filter::formatText($text, $tree);
107
108
            // Only one line?  Remove block-level attributes and skip expand/collapse.
109
            if (!str_contains($text, "\n")) {
110
                return
111
                    '<div class="fact_NOTE">' .
112
                    I18N::translate(
113
                        '<span class="label">%1$s:</span> <span class="field" dir="auto">%2$s</span>',
114
                        $label,
115
                        strip_tags($html, '<a><strong><em>')
116
                    ) .
117
                    '</div>';
118
            }
119
120
            [$text] = explode("\n", strip_tags($text));
121
            $first_line = Str::limit($text, 50, I18N::translate('…'));
122
        }
123
124
        $id       = 'collapse-' . Uuid::uuid4()->toString();
125
        $expanded = (bool) $tree->getPreference('EXPAND_NOTES');
126
127
        return
128
            '<div class="fact_NOTE">' .
129
            '<a href="#' . e($id) . '" role="button" data-toggle="collapse" aria-controls="' . e($id) . '" aria-expanded="' . ($expanded ? 'true' : 'false') . '">' .
130
            view('icons/expand') .
131
            view('icons/collapse') .
132
            '</a> ' .
133
            '<span class="label">' . $label . ':</span> ' .
134
            $first_line .
135
            '</div>' .
136
            '<div id="' . e($id) . '" class="collapse ' . ($expanded ? 'show' : '') . '">' .
137
            $html .
138
            '</div>';
139
    }
140
141
    /**
142
     * Print all of the notes in this fact record
143
     *
144
     * @param Tree   $tree
145
     * @param string $factrec The fact to print the notes from
146
     * @param int    $level   The level of the notes
147
     *
148
     * @return string HTML
149
     */
150
    public static function printFactNotes(Tree $tree, $factrec, $level): string
151
    {
152
        $data          = '';
153
        $previous_spos = 0;
154
        $nlevel        = $level + 1;
155
        $ct            = preg_match_all("/$level NOTE (.*)/", $factrec, $match, PREG_SET_ORDER);
156
        for ($j = 0; $j < $ct; $j++) {
157
            $spos1 = strpos($factrec, $match[$j][0], $previous_spos);
158
            $spos2 = strpos($factrec . "\n$level", "\n$level", $spos1 + 1);
159
            if (!$spos2) {
160
                $spos2 = strlen($factrec);
161
            }
162
            $previous_spos = $spos2;
163
            $nrec          = substr($factrec, $spos1, $spos2 - $spos1);
164
            if (!isset($match[$j][1])) {
165
                $match[$j][1] = '';
166
            }
167
            if (!preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $match[$j][1], $nmatch)) {
168
                $data .= self::printNoteRecord($tree, $match[$j][1], $nlevel, $nrec);
169
            } else {
170
                $note = Registry::noteFactory()->make($nmatch[1], $tree);
171
                if ($note) {
172
                    if ($note->canShow()) {
173
                        $noterec = $note->gedcom();
174
                        $nt      = preg_match("/0 @$nmatch[1]@ NOTE (.*)/", $noterec, $n1match);
175
                        $data    .= self::printNoteRecord($tree, $nt > 0 ? $n1match[1] : '', 1, $noterec);
176
                    }
177
                } else {
178
                    $data = '<div class="fact_NOTE"><span class="label">' . I18N::translate('Note') . '</span>: <span class="field error">' . $nmatch[1] . '</span></div>';
179
                }
180
            }
181
        }
182
183
        return $data;
184
    }
185
186
    /**
187
     * Format age of parents in HTML
188
     *
189
     * @param Individual $person child
190
     * @param Date       $birth_date
191
     *
192
     * @return string HTML
193
     */
194
    public static function formatParentsAges(Individual $person, Date $birth_date): string
195
    {
196
        $html     = '';
197
        $families = $person->childFamilies();
198
        // Multiple sets of parents (e.g. adoption) cause complications, so ignore.
199
        if ($birth_date->isOK() && $families->count() === 1) {
200
            $family = $families->first();
201
            foreach ($family->spouses() as $parent) {
202
                if ($parent->getBirthDate()->isOK()) {
203
                    $sex      = '<small>' . view('icons/sex', ['sex' => $parent->sex()]) . '</small>';
204
                    $age      = new Age($parent->getBirthDate(), $birth_date);
205
                    $deatdate = $parent->getDeathDate();
206
                    switch ($parent->sex()) {
207
                        case 'F':
208
                            // Highlight mothers who die in childbirth or shortly afterwards
209
                            if ($deatdate->isOK() && $deatdate->maximumJulianDay() < $birth_date->minimumJulianDay() + 90) {
210
                                $html .= ' <span title="' . I18N::translate('Death of a mother') . '" class="parentdeath">' . $sex . I18N::number($age->ageYears()) . '</span>';
211
                            } else {
212
                                $html .= ' <span title="' . I18N::translate('Mother’s age') . '">' . $sex . I18N::number($age->ageYears()) . '</span>';
213
                            }
214
                            break;
215
                        case 'M':
216
                            // Highlight fathers who die before the birth
217
                            if ($deatdate->isOK() && $deatdate->maximumJulianDay() < $birth_date->minimumJulianDay()) {
218
                                $html .= ' <span title="' . I18N::translate('Death of a father') . '" class="parentdeath">' . $sex . I18N::number($age->ageYears()) . '</span>';
219
                            } else {
220
                                $html .= ' <span title="' . I18N::translate('Father’s age') . '">' . $sex . I18N::number($age->ageYears()) . '</span>';
221
                            }
222
                            break;
223
                        default:
224
                            $html .= ' <span title="' . I18N::translate('Parent’s age') . '">' . $sex . I18N::number($age->ageYears()) . '</span>';
225
                            break;
226
                    }
227
                }
228
            }
229
            if ($html) {
230
                $html = '<span class="age">' . $html . '</span>';
231
            }
232
        }
233
234
        return $html;
235
    }
236
237
    /**
238
     * Convert a GEDCOM age string to localized text.
239
     *
240
     * @param string $age_string
241
     *
242
     * @return string
243
     */
244
    public static function formatGedcomAge(string $age_string): string
245
    {
246
        switch (strtoupper($age_string)) {
247
            case 'CHILD':
248
                return I18N::translate('Child');
249
            case 'INFANT':
250
                return I18N::translate('Infant');
251
            case 'STILLBORN':
252
                return I18N::translate('Stillborn');
253
            default:
254
                return (string) preg_replace_callback(
255
                    [
256
                        '/(\d+)([ymwd])/',
257
                    ],
258
                    static function (array $match): string {
259
                        $num = (int) $match[1];
260
261
                        switch ($match[2]) {
262
                            case 'y':
263
                                return I18N::plural('%s year', '%s years', $num, I18N::number($num));
264
                            case 'm':
265
                                return I18N::plural('%s month', '%s months', $num, I18N::number($num));
266
                            case 'w':
267
                                return I18N::plural('%s week', '%s weeks', $num, I18N::number($num));
268
                            case 'd':
269
                                return I18N::plural('%s day', '%s days', $num, I18N::number($num));
270
                            default:
271
                                throw new LogicException('Should never get here');
272
                        }
273
                    },
274
                    $age_string
275
                ) ;
276
        }
277
    }
278
279
    /**
280
     * Print fact DATE/TIME
281
     *
282
     * @param Fact         $event  event containing the date/age
283
     * @param GedcomRecord $record the person (or couple) whose ages should be printed
284
     * @param bool         $anchor option to print a link to calendar
285
     * @param bool         $time   option to print TIME value
286
     *
287
     * @return string
288
     */
289
    public static function formatFactDate(Fact $event, GedcomRecord $record, bool $anchor, bool $time): string
290
    {
291
        $factrec = $event->gedcom();
292
        $html    = '';
293
        // Recorded age
294
        if (preg_match('/\n2 AGE (.+)/', $factrec, $match)) {
295
            $fact_age = self::formatGedcomAge($match[1]);
296
        } else {
297
            $fact_age = '';
298
        }
299
        if (preg_match('/\n2 HUSB\n3 AGE (.+)/', $factrec, $match)) {
300
            $husb_age = self::formatGedcomAge($match[1]);
301
        } else {
302
            $husb_age = '';
303
        }
304
        if (preg_match('/\n2 WIFE\n3 AGE (.+)/', $factrec, $match)) {
305
            $wife_age = self::formatGedcomAge($match[1]);
306
        } else {
307
            $wife_age = '';
308
        }
309
310
        // Calculated age
311
        $fact = $event->getTag();
0 ignored issues
show
Deprecated Code introduced by
The function Fisharebest\Webtrees\Fact::getTag() has been deprecated: since 2.0.5. Will be removed in 2.1.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

311
        $fact = /** @scrutinizer ignore-deprecated */ $event->getTag();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
312
        if (preg_match('/\n2 DATE (.+)/', $factrec, $match)) {
313
            $date = new Date($match[1]);
314
            $html .= ' ' . $date->display($anchor);
315
            // time
316
            if ($time && preg_match('/\n3 TIME (.+)/', $factrec, $match)) {
317
                $html .= ' – <span class="date">' . $match[1] . '</span>';
318
            }
319
            if ($record instanceof Individual) {
320
                if (in_array($fact, Gedcom::BIRTH_EVENTS, true) && $record->tree()->getPreference('SHOW_PARENTS_AGE')) {
321
                    // age of parents at child birth
322
                    $html .= self::formatParentsAges($record, $date);
323
                }
324
                if ($fact !== 'BIRT' && $fact !== 'CHAN' && $fact !== '_TODO') {
325
                    // age at event
326
                    $birth_date = $record->getBirthDate();
327
                    // Can't use getDeathDate(), as this also gives BURI/CREM events, which
328
                    // wouldn't give the correct "days after death" result for people with
329
                    // no DEAT.
330
                    $death_event = $record->facts(['DEAT'])->first();
331
                    if ($death_event instanceof Fact) {
332
                        $death_date = $death_event->date();
333
                    } else {
334
                        $death_date = new Date('');
335
                    }
336
                    $ageText = '';
337
                    if ($fact === 'DEAT' || Date::compare($date, $death_date) <= 0 || !$record->isDead()) {
338
                        // Before death, print age
339
                        $age = (string) new Age($birth_date, $date);
340
341
                        // Only show calculated age if it differs from recorded age
342
                        if ($age !== '') {
343
                            if (
344
                                $fact_age !== '' && $fact_age !== $age ||
345
                                $fact_age === '' && $husb_age === '' && $wife_age === '' ||
346
                                $husb_age !== '' && $husb_age !== $age && $record->sex() === 'M' ||
347
                                $wife_age !== '' && $wife_age !== $age && $record->sex() === 'F'
348
                            ) {
349
                                switch ($record->sex()) {
350
                                    case 'M':
351
                                        /* I18N: The age of an individual at a given date */
352
                                        $ageText = I18N::translateContext('Male', '(aged %s)', $age);
353
                                        break;
354
                                    case 'F':
355
                                        /* I18N: The age of an individual at a given date */
356
                                        $ageText = I18N::translateContext('Female', '(aged %s)', $age);
357
                                        break;
358
                                    default:
359
                                        /* I18N: The age of an individual at a given date */
360
                                        $ageText = I18N::translate('(aged %s)', $age);
361
                                        break;
362
                                }
363
                            }
364
                        }
365
                    }
366
                    if ($fact !== 'DEAT' && $death_date->isOK() && Date::compare($death_date, $date) < 0) {
367
                        $death_day = $death_date->minimumDate()->day();
368
                        $event_day = $date->minimumDate()->day();
369
                        if ($death_day !== 0 && $event_day !== 0 && $death_day === $event_day) {
370
                            // On the exact date of death?
371
                            // NOTE: this path is never reached.  Keep the code (translation) in case
372
                            // we decide to re-introduce it.
373
                            $ageText = I18N::translate('(on the date of death)');
374
                        } else {
375
                            // After death
376
                            $age = (string) new Age($death_date, $date);
377
                            $ageText = I18N::translate('(%s after death)', $age);
378
                        }
379
                        // Family events which occur after death are probably errors
380
                        if ($event->record() instanceof Family) {
381
                            $ageText .= view('icons/warning');
382
                        }
383
                    }
384
                    if ($ageText !== '') {
385
                        $html .= ' <span class="age">' . $ageText . '</span>';
386
                    }
387
                }
388
            }
389
        }
390
        // print gedcom ages
391
        $age_labels = [
392
            I18N::translate('Age')     => $fact_age,
393
            I18N::translate('Husband') => $husb_age,
394
            I18N::translate('Wife')    => $wife_age,
395
        ];
396
397
        foreach (array_filter($age_labels) as $label => $age) {
398
            $html .= ' <span class="label">' . $label . ':</span> <span class="age">' . $age . '</span>';
399
        }
400
401
        return $html;
402
    }
403
404
    /**
405
     * print fact PLACe TEMPle STATus
406
     *
407
     * @param Fact $event       gedcom fact record
408
     * @param bool $anchor      to print a link to placelist
409
     * @param bool $sub_records to print place subrecords
410
     * @param bool $lds         to print LDS TEMPle and STATus
411
     *
412
     * @return string HTML
413
     */
414
    public static function formatFactPlace(Fact $event, $anchor = false, $sub_records = false, $lds = false): string
415
    {
416
        $tree = $event->record()->tree();
417
418
        if ($anchor) {
419
            // Show the full place name, for facts/events tab
420
            $html = $event->place()->fullName(true);
421
        } else {
422
            // Abbreviate the place name, for chart boxes
423
            return $event->place()->shortName();
424
        }
425
426
        if ($sub_records) {
427
            $placerec = Functions::getSubRecord(2, '2 PLAC', $event->gedcom());
428
            if ($placerec !== '') {
429
                if (preg_match_all('/\n3 (?:_HEB|ROMN) (.+)/', $placerec, $matches)) {
430
                    foreach ($matches[1] as $match) {
431
                        $wt_place = new Place($match, $tree);
432
                        $html     .= ' - ' . $wt_place->fullName();
433
                    }
434
                }
435
                $map_lati = '';
436
                $cts      = preg_match('/\d LATI (.*)/', $placerec, $match);
437
                if ($cts > 0) {
438
                    $map_lati = $match[1];
439
                    $html     .= '<br><span class="label">' . I18N::translate('Latitude') . ': </span>' . $map_lati;
440
                }
441
                $map_long = '';
442
                $cts      = preg_match('/\d LONG (.*)/', $placerec, $match);
443
                if ($cts > 0) {
444
                    $map_long = $match[1];
445
                    $html     .= ' <span class="label">' . I18N::translate('Longitude') . ': </span>' . $map_long;
446
                }
447
                if ($map_lati && $map_long) {
448
                    $map_lati = trim(strtr($map_lati, 'NSEW,�', ' - -. ')); // S5,6789 ==> -5.6789
449
                    $map_long = trim(strtr($map_long, 'NSEW,�', ' - -. ')); // E3.456� ==> 3.456
450
451
                    $html .= '<a href="https://maps.google.com/maps?q=' . e($map_lati) . ',' . e($map_long) . '" rel="nofollow" title="' . I18N::translate('Google Maps™') . '">' .
452
                        view('icons/google-maps') .
453
                        '<span class="sr-only">' . I18N::translate('Google Maps™') . '</span>' .
454
                        '</a>';
455
456
                    $html .= '<a href="https://www.bing.com/maps/?lvl=15&cp=' . e($map_lati) . '~' . e($map_long) . '" rel="nofollow" title="' . I18N::translate('Bing Maps™') . '">' .
457
                        view('icons/bing-maps') .
458
                        '<span class="sr-only">' . I18N::translate('Bing Maps™') . '</span>' .
459
                        '</a>';
460
461
                    $html .= '<a href="https://www.openstreetmap.org/#map=15/' . e($map_lati) . '/' . e($map_long) . '" rel="nofollow" title="' . I18N::translate('OpenStreetMap™') . '">' .
462
                        view('icons/openstreetmap') .
463
                        '<span class="sr-only">' . I18N::translate('OpenStreetMap™') . '</span>' .
464
                        '</a>';
465
                }
466
                if (preg_match('/\d NOTE (.*)/', $placerec, $match)) {
467
                    $html .= '<br>' . self::printFactNotes($tree, $placerec, 3);
468
                }
469
            }
470
        }
471
        if ($lds) {
472
            if (preg_match('/2 TEMP (.*)/', $event->gedcom(), $match)) {
473
                $html .= '<br>' . I18N::translate('LDS temple') . ': ' . GedcomCodeTemp::templeName($match[1]);
474
            }
475
            if (preg_match('/2 STAT (.*)/', $event->gedcom(), $match)) {
476
                $html .= '<br>' . I18N::translate('Status') . ': ' . GedcomCodeStat::statusName($match[1]);
477
                if (preg_match('/3 DATE (.*)/', $event->gedcom(), $match)) {
478
                    $date = new Date($match[1]);
479
                    $html .= ', ' . GedcomTag::getLabel('STAT:DATE') . ': ' . $date->display();
480
                }
481
            }
482
        }
483
484
        return $html;
485
    }
486
487
    /**
488
     * Check for facts that may exist only once for a certain record type.
489
     * If the fact already exists in the second array, delete it from the first one.
490
     *
491
     * @param array<string>    $uniquefacts
492
     * @param Collection<Fact> $recfacts
493
     *
494
     * @return array<string>
495
     */
496
    public static function checkFactUnique(array $uniquefacts, Collection $recfacts): array
497
    {
498
        foreach ($recfacts as $factarray) {
499
            $fact = $factarray->getTag();
500
501
            $key = array_search($fact, $uniquefacts, true);
502
            if ($key !== false) {
503
                unset($uniquefacts[$key]);
504
            }
505
        }
506
507
        return $uniquefacts;
508
    }
509
510
    /**
511
     * Print a new fact box on details pages
512
     *
513
     * @param GedcomRecord     $record    the person, family, source etc the fact will be added to
514
     * @param Collection<Fact> $usedfacts an array of facts already used in this record
515
     * @param string           $type      the type of record INDI, FAM, SOUR etc
516
     *
517
     * @return void
518
     */
519
    public static function printAddNewFact(GedcomRecord $record, Collection $usedfacts, $type): void
520
    {
521
        $tree = $record->tree();
522
523
        // -- Add from pick list
524
        switch ($type) {
525
            case Individual::RECORD_TYPE:
526
                $addfacts    = preg_split('/[, ;:]+/', $tree->getPreference('INDI_FACTS_ADD'), -1, PREG_SPLIT_NO_EMPTY);
527
                $uniquefacts = preg_split('/[, ;:]+/', $tree->getPreference('INDI_FACTS_UNIQUE'), -1, PREG_SPLIT_NO_EMPTY);
528
                $quickfacts  = preg_split('/[, ;:]+/', $tree->getPreference('INDI_FACTS_QUICK'), -1, PREG_SPLIT_NO_EMPTY);
529
                break;
530
531
            case Family::RECORD_TYPE:
532
                $addfacts    = preg_split('/[, ;:]+/', $tree->getPreference('FAM_FACTS_ADD'), -1, PREG_SPLIT_NO_EMPTY);
533
                $uniquefacts = preg_split('/[, ;:]+/', $tree->getPreference('FAM_FACTS_UNIQUE'), -1, PREG_SPLIT_NO_EMPTY);
534
                $quickfacts  = preg_split('/[, ;:]+/', $tree->getPreference('FAM_FACTS_QUICK'), -1, PREG_SPLIT_NO_EMPTY);
535
                break;
536
537
            case Source::RECORD_TYPE:
538
                $addfacts    = preg_split('/[, ;:]+/', $tree->getPreference('SOUR_FACTS_ADD'), -1, PREG_SPLIT_NO_EMPTY);
539
                $uniquefacts = preg_split('/[, ;:]+/', $tree->getPreference('SOUR_FACTS_UNIQUE'), -1, PREG_SPLIT_NO_EMPTY);
540
                $quickfacts  = preg_split('/[, ;:]+/', $tree->getPreference('SOUR_FACTS_QUICK'), -1, PREG_SPLIT_NO_EMPTY);
541
                break;
542
543
            case Note::RECORD_TYPE:
544
                $addfacts    = preg_split('/[, ;:]+/', $tree->getPreference('NOTE_FACTS_ADD'), -1, PREG_SPLIT_NO_EMPTY);
545
                $uniquefacts = preg_split('/[, ;:]+/', $tree->getPreference('NOTE_FACTS_UNIQUE'), -1, PREG_SPLIT_NO_EMPTY);
546
                $quickfacts  = preg_split('/[, ;:]+/', $tree->getPreference('NOTE_FACTS_QUICK'), -1, PREG_SPLIT_NO_EMPTY);
547
                break;
548
549
            case Repository::RECORD_TYPE:
550
                $addfacts    = preg_split('/[, ;:]+/', $tree->getPreference('REPO_FACTS_ADD'), -1, PREG_SPLIT_NO_EMPTY);
551
                $uniquefacts = preg_split('/[, ;:]+/', $tree->getPreference('REPO_FACTS_UNIQUE'), -1, PREG_SPLIT_NO_EMPTY);
552
                $quickfacts  = preg_split('/[, ;:]+/', $tree->getPreference('REPO_FACTS_QUICK'), -1, PREG_SPLIT_NO_EMPTY);
553
                break;
554
555
            case Media::RECORD_TYPE:
556
                $addfacts    = ['NOTE'];
557
                $uniquefacts = [];
558
                $quickfacts  = [];
559
                break;
560
            default:
561
                return;
562
        }
563
        $addfacts            = array_merge(self::checkFactUnique($uniquefacts, $usedfacts), $addfacts);
564
        $quickfacts          = array_intersect($quickfacts, $addfacts);
565
        $translated_addfacts = [];
566
        foreach ($addfacts as $addfact) {
567
            $translated_addfacts[$addfact] = GedcomTag::getLabel($record->tag() . ':' . $addfact);
568
        }
569
        uasort($translated_addfacts, static function (string $x, string $y): int {
570
            return I18N::strcasecmp(I18N::translate($x), I18N::translate($y));
571
        });
572
573
        echo view('edit/add-fact-row', [
574
            'add_facts'   => $translated_addfacts,
575
            'quick_facts' => $quickfacts,
576
            'record'      => $record,
577
            'tree'        => $tree,
578
        ]);
579
    }
580
}
581