1242a7862SGreg Roach<?php 2242a7862SGreg Roachdeclare(strict_types=1); 3242a7862SGreg Roach 4242a7862SGreg Roachuse Fisharebest\Webtrees\Auth; 5242a7862SGreg Roachuse Fisharebest\Webtrees\Fact; 6242a7862SGreg Roachuse Fisharebest\Webtrees\Functions\Functions; 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; 12242a7862SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 13242a7862SGreg Roachuse Illuminate\Support\Collection; 14242a7862SGreg Roachuse Ramsey\Uuid\Uuid; 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 28242a7862SGreg Roach$module_service = app(ModuleService::class); 29242a7862SGreg Roach 30*87cca37cSGreg Roach$menus = $module_service->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user())->map(function (ModuleChartInterface $module) use ($individual): ?Menu { 31242a7862SGreg Roach return $module->chartBoxMenu($individual); 32242a7862SGreg Roach})->filter(); 33242a7862SGreg Roach 3439ca88baSGreg Roachforeach ($individual->spouseFamilies() as $family) { 35242a7862SGreg Roach $menus[] = 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 = [ 49242a7862SGreg Roach 'ADDR', 50242a7862SGreg Roach 'ALIA', 51242a7862SGreg Roach 'ASSO', 52242a7862SGreg Roach 'CHAN', 53242a7862SGreg Roach 'CHIL', 54242a7862SGreg Roach 'EMAIL', 55242a7862SGreg Roach 'FAMC', 56242a7862SGreg Roach 'FAMS', 57242a7862SGreg Roach 'HUSB', 58242a7862SGreg Roach 'NAME', 59242a7862SGreg Roach 'NOTE', 60242a7862SGreg Roach 'OBJE', 61242a7862SGreg Roach 'PHON', 62242a7862SGreg Roach 'RESI', 63242a7862SGreg Roach 'RESN', 64242a7862SGreg Roach 'SEX', 65242a7862SGreg Roach 'SOUR', 66242a7862SGreg Roach 'SSN', 67242a7862SGreg Roach 'SUBM', 68242a7862SGreg Roach 'TITL', 69242a7862SGreg Roach 'URL', 70242a7862SGreg Roach 'WIFE', 71242a7862SGreg Roach 'WWW', 72242a7862SGreg Roach '_EMAIL', 73242a7862SGreg Roach '_TODO', 74242a7862SGreg Roach '_UID', 75242a7862SGreg Roach '_WT_OBJE_SORT', 76242a7862SGreg Roach ]; 77242a7862SGreg Roach 78242a7862SGreg Roach 7939ca88baSGreg Roach/** @var Collection|Fact[] $all_facts */ 80242a7862SGreg Roach$all_facts = $individual->facts(); 8139ca88baSGreg Roachforeach ($individual->spouseFamilies() as $family) { 82242a7862SGreg Roach foreach ($family->facts() as $fact) { 8339ca88baSGreg Roach $all_facts->push($fact); 84242a7862SGreg Roach } 85242a7862SGreg Roach} 8639ca88baSGreg Roach$all_facts = $all_facts->filter(function (Fact $fact) use ($exclude): bool { 87242a7862SGreg Roach return !in_array($fact->getTag(), $exclude); 88242a7862SGreg Roach}); 89242a7862SGreg Roach 90820b62dfSGreg RoachFunctions::sortFacts($all_facts); 91242a7862SGreg Roach 92242a7862SGreg Roach$id = Uuid::uuid4()->toString(); 93242a7862SGreg Roach 94242a7862SGreg Roach/** 95242a7862SGreg Roach * @var Individual $individual 96242a7862SGreg Roach */ 97242a7862SGreg Roach?> 9839ca88baSGreg Roach<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()) ?>"> 99242a7862SGreg Roach <?php if ($individual->canShow() && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) : ?> 100242a7862SGreg Roach <div class="wt-chart-box-thumbnail float-left mr-1"> 101242a7862SGreg Roach <?= $individual->displayImage(40, 50, 'crop', ['class' => 'wt-chart-box-thumbnail']) ?> 102242a7862SGreg Roach </div> 103242a7862SGreg Roach <?php endif ?> 104242a7862SGreg Roach 105e759aebbSGreg Roach <div class="wt-chart-box-extra d-print-none float-right ml-1"> 106242a7862SGreg Roach <div class="dropdown position-static wt-chart-box-zoom"> 107242a7862SGreg Roach <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 108242a7862SGreg Roach <div ><?= view('icons/zoom-in') ?></div> 109242a7862SGreg Roach <div class="d-none"><?= view('icons/zoom-out') ?></div> 110242a7862SGreg Roach <span class="sr-only"><?= I18N::translate('Links') ?></span> 111242a7862SGreg Roach </a> 112242a7862SGreg Roach 113242a7862SGreg Roach <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 ?>"> 114242a7862SGreg Roach <?php foreach ($all_facts as $fact): ?> 115242a7862SGreg Roach <?= $fact->summary() ?> 116242a7862SGreg Roach <?php endforeach ?> 117242a7862SGreg Roach </div> 118242a7862SGreg Roach </div> 119242a7862SGreg Roach 120242a7862SGreg Roach <div class="dropdown position-static wt-chart-box-links"> 121242a7862SGreg Roach <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 122242a7862SGreg Roach <i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i> 123242a7862SGreg Roach <span class="sr-only"><?= I18N::translate('Links') ?></span> 124242a7862SGreg Roach </a> 125242a7862SGreg Roach 126242a7862SGreg Roach <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 ?>"> 127242a7862SGreg Roach <?php foreach ($menus as $menu): ?> 128242a7862SGreg Roach <?= $menu->getMenuAsList() ?> 129242a7862SGreg Roach <?php endforeach ?> 130242a7862SGreg Roach </div> 131242a7862SGreg Roach </div> 132242a7862SGreg Roach </div> 133242a7862SGreg Roach 134242a7862SGreg Roach <div class="wt-chart-box-name font-weight-bold"> 13539ca88baSGreg Roach <a href="<?= e($individual->url()) ?>" class="wt-chart-box-name"><?= $individual->fullName() ?></a> 136242a7862SGreg Roach </div> 137242a7862SGreg Roach 138242a7862SGreg Roach <div class="wt-chart-box-name font-weight-bold"> 13939ca88baSGreg Roach <?= $individual->alternateName() ?> 140242a7862SGreg Roach </div> 141242a7862SGreg Roach 142242a7862SGreg Roach <div class="wt-chart-box-lifespan"> 143242a7862SGreg Roach <?= $individual->getLifeSpan() ?> 144242a7862SGreg Roach </div> 145242a7862SGreg Roach 146242a7862SGreg Roach <div class="wt-chart-box-facts"> 147242a7862SGreg Roach <div class="wt-chart-box-fact small"> 148242a7862SGreg Roach <?php 149242a7862SGreg Roach $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY); 150242a7862SGreg Roach // Show BIRT or equivalent event 151242a7862SGreg Roach 152242a7862SGreg Roach foreach (Gedcom::BIRTH_EVENTS as $birttag) { 153242a7862SGreg Roach if (!in_array($birttag, $opt_tags)) { 154820b62dfSGreg Roach $event = $individual->facts([$birttag])->first(); 155242a7862SGreg Roach if ($event instanceof Fact) { 156242a7862SGreg Roach echo $event->summary(); 157242a7862SGreg Roach break; 158242a7862SGreg Roach } 159242a7862SGreg Roach } 160242a7862SGreg Roach } 161242a7862SGreg Roach // Show optional events (before death) 162242a7862SGreg Roach foreach ($opt_tags as $key => $tag) { 163242a7862SGreg Roach if (!in_array($tag, Gedcom::DEATH_EVENTS)) { 164820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 165242a7862SGreg Roach if ($event instanceof Fact) { 166242a7862SGreg Roach echo $event->summary(); 167242a7862SGreg Roach unset($opt_tags[$key]); 168242a7862SGreg Roach } 169242a7862SGreg Roach } 170242a7862SGreg Roach } 171242a7862SGreg Roach // Show DEAT or equivalent event 172242a7862SGreg Roach foreach (Gedcom::DEATH_EVENTS as $deattag) { 173820b62dfSGreg Roach $event = $individual->facts([$deattag])->first(); 174242a7862SGreg Roach if ($event instanceof Fact) { 175242a7862SGreg Roach echo $event->summary(); 176242a7862SGreg Roach if (in_array($deattag, $opt_tags)) { 177242a7862SGreg Roach unset($opt_tags[array_search($deattag, $opt_tags)]); 178242a7862SGreg Roach } 179242a7862SGreg Roach break; 180242a7862SGreg Roach } 181242a7862SGreg Roach } 182242a7862SGreg Roach // Show remaining optional events (after death) 183242a7862SGreg Roach foreach ($opt_tags as $tag) { 184820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 185242a7862SGreg Roach if ($event instanceof Fact) { 186242a7862SGreg Roach echo $event->summary(); 187242a7862SGreg Roach } 188242a7862SGreg Roach } 189242a7862SGreg Roach ?> 190242a7862SGreg Roach </div> 191242a7862SGreg Roach </div> 192242a7862SGreg Roach</div> 193