Completed
Push — develop ( 778c00...2ca406 )
by Greg
24:21 queued 15:55
created

FunctionsPrint::printNoteRecord()   B

Complexity

Conditions 6
Paths 15

Size

Total Lines 53
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 36
c 1
b 0
f 0
nc 15
nop 4
dl 0
loc 53
rs 8.7217

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

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