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