xref: /webtrees/resources/views/chart-box.phtml (revision 93894b1df04478ea1760bf8b6243c2a65b8d745b)
1242a7862SGreg Roach<?php
2242a7862SGreg Roachdeclare(strict_types=1);
3242a7862SGreg Roach
4242a7862SGreg Roachuse Fisharebest\Webtrees\Auth;
5242a7862SGreg Roachuse Fisharebest\Webtrees\Fact;
6242a7862SGreg Roachuse Fisharebest\Webtrees\Gedcom;
7242a7862SGreg Roachuse Fisharebest\Webtrees\I18N;
8242a7862SGreg Roachuse Fisharebest\Webtrees\Individual;
9242a7862SGreg Roachuse Fisharebest\Webtrees\Menu;
10242a7862SGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface;
11242a7862SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
12242a7862SGreg Roachuse Illuminate\Support\Collection;
13242a7862SGreg Roachuse Ramsey\Uuid\Uuid;
14242a7862SGreg Roach
15242a7862SGreg Roach/**
16e759aebbSGreg Roach * @var Individual|null   $individual
17242a7862SGreg Roach * @var ModuleService     $module_service
18242a7862SGreg Roach * @var Collection|Menu[] $menus
19242a7862SGreg Roach */
20242a7862SGreg Roach
21e759aebbSGreg Roachif ($individual === null) {
22e759aebbSGreg Roach    echo '<div class="wt-chart-box"></div>';
23e759aebbSGreg Roach
24e759aebbSGreg Roach    return;
25e759aebbSGreg Roach}
26e759aebbSGreg Roach
27242a7862SGreg Roach$module_service = app(ModuleService::class);
28242a7862SGreg Roach
290b5fd0a6SGreg Roach$menus = $module_service->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user())->map(static function (ModuleChartInterface $module) use ($individual): ?Menu {
30242a7862SGreg Roach    return $module->chartBoxMenu($individual);
31242a7862SGreg Roach})->filter();
32242a7862SGreg Roach
3339ca88baSGreg Roachforeach ($individual->spouseFamilies() as $family) {
34b6c326d8SGreg Roach    $menus->push(new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url()));
3539ca88baSGreg Roach    $spouse  = $family->spouse($individual);
36242a7862SGreg Roach    if ($spouse && $spouse->canShow()) {
3739ca88baSGreg Roach        $menus->push(new Menu($spouse->fullName(), $spouse->url()));
38242a7862SGreg Roach    }
3939ca88baSGreg Roach    foreach ($family->children() as $child) {
40242a7862SGreg Roach        if ($child->canShow()) {
4139ca88baSGreg Roach            $menus->push(new Menu($child->fullName(), $child->url()));
42242a7862SGreg Roach        }
43242a7862SGreg Roach    }
44242a7862SGreg Roach}
45242a7862SGreg Roach
46242a7862SGreg Roach   // Do not show these facts in the expanded chart boxes.
47242a7862SGreg Roach    $exclude = [
48242a7862SGreg Roach        'ADDR',
49242a7862SGreg Roach        'ALIA',
50242a7862SGreg Roach        'ASSO',
51242a7862SGreg Roach        'CHAN',
52242a7862SGreg Roach        'CHIL',
53242a7862SGreg Roach        'EMAIL',
54242a7862SGreg Roach        'FAMC',
55242a7862SGreg Roach        'FAMS',
56242a7862SGreg Roach        'HUSB',
57242a7862SGreg Roach        'NAME',
58242a7862SGreg Roach        'NOTE',
59242a7862SGreg Roach        'OBJE',
60242a7862SGreg Roach        'PHON',
61242a7862SGreg Roach        'RESI',
62242a7862SGreg Roach        'RESN',
63242a7862SGreg Roach        'SEX',
64242a7862SGreg Roach        'SOUR',
65242a7862SGreg Roach        'SSN',
66242a7862SGreg Roach        'SUBM',
67242a7862SGreg Roach        'TITL',
68242a7862SGreg Roach        'URL',
69242a7862SGreg Roach        'WIFE',
70242a7862SGreg Roach        'WWW',
71242a7862SGreg Roach        '_EMAIL',
72242a7862SGreg Roach        '_TODO',
73242a7862SGreg Roach        '_UID',
74242a7862SGreg Roach        '_WT_OBJE_SORT',
75242a7862SGreg Roach    ];
76242a7862SGreg Roach
77242a7862SGreg Roach
7839ca88baSGreg Roach/** @var Collection|Fact[] $all_facts */
79242a7862SGreg Roach$all_facts = $individual->facts();
8039ca88baSGreg Roachforeach ($individual->spouseFamilies() as $family) {
81242a7862SGreg Roach    foreach ($family->facts() as $fact) {
8239ca88baSGreg Roach        $all_facts->push($fact);
83242a7862SGreg Roach    }
84242a7862SGreg Roach}
850b5fd0a6SGreg Roach$all_facts = $all_facts->filter(static function (Fact $fact) use ($exclude): bool {
860b5fd0a6SGreg Roach    return !in_array($fact->getTag(), $exclude, true);
878af3e5c1SGreg Roach});
88242a7862SGreg Roach
89580a4d11SGreg Roach$all_facts = Fact::sortFacts($all_facts);
90242a7862SGreg Roach
91242a7862SGreg Roach$id = Uuid::uuid4()->toString();
92242a7862SGreg Roach
93242a7862SGreg Roach/**
94242a7862SGreg Roach * @var Individual $individual
95242a7862SGreg Roach */
96242a7862SGreg Roach?>
9717dd427eSGreg Roach<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()) ?>">
98242a7862SGreg Roach    <?php if ($individual->canShow() && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) : ?>
99242a7862SGreg Roach        <div class="wt-chart-box-thumbnail float-left mr-1">
100242a7862SGreg Roach            <?= $individual->displayImage(40, 50, 'crop', ['class' => 'wt-chart-box-thumbnail']) ?>
101242a7862SGreg Roach        </div>
102242a7862SGreg Roach    <?php endif ?>
103242a7862SGreg Roach
104*93894b1dSGreg Roach    <?php if ($individual->canShow()): ?>
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): ?>
128b6c326d8SGreg Roach                        <a class="dropdown-item p-1 <?= e($menu->getClass()) ?>" href="<?= e($menu->getLink()) ?>">
129b6c326d8SGreg Roach                            <?= $menu->getLabel() ?>
130b6c326d8SGreg Roach                        </a>
131242a7862SGreg Roach                    <?php endforeach ?>
132242a7862SGreg Roach                </div>
133242a7862SGreg Roach            </div>
134242a7862SGreg Roach        </div>
135*93894b1dSGreg Roach    <?php endif ?>
136242a7862SGreg Roach
137242a7862SGreg Roach    <div class="wt-chart-box-name font-weight-bold">
13839ca88baSGreg Roach        <a href="<?= e($individual->url()) ?>" class="wt-chart-box-name"><?= $individual->fullName() ?></a>
139242a7862SGreg Roach    </div>
140242a7862SGreg Roach
141242a7862SGreg Roach    <div class="wt-chart-box-name font-weight-bold">
14239ca88baSGreg Roach        <?= $individual->alternateName() ?>
143242a7862SGreg Roach    </div>
144242a7862SGreg Roach
145242a7862SGreg Roach    <div class="wt-chart-box-lifespan">
146242a7862SGreg Roach        <?= $individual->getLifeSpan() ?>
147242a7862SGreg Roach    </div>
148242a7862SGreg Roach
149242a7862SGreg Roach    <div class="wt-chart-box-facts">
150242a7862SGreg Roach        <div class="wt-chart-box-fact small">
151242a7862SGreg Roach            <?php
152242a7862SGreg Roach            $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
153242a7862SGreg Roach            // Show BIRT or equivalent event
154242a7862SGreg Roach
155242a7862SGreg Roach            foreach (Gedcom::BIRTH_EVENTS as $birttag) {
15622d65e5aSGreg Roach                if (!in_array($birttag, $opt_tags, true)) {
157820b62dfSGreg Roach                    $event = $individual->facts([$birttag])->first();
158242a7862SGreg Roach                    if ($event instanceof Fact) {
159242a7862SGreg Roach                        echo $event->summary();
160242a7862SGreg Roach                        break;
161242a7862SGreg Roach                    }
162242a7862SGreg Roach                }
163242a7862SGreg Roach            }
164242a7862SGreg Roach            // Show optional events (before death)
165242a7862SGreg Roach            foreach ($opt_tags as $key => $tag) {
16622d65e5aSGreg Roach                if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
167820b62dfSGreg Roach                    $event = $individual->facts([$tag])->first();
168242a7862SGreg Roach                    if ($event instanceof Fact) {
169242a7862SGreg Roach                        echo $event->summary();
170242a7862SGreg Roach                        unset($opt_tags[$key]);
171242a7862SGreg Roach                    }
172242a7862SGreg Roach                }
173242a7862SGreg Roach            }
174242a7862SGreg Roach            // Show DEAT or equivalent event
175242a7862SGreg Roach            foreach (Gedcom::DEATH_EVENTS as $deattag) {
176820b62dfSGreg Roach                $event = $individual->facts([$deattag])->first();
177242a7862SGreg Roach                if ($event instanceof Fact) {
178242a7862SGreg Roach                    echo $event->summary();
17922d65e5aSGreg Roach                    if (in_array($deattag, $opt_tags, true)) {
18022d65e5aSGreg Roach                        unset($opt_tags[array_search($deattag, $opt_tags, true)]);
181242a7862SGreg Roach                    }
182242a7862SGreg Roach                    break;
183242a7862SGreg Roach                }
184242a7862SGreg Roach            }
185242a7862SGreg Roach            // Show remaining optional events (after death)
186242a7862SGreg Roach            foreach ($opt_tags as $tag) {
187820b62dfSGreg Roach                $event = $individual->facts([$tag])->first();
188242a7862SGreg Roach                if ($event instanceof Fact) {
189242a7862SGreg Roach                    echo $event->summary();
190242a7862SGreg Roach                }
191242a7862SGreg Roach            }
192242a7862SGreg Roach            ?>
193242a7862SGreg Roach        </div>
194242a7862SGreg Roach    </div>
195242a7862SGreg Roach</div>
196