xref: /webtrees/resources/views/chart-box.phtml (revision 5e6816be28791f7fa2ef2bd1e23a17dee823d3b5)
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;
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
300b5fd0a6SGreg Roach$menus = $module_service->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user())->map(static function (ModuleChartInterface $module) use ($individual): ?Menu {
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 = [
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
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}
85d70512abSGreg Roach
860b5fd0a6SGreg Roach$all_facts = $all_facts->filter(static function (Fact $fact) use ($exclude): bool {
870b5fd0a6SGreg Roach    return !in_array($fact->getTag(), $exclude, true);
888af3e5c1SGreg Roach});
89242a7862SGreg Roach
90580a4d11SGreg Roach$all_facts = Fact::sortFacts($all_facts);
91242a7862SGreg Roach
92242a7862SGreg Roach$id = Uuid::uuid4()->toString();
93242a7862SGreg Roach?>
94d70512abSGreg Roach
9517dd427eSGreg 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()) ?>">
96242a7862SGreg Roach    <?php if ($individual->canShow() && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) : ?>
97242a7862SGreg Roach        <div class="wt-chart-box-thumbnail float-left mr-1">
98242a7862SGreg Roach            <?= $individual->displayImage(40, 50, 'crop', ['class' => 'wt-chart-box-thumbnail']) ?>
99242a7862SGreg Roach        </div>
100242a7862SGreg Roach    <?php endif ?>
101242a7862SGreg Roach
10293894b1dSGreg Roach    <?php if ($individual->canShow()) : ?>
103e759aebbSGreg Roach        <div class="wt-chart-box-extra d-print-none float-right ml-1">
104242a7862SGreg Roach            <div class="dropdown position-static wt-chart-box-zoom">
105242a7862SGreg Roach                <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
106242a7862SGreg Roach                    <div ><?= view('icons/zoom-in') ?></div>
107242a7862SGreg Roach                    <div class="d-none"><?= view('icons/zoom-out') ?></div>
108242a7862SGreg Roach                    <span class="sr-only"><?= I18N::translate('Links') ?></span>
109242a7862SGreg Roach                </a>
110242a7862SGreg Roach
111242a7862SGreg 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 ?>">
112242a7862SGreg Roach                    <?php foreach ($all_facts as $fact) : ?>
113242a7862SGreg Roach                        <?= $fact->summary() ?>
114242a7862SGreg Roach                    <?php endforeach ?>
115242a7862SGreg Roach                </div>
116242a7862SGreg Roach            </div>
117242a7862SGreg Roach
118242a7862SGreg Roach            <div class="dropdown position-static wt-chart-box-links">
119242a7862SGreg Roach                <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
120242a7862SGreg Roach                    <i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i>
121242a7862SGreg Roach                    <span class="sr-only"><?= I18N::translate('Links') ?></span>
122242a7862SGreg Roach                </a>
123242a7862SGreg Roach
124242a7862SGreg 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 ?>">
125242a7862SGreg Roach                    <?php foreach ($menus as $menu) : ?>
126b6c326d8SGreg Roach                        <a class="dropdown-item p-1 <?= e($menu->getClass()) ?>" href="<?= e($menu->getLink()) ?>">
127b6c326d8SGreg Roach                            <?= $menu->getLabel() ?>
128b6c326d8SGreg Roach                        </a>
129242a7862SGreg Roach                    <?php endforeach ?>
130242a7862SGreg Roach                </div>
131242a7862SGreg Roach            </div>
132242a7862SGreg Roach        </div>
13393894b1dSGreg Roach    <?php endif ?>
134242a7862SGreg Roach
135242a7862SGreg Roach    <div class="wt-chart-box-name font-weight-bold">
13639ca88baSGreg Roach        <a href="<?= e($individual->url()) ?>" class="wt-chart-box-name"><?= $individual->fullName() ?></a>
137242a7862SGreg Roach    </div>
138242a7862SGreg Roach
139242a7862SGreg Roach    <div class="wt-chart-box-name font-weight-bold">
14039ca88baSGreg Roach        <?= $individual->alternateName() ?>
141242a7862SGreg Roach    </div>
142242a7862SGreg Roach
143242a7862SGreg Roach    <div class="wt-chart-box-lifespan">
144*5e6816beSGreg Roach        <?= $individual->lifespan() ?>
145242a7862SGreg Roach    </div>
146242a7862SGreg Roach
147242a7862SGreg Roach    <div class="wt-chart-box-facts">
148242a7862SGreg Roach        <div class="wt-chart-box-fact small">
149242a7862SGreg Roach            <?php
150242a7862SGreg Roach            $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
151242a7862SGreg Roach            // Show BIRT or equivalent event
152242a7862SGreg Roach
153242a7862SGreg Roach            foreach (Gedcom::BIRTH_EVENTS as $birttag) {
15422d65e5aSGreg Roach                if (!in_array($birttag, $opt_tags, true)) {
155820b62dfSGreg Roach                    $event = $individual->facts([$birttag])->first();
156242a7862SGreg Roach                    if ($event instanceof Fact) {
157242a7862SGreg Roach                        echo $event->summary();
158242a7862SGreg Roach                        break;
159242a7862SGreg Roach                    }
160242a7862SGreg Roach                }
161242a7862SGreg Roach            }
162242a7862SGreg Roach            // Show optional events (before death)
163242a7862SGreg Roach            foreach ($opt_tags as $key => $tag) {
16422d65e5aSGreg Roach                if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
165820b62dfSGreg Roach                    $event = $individual->facts([$tag])->first();
166242a7862SGreg Roach                    if ($event instanceof Fact) {
167242a7862SGreg Roach                        echo $event->summary();
168242a7862SGreg Roach                        unset($opt_tags[$key]);
169242a7862SGreg Roach                    }
170242a7862SGreg Roach                }
171242a7862SGreg Roach            }
172242a7862SGreg Roach            // Show DEAT or equivalent event
173242a7862SGreg Roach            foreach (Gedcom::DEATH_EVENTS as $deattag) {
174820b62dfSGreg Roach                $event = $individual->facts([$deattag])->first();
175242a7862SGreg Roach                if ($event instanceof Fact) {
176242a7862SGreg Roach                    echo $event->summary();
17722d65e5aSGreg Roach                    if (in_array($deattag, $opt_tags, true)) {
17822d65e5aSGreg Roach                        unset($opt_tags[array_search($deattag, $opt_tags, true)]);
179242a7862SGreg Roach                    }
180242a7862SGreg Roach                    break;
181242a7862SGreg Roach                }
182242a7862SGreg Roach            }
183242a7862SGreg Roach            // Show remaining optional events (after death)
184242a7862SGreg Roach            foreach ($opt_tags as $tag) {
185820b62dfSGreg Roach                $event = $individual->facts([$tag])->first();
186242a7862SGreg Roach                if ($event instanceof Fact) {
187242a7862SGreg Roach                    echo $event->summary();
188242a7862SGreg Roach                }
189242a7862SGreg Roach            }
190242a7862SGreg Roach            ?>
191242a7862SGreg Roach        </div>
192242a7862SGreg Roach    </div>
193242a7862SGreg Roach</div>
194