xref: /webtrees/resources/views/chart-box.phtml (revision 22d65e5ad7724941da33d875027b68b86648a321)
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
104e759aebbSGreg Roach    <div class="wt-chart-box-extra d-print-none float-right ml-1">
105242a7862SGreg Roach        <div class="dropdown position-static wt-chart-box-zoom">
106242a7862SGreg Roach            <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
107242a7862SGreg Roach                <div ><?= view('icons/zoom-in') ?></div>
108242a7862SGreg Roach                <div class="d-none"><?= view('icons/zoom-out') ?></div>
109242a7862SGreg Roach                <span class="sr-only"><?= I18N::translate('Links') ?></span>
110242a7862SGreg Roach            </a>
111242a7862SGreg Roach
112242a7862SGreg 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 ?>">
113242a7862SGreg Roach                <?php foreach ($all_facts as $fact): ?>
114242a7862SGreg Roach                    <?= $fact->summary() ?>
115242a7862SGreg Roach                <?php endforeach ?>
116242a7862SGreg Roach            </div>
117242a7862SGreg Roach        </div>
118242a7862SGreg Roach
119242a7862SGreg Roach        <div class="dropdown position-static wt-chart-box-links">
120242a7862SGreg Roach            <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
121242a7862SGreg Roach                <i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i>
122242a7862SGreg Roach                <span class="sr-only"><?= I18N::translate('Links') ?></span>
123242a7862SGreg Roach            </a>
124242a7862SGreg Roach
125242a7862SGreg 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 ?>">
126242a7862SGreg Roach                <?php foreach ($menus as $menu): ?>
127b6c326d8SGreg Roach                    <a class="dropdown-item p-1 <?= e($menu->getClass()) ?>" href="<?= e($menu->getLink()) ?>">
128b6c326d8SGreg Roach                        <?= $menu->getLabel() ?>
129b6c326d8SGreg Roach                    </a>
130242a7862SGreg Roach                <?php endforeach ?>
131242a7862SGreg Roach            </div>
132242a7862SGreg Roach        </div>
133242a7862SGreg Roach    </div>
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">
144242a7862SGreg Roach        <?= $individual->getLifeSpan() ?>
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) {
154*22d65e5aSGreg 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) {
164*22d65e5aSGreg 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();
177*22d65e5aSGreg Roach                    if (in_array($deattag, $opt_tags, true)) {
178*22d65e5aSGreg 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