xref: /webtrees/resources/views/chart-box.phtml (revision 00b1984e374faddab4698e73088f0c964e529b65)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Auth;
6use Fisharebest\Webtrees\Fact;
7use Fisharebest\Webtrees\Gedcom;
8use Fisharebest\Webtrees\I18N;
9use Fisharebest\Webtrees\Individual;
10use Fisharebest\Webtrees\Menu;
11use Fisharebest\Webtrees\Module\ModuleChartInterface;
12use Fisharebest\Webtrees\Services\ModuleService;
13use Illuminate\Support\Collection;
14use Ramsey\Uuid\Uuid;
15
16/**
17 * @var Individual|null   $individual
18 * @var ModuleService     $module_service
19 * @var Collection|Menu[] $menus
20 */
21
22if ($individual === null) {
23    echo '<div class="wt-chart-box"></div>';
24
25    return;
26}
27
28$module_service = app(ModuleService::class);
29
30$menus = $module_service->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user())->map(static function (ModuleChartInterface $module) use ($individual): ?Menu {
31    return $module->chartBoxMenu($individual);
32})->filter();
33
34foreach ($individual->spouseFamilies() as $family) {
35    $menus->push(new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url()));
36    $spouse  = $family->spouse($individual);
37    if ($spouse && $spouse->canShow()) {
38        $menus->push(new Menu($spouse->fullName(), $spouse->url()));
39    }
40    foreach ($family->children() as $child) {
41        if ($child->canShow()) {
42            $menus->push(new Menu($child->fullName(), $child->url()));
43        }
44    }
45}
46
47// Do not show these facts in the expanded chart boxes.
48$exclude = [
49    'ADDR',
50    'ALIA',
51    'ASSO',
52    'CHAN',
53    'CHIL',
54    'EMAIL',
55    'FAMC',
56    'FAMS',
57    'HUSB',
58    'NAME',
59    'NOTE',
60    'OBJE',
61    'PHON',
62    'RESI',
63    'RESN',
64    'SEX',
65    'SOUR',
66    'SSN',
67    'SUBM',
68    'TITL',
69    'URL',
70    'WIFE',
71    'WWW',
72    '_EMAIL',
73    '_TODO',
74    '_UID',
75    '_WT_OBJE_SORT',
76];
77
78/** @var Collection|Fact[] $all_facts */
79$all_facts = $individual->facts();
80foreach ($individual->spouseFamilies() as $family) {
81    foreach ($family->facts() as $fact) {
82        $all_facts->push($fact);
83    }
84}
85
86$all_facts = $all_facts->filter(static function (Fact $fact) use ($exclude): bool {
87    return !in_array($fact->getTag(), $exclude, true);
88});
89
90$all_facts = Fact::sortFacts($all_facts);
91
92$id = Uuid::uuid4()->toString();
93?>
94
95<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()) ?>">
96    <?php if ($individual->canShow() && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) : ?>
97        <div class="wt-chart-box-thumbnail float-left mr-1">
98            <?= $individual->displayImage(40, 50, 'crop', ['class' => 'wt-chart-box-thumbnail']) ?>
99        </div>
100    <?php endif ?>
101
102    <?php if ($individual->canShow()) : ?>
103        <div class="wt-chart-box-extra d-print-none float-right ml-1">
104            <div class="dropdown position-static wt-chart-box-zoom">
105                <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
106                    <div ><?= view('icons/zoom-in') ?></div>
107                    <div class="d-none"><?= view('icons/zoom-out') ?></div>
108                    <span class="sr-only"><?= I18N::translate('Links') ?></span>
109                </a>
110
111                <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 ?>">
112                    <?php foreach ($all_facts as $fact) : ?>
113                        <?= $fact->summary() ?>
114                    <?php endforeach ?>
115                </div>
116            </div>
117
118            <div class="dropdown position-static wt-chart-box-links">
119                <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
120                    <i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i>
121                    <span class="sr-only"><?= I18N::translate('Links') ?></span>
122                </a>
123
124                <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 ?>">
125                    <?php foreach ($menus as $menu) : ?>
126                        <a class="dropdown-item p-1 <?= e($menu->getClass()) ?>" href="<?= e($menu->getLink()) ?>">
127                            <?= $menu->getLabel() ?>
128                        </a>
129                    <?php endforeach ?>
130                </div>
131            </div>
132        </div>
133    <?php endif ?>
134
135    <div class="wt-chart-box-name font-weight-bold">
136        <a href="<?= e($individual->url()) ?>" class="wt-chart-box-name"><?= $individual->fullName() ?></a>
137    </div>
138
139    <div class="wt-chart-box-name font-weight-bold">
140        <?= $individual->alternateName() ?>
141    </div>
142
143    <div class="wt-chart-box-lifespan">
144        <?= $individual->lifespan() ?>
145    </div>
146
147    <div class="wt-chart-box-facts">
148        <div class="wt-chart-box-fact small">
149            <?php
150            $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
151            // Show BIRT or equivalent event
152
153            foreach (Gedcom::BIRTH_EVENTS as $birttag) {
154                if (!in_array($birttag, $opt_tags, true)) {
155                    $event = $individual->facts([$birttag])->first();
156                    if ($event instanceof Fact) {
157                        echo $event->summary();
158                        break;
159                    }
160                }
161            }
162            // Show optional events (before death)
163            foreach ($opt_tags as $key => $tag) {
164                if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
165                    $event = $individual->facts([$tag])->first();
166                    if ($event instanceof Fact) {
167                        echo $event->summary();
168                        unset($opt_tags[$key]);
169                    }
170                }
171            }
172            // Show DEAT or equivalent event
173            foreach (Gedcom::DEATH_EVENTS as $deattag) {
174                $event = $individual->facts([$deattag])->first();
175                if ($event instanceof Fact) {
176                    echo $event->summary();
177                    if (in_array($deattag, $opt_tags, true)) {
178                        unset($opt_tags[array_search($deattag, $opt_tags, true)]);
179                    }
180                    break;
181                }
182            }
183            // Show remaining optional events (after death)
184            foreach ($opt_tags as $tag) {
185                $event = $individual->facts([$tag])->first();
186                if ($event instanceof Fact) {
187                    echo $event->summary();
188                }
189            }
190            ?>
191        </div>
192    </div>
193</div>
194