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