1242a7862SGreg Roach<?php 2d70512abSGreg Roach 3242a7862SGreg Roachdeclare(strict_types=1); 4242a7862SGreg Roach 5242a7862SGreg Roachuse Fisharebest\Webtrees\Auth; 6242a7862SGreg Roachuse Fisharebest\Webtrees\Fact; 7242a7862SGreg Roachuse Fisharebest\Webtrees\Gedcom; 8242a7862SGreg Roachuse Fisharebest\Webtrees\I18N; 9242a7862SGreg Roachuse Fisharebest\Webtrees\Individual; 10242a7862SGreg Roachuse Fisharebest\Webtrees\Menu; 11242a7862SGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 122e464181SGreg Roachuse Fisharebest\Webtrees\Registry; 13242a7862SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 14242a7862SGreg Roachuse Illuminate\Support\Collection; 15242a7862SGreg Roach 16242a7862SGreg Roach/** 17e759aebbSGreg Roach * @var Individual|null $individual 18242a7862SGreg Roach * @var ModuleService $module_service 19242a7862SGreg Roach * @var Collection|Menu[] $menus 20242a7862SGreg Roach */ 21242a7862SGreg Roach 22e759aebbSGreg Roachif ($individual === null) { 23e759aebbSGreg Roach echo '<div class="wt-chart-box"></div>'; 24e759aebbSGreg Roach 25e759aebbSGreg Roach return; 26e759aebbSGreg Roach} 27e759aebbSGreg Roach 28d35568b4SGreg Roach$module_service = Registry::container()->get(ModuleService::class); 29242a7862SGreg Roach 30*1ff45046SGreg Roach$menus = $module_service->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user())->map(static function (ModuleChartInterface $module) use ($individual): Menu|null { 31242a7862SGreg Roach return $module->chartBoxMenu($individual); 32242a7862SGreg Roach})->filter(); 33242a7862SGreg Roach 3439ca88baSGreg Roachforeach ($individual->spouseFamilies() as $family) { 35b6c326d8SGreg Roach $menus->push(new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url())); 3639ca88baSGreg Roach $spouse = $family->spouse($individual); 37242a7862SGreg Roach if ($spouse && $spouse->canShow()) { 3839ca88baSGreg Roach $menus->push(new Menu($spouse->fullName(), $spouse->url())); 39242a7862SGreg Roach } 4039ca88baSGreg Roach foreach ($family->children() as $child) { 41242a7862SGreg Roach if ($child->canShow()) { 4239ca88baSGreg Roach $menus->push(new Menu($child->fullName(), $child->url())); 43242a7862SGreg Roach } 44242a7862SGreg Roach } 45242a7862SGreg Roach} 46242a7862SGreg Roach 47242a7862SGreg Roach// Do not show these facts in the expanded chart boxes. 48242a7862SGreg Roach$exclude = [ 4993386620SGreg Roach 'FAM:CHAN', 5093386620SGreg Roach 'FAM:CHIL', 5193386620SGreg Roach 'FAM:HUSB', 5293386620SGreg Roach 'FAM:NOTE', 5393386620SGreg Roach 'FAM:OBJE', 5493386620SGreg Roach 'FAM:RESN', 5593386620SGreg Roach 'FAM:SOUR', 5693386620SGreg Roach 'FAM:WIFE', 5793386620SGreg Roach 'INDI:ADDR', 5893386620SGreg Roach 'INDI:ALIA', 5993386620SGreg Roach 'INDI:ASSO', 6093386620SGreg Roach 'INDI:CHAN', 6193386620SGreg Roach 'INDI:EMAIL', 6293386620SGreg Roach 'INDI:FAMC', 6393386620SGreg Roach 'INDI:FAMS', 6493386620SGreg Roach 'INDI:NAME', 6593386620SGreg Roach 'INDI:NOTE', 6693386620SGreg Roach 'INDI:OBJE', 6793386620SGreg Roach 'INDI:PHON', 6893386620SGreg Roach 'INDI:RESI', 6993386620SGreg Roach 'INDI:RESN', 7093386620SGreg Roach 'INDI:SEX', 7193386620SGreg Roach 'INDI:SOUR', 7293386620SGreg Roach 'INDI:SSN', 7393386620SGreg Roach 'INDI:SUBM', 7493386620SGreg Roach 'INDI:TITL', 7593386620SGreg Roach 'INDI:URL', 7693386620SGreg Roach 'INDI:WWW', 7793386620SGreg Roach 'INDI:_EMAIL', 7893386620SGreg Roach 'INDI:_TODO', 7993386620SGreg Roach 'INDI:_UID', 801bcc6ba6SGreg Roach 'INDI:_WT_OBJE_SORT' 81242a7862SGreg Roach]; 82242a7862SGreg Roach 8339ca88baSGreg Roach/** @var Collection|Fact[] $all_facts */ 84242a7862SGreg Roach$all_facts = $individual->facts(); 8539ca88baSGreg Roachforeach ($individual->spouseFamilies() as $family) { 86242a7862SGreg Roach foreach ($family->facts() as $fact) { 8739ca88baSGreg Roach $all_facts->push($fact); 88242a7862SGreg Roach } 89242a7862SGreg Roach} 90d70512abSGreg Roach 910b5fd0a6SGreg Roach$all_facts = $all_facts->filter(static function (Fact $fact) use ($exclude): bool { 9293386620SGreg Roach return !in_array($fact->tag(), $exclude, true); 938af3e5c1SGreg Roach}); 94242a7862SGreg Roach 95580a4d11SGreg Roach$all_facts = Fact::sortFacts($all_facts); 96242a7862SGreg Roach 972e464181SGreg Roach$id = Registry::idFactory()->id(); 98242a7862SGreg Roach?> 99d70512abSGreg Roach 100d4786c66SGreg Roach<div class="wt-chart-box wt-chart-box-<?= strtolower($individual->sex()) ?> <?= $individual->isPendingAddition() ? 'wt-new' : '' ?> <?= $individual->isPendingDeletion() ? 'wt-old' : '' ?> overflow-hidden" data-wt-chart-xref="<?= e($individual->xref()) ?>" data-tree="<?= e($individual->tree()->name()) ?>"> 101242a7862SGreg Roach <?php if ($individual->canShow() && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) : ?> 102315eb316SGreg Roach <div class="wt-chart-box-thumbnail float-start me-1"> 103242a7862SGreg Roach <?= $individual->displayImage(40, 50, 'crop', ['class' => 'wt-chart-box-thumbnail']) ?> 104242a7862SGreg Roach </div> 105242a7862SGreg Roach <?php endif ?> 106242a7862SGreg Roach 10793894b1dSGreg Roach <?php if ($individual->canShow()) : ?> 108315eb316SGreg Roach <div class="wt-chart-box-extra d-print-none float-end ms-1"> 109242a7862SGreg Roach <div class="dropdown position-static wt-chart-box-zoom"> 110315eb316SGreg Roach <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 111242a7862SGreg Roach <div ><?= view('icons/zoom-in') ?></div> 112242a7862SGreg Roach <div class="d-none"><?= view('icons/zoom-out') ?></div> 113315eb316SGreg Roach <span class="visually-hidden"><?= I18N::translate('Links') ?></span> 114242a7862SGreg Roach </a> 115242a7862SGreg Roach 116315eb316SGreg Roach <div class="dropdown-menu dropdown-menu-end wt-chart-box-dropdown wt-chart-box-zoom-dropdown" style="position: inherit" aria-labelledby="#chart-box-zoom-<?= $id ?>"> 117242a7862SGreg Roach <?php foreach ($all_facts as $fact) : ?> 118242a7862SGreg Roach <?= $fact->summary() ?> 119242a7862SGreg Roach <?php endforeach ?> 120242a7862SGreg Roach </div> 121242a7862SGreg Roach </div> 122242a7862SGreg Roach 123242a7862SGreg Roach <div class="dropdown position-static wt-chart-box-links"> 124315eb316SGreg Roach <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 125242a7862SGreg Roach <i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i> 126315eb316SGreg Roach <span class="visually-hidden"><?= I18N::translate('Links') ?></span> 127242a7862SGreg Roach </a> 128242a7862SGreg Roach 129315eb316SGreg Roach <div class="dropdown-menu dropdown-menu-end wt-chart-box-dropdown wt-chart-box-links-dropdown" style="position: inherit" aria-labelledby="#chart-box-menu-<?= $id ?>"> 130242a7862SGreg Roach <?php foreach ($menus as $menu) : ?> 131b6c326d8SGreg Roach <a class="dropdown-item p-1 <?= e($menu->getClass()) ?>" href="<?= e($menu->getLink()) ?>"> 132b6c326d8SGreg Roach <?= $menu->getLabel() ?> 133b6c326d8SGreg Roach </a> 134242a7862SGreg Roach <?php endforeach ?> 135242a7862SGreg Roach </div> 136242a7862SGreg Roach </div> 137242a7862SGreg Roach </div> 13893894b1dSGreg Roach <?php endif ?> 139242a7862SGreg Roach 1407f9d794bSGreg Roach <div class="wt-chart-box-name"> 141ebbd0d78SGreg Roach <?php if ($individual->canShow()) : ?> 1427f9d794bSGreg Roach <a href="<?= e($individual->url()) ?>"><?= $individual->fullName() ?></a> 143ebbd0d78SGreg Roach <?php else : ?> 1447f9d794bSGreg Roach <?= $individual->fullName() ?> 145ebbd0d78SGreg Roach <?php endif ?> 146242a7862SGreg Roach </div> 147242a7862SGreg Roach 1487f9d794bSGreg Roach <div class="wt-chart-box-name wt-chart-box-name-alt"> 14939ca88baSGreg Roach <?= $individual->alternateName() ?> 150242a7862SGreg Roach </div> 151242a7862SGreg Roach 152242a7862SGreg Roach <div class="wt-chart-box-lifespan"> 1535e6816beSGreg Roach <?= $individual->lifespan() ?> 154242a7862SGreg Roach </div> 155242a7862SGreg Roach 156242a7862SGreg Roach <div class="wt-chart-box-facts"> 157242a7862SGreg Roach <div class="wt-chart-box-fact small"> 158242a7862SGreg Roach <?php 159242a7862SGreg Roach $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY); 160242a7862SGreg Roach // Show BIRT or equivalent event 161242a7862SGreg Roach 162242a7862SGreg Roach foreach (Gedcom::BIRTH_EVENTS as $birttag) { 16322d65e5aSGreg Roach if (!in_array($birttag, $opt_tags, true)) { 164820b62dfSGreg Roach $event = $individual->facts([$birttag])->first(); 165242a7862SGreg Roach if ($event instanceof Fact) { 166242a7862SGreg Roach echo $event->summary(); 167242a7862SGreg Roach break; 168242a7862SGreg Roach } 169242a7862SGreg Roach } 170242a7862SGreg Roach } 171242a7862SGreg Roach // Show optional events (before death) 172242a7862SGreg Roach foreach ($opt_tags as $key => $tag) { 17322d65e5aSGreg Roach if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) { 174820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 175242a7862SGreg Roach if ($event instanceof Fact) { 176242a7862SGreg Roach echo $event->summary(); 177242a7862SGreg Roach unset($opt_tags[$key]); 178242a7862SGreg Roach } 179242a7862SGreg Roach } 180242a7862SGreg Roach } 181242a7862SGreg Roach // Show DEAT or equivalent event 182242a7862SGreg Roach foreach (Gedcom::DEATH_EVENTS as $deattag) { 183820b62dfSGreg Roach $event = $individual->facts([$deattag])->first(); 184242a7862SGreg Roach if ($event instanceof Fact) { 185242a7862SGreg Roach echo $event->summary(); 18622d65e5aSGreg Roach if (in_array($deattag, $opt_tags, true)) { 18722d65e5aSGreg Roach unset($opt_tags[array_search($deattag, $opt_tags, true)]); 188242a7862SGreg Roach } 189242a7862SGreg Roach break; 190242a7862SGreg Roach } 191242a7862SGreg Roach } 192242a7862SGreg Roach // Show remaining optional events (after death) 193242a7862SGreg Roach foreach ($opt_tags as $tag) { 194820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 195242a7862SGreg Roach if ($event instanceof Fact) { 196242a7862SGreg Roach echo $event->summary(); 197242a7862SGreg Roach } 198242a7862SGreg Roach } 199242a7862SGreg Roach ?> 200242a7862SGreg Roach </div> 201242a7862SGreg Roach </div> 202242a7862SGreg Roach</div> 203