xref: /webtrees/resources/views/fact-add-new.phtml (revision b11cdcd45131b1585d66693fab363cfeb18c51a4)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Auth;
6use Fisharebest\Webtrees\Family;
7use Fisharebest\Webtrees\GedcomRecord;
8use Fisharebest\Webtrees\I18N;
9use Fisharebest\Webtrees\Individual;
10use Fisharebest\Webtrees\Registry;
11use Fisharebest\Webtrees\Services\GedcomEditService;
12
13/**
14 * @var GedcomRecord $record
15 */
16
17?>
18
19<?php
20$add_facts = (new GedcomEditService())->factsToAdd($record, false);
21
22// Add from pick list
23switch ($record->tag()) {
24    case Individual::RECORD_TYPE:
25        $quick_facts  = array_filter(explode(',', $record->tree()->getPreference('INDI_FACTS_QUICK')));
26        $unique_facts = [
27            'ADOP',
28            'AFN',
29            'BAPL',
30            'BAPM',
31            'BARM',
32            'BASM',
33            'BIRT',
34            'BURI',
35            'CAST',
36            'CHAN',
37            'CHR',
38            'CHRA',
39            'CONF',
40            'CONL',
41            'CREM',
42            'DEAT',
43            'ENDL',
44            'FCOM',
45            'GRAD',
46            'NCHI',
47            'NMR',
48            'ORDN',
49            'PROB',
50            'REFN',
51            'RELI',
52            'RESN',
53            'RETI',
54            'RFN',
55            'RIN',
56            'SEX',
57            'SLGC',
58            'SSN',
59            'WILL',
60        ];
61        break;
62
63    case Family::RECORD_TYPE:
64        $quick_facts  = array_filter(explode(',', $record->tree()->getPreference('FAM_FACTS_QUICK')));
65        $unique_facts = [
66            'DIV',
67            'DIVF',
68            'ENGA',
69            'MARR',
70        ];
71        break;
72
73    default:
74        $quick_facts  = [];
75        $unique_facts = [];
76        break;
77}
78
79// Filter existing tags
80$filter_fn = static fn (string $tag): bool => !in_array($tag, $unique_facts, true) || $record->facts([$tag])->isEmpty();
81
82$quick_facts = array_filter($quick_facts, $filter_fn);
83
84
85// Create a label for a subtag
86$label_fn = static fn (string $subtag): string => Registry::elementFactory()->make($record->tag() . ':' . $subtag)->label();
87
88$quick_facts = array_combine($quick_facts, array_map($label_fn, $quick_facts));
89$add_facts   = array_combine($add_facts, array_map($label_fn, $add_facts));
90
91uasort($add_facts, I18N::comparator());
92
93if (!Auth::canUploadMedia($record->tree(), Auth::user())) {
94    unset($add_facts['OBJE'], $quick_facts['OBJE']);
95}
96
97echo view('edit/add-fact-row', [
98    'add_facts'   => $add_facts,
99    'quick_facts' => $quick_facts,
100    'record'      => $record,
101]);