1<?php 2declare(strict_types=1); 3 4use Fisharebest\Webtrees\Auth; 5use Fisharebest\Webtrees\Fact; 6use Fisharebest\Webtrees\Functions\Functions; 7use Fisharebest\Webtrees\Gedcom; 8use Fisharebest\Webtrees\I18N; 9use Fisharebest\Webtrees\Individual; 10use Fisharebest\Webtrees\Menu; 11use Fisharebest\Webtrees\Module\ModuleChartInterface; 12use Fisharebest\Webtrees\Services\ModuleService; 13use Illuminate\Support\Collection; 14use Ramsey\Uuid\Uuid; 15 16/** 17 * @var Individual|null $individual 18 * @var ModuleService $module_service 19 * @var Collection|Menu[] $menus 20 */ 21 22if ($individual === null) { 23 echo '<div class="wt-chart-box"></div>'; 24 25 return; 26} 27 28$module_service = app(ModuleService::class); 29 30$menus = $module_service->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user())->map(function (ModuleChartInterface $module) use ($individual): ?Menu { 31 return $module->chartBoxMenu($individual); 32})->filter(); 33 34foreach ($individual->spouseFamilies() as $family) { 35 $menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url()); 36 $spouse = $family->spouse($individual); 37 if ($spouse && $spouse->canShow()) { 38 $menus->push(new Menu($spouse->fullName(), $spouse->url())); 39 } 40 foreach ($family->children() as $child) { 41 if ($child->canShow()) { 42 $menus->push(new Menu($child->fullName(), $child->url())); 43 } 44 } 45} 46 47 // Do not show these facts in the expanded chart boxes. 48 $exclude = [ 49 'ADDR', 50 'ALIA', 51 'ASSO', 52 'CHAN', 53 'CHIL', 54 'EMAIL', 55 'FAMC', 56 'FAMS', 57 'HUSB', 58 'NAME', 59 'NOTE', 60 'OBJE', 61 'PHON', 62 'RESI', 63 'RESN', 64 'SEX', 65 'SOUR', 66 'SSN', 67 'SUBM', 68 'TITL', 69 'URL', 70 'WIFE', 71 'WWW', 72 '_EMAIL', 73 '_TODO', 74 '_UID', 75 '_WT_OBJE_SORT', 76 ]; 77 78 79/** @var Collection|Fact[] $all_facts */ 80$all_facts = $individual->facts(); 81foreach ($individual->spouseFamilies() as $family) { 82 foreach ($family->facts() as $fact) { 83 $all_facts->push($fact); 84 } 85} 86$all_facts = $all_facts->filter(function (Fact $fact) use ($exclude): bool { 87 return !in_array($fact->getTag(), $exclude); 88}); 89 90Functions::sortFacts($all_facts); 91 92$id = Uuid::uuid4()->toString(); 93 94/** 95 * @var Individual $individual 96 */ 97?> 98<div class="wt-chart-box wt-chart-box-<?= strtolower($individual->sex()) ?>" style="overflow: hidden;" data-xref="<?= e($individual->xref()) ?>" data-tree="<?= e($individual->tree()->name()) ?>"> 99 <?php if ($individual->canShow() && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) : ?> 100 <div class="wt-chart-box-thumbnail float-left mr-1"> 101 <?= $individual->displayImage(40, 50, 'crop', ['class' => 'wt-chart-box-thumbnail']) ?> 102 </div> 103 <?php endif ?> 104 105 <div class="wt-chart-box-extra d-print-none float-right ml-1"> 106 <div class="dropdown position-static wt-chart-box-zoom"> 107 <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 108 <div ><?= view('icons/zoom-in') ?></div> 109 <div class="d-none"><?= view('icons/zoom-out') ?></div> 110 <span class="sr-only"><?= I18N::translate('Links') ?></span> 111 </a> 112 113 <div class="dropdown-menu dropdown-menu-right wt-chart-box-dropdown wt-chart-box-zoom-dropdown" style="position: inherit" aria-labelledby="#chart-box-zoom-<?= $id ?>"> 114 <?php foreach ($all_facts as $fact): ?> 115 <?= $fact->summary() ?> 116 <?php endforeach ?> 117 </div> 118 </div> 119 120 <div class="dropdown position-static wt-chart-box-links"> 121 <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 122 <i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i> 123 <span class="sr-only"><?= I18N::translate('Links') ?></span> 124 </a> 125 126 <div class="dropdown-menu dropdown-menu-right wt-chart-box-dropdown wt-chart-box-links-dropdown" style="position: inherit" aria-labelledby="#chart-box-menu-<?= $id ?>"> 127 <?php foreach ($menus as $menu): ?> 128 <?= $menu->getMenuAsList() ?> 129 <?php endforeach ?> 130 </div> 131 </div> 132 </div> 133 134 <div class="wt-chart-box-name font-weight-bold"> 135 <a href="<?= e($individual->url()) ?>" class="wt-chart-box-name"><?= $individual->fullName() ?></a> 136 </div> 137 138 <div class="wt-chart-box-name font-weight-bold"> 139 <?= $individual->alternateName() ?> 140 </div> 141 142 <div class="wt-chart-box-lifespan"> 143 <?= $individual->getLifeSpan() ?> 144 </div> 145 146 <div class="wt-chart-box-facts"> 147 <div class="wt-chart-box-fact small"> 148 <?php 149 $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY); 150 // Show BIRT or equivalent event 151 152 foreach (Gedcom::BIRTH_EVENTS as $birttag) { 153 if (!in_array($birttag, $opt_tags)) { 154 $event = $individual->facts([$birttag])->first(); 155 if ($event instanceof Fact) { 156 echo $event->summary(); 157 break; 158 } 159 } 160 } 161 // Show optional events (before death) 162 foreach ($opt_tags as $key => $tag) { 163 if (!in_array($tag, Gedcom::DEATH_EVENTS)) { 164 $event = $individual->facts([$tag])->first(); 165 if ($event instanceof Fact) { 166 echo $event->summary(); 167 unset($opt_tags[$key]); 168 } 169 } 170 } 171 // Show DEAT or equivalent event 172 foreach (Gedcom::DEATH_EVENTS as $deattag) { 173 $event = $individual->facts([$deattag])->first(); 174 if ($event instanceof Fact) { 175 echo $event->summary(); 176 if (in_array($deattag, $opt_tags)) { 177 unset($opt_tags[array_search($deattag, $opt_tags)]); 178 } 179 break; 180 } 181 } 182 // Show remaining optional events (after death) 183 foreach ($opt_tags as $tag) { 184 $event = $individual->facts([$tag])->first(); 185 if ($event instanceof Fact) { 186 echo $event->summary(); 187 } 188 } 189 ?> 190 </div> 191 </div> 192</div> 193