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