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