xref: /webtrees/resources/views/chart-box.phtml (revision f4c767fd89cdb62ee54edec032285924cd767af7)
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->tag(), $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        <?php if ($individual->canShow()) : ?>
137            <a href="<?= e($individual->url()) ?>" class="wt-chart-box-name"><?= $individual->fullName() ?></a>
138        <?php else : ?>
139            <span class="wt-chart-box-name"><?= $individual->fullName() ?></span>
140        <?php endif ?>
141    </div>
142
143    <div class="wt-chart-box-name font-weight-bold">
144        <?= $individual->alternateName() ?>
145    </div>
146
147    <div class="wt-chart-box-lifespan">
148        <?= $individual->lifespan() ?>
149    </div>
150
151    <div class="wt-chart-box-facts">
152        <div class="wt-chart-box-fact small">
153            <?php
154            $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
155            // Show BIRT or equivalent event
156
157            foreach (Gedcom::BIRTH_EVENTS as $birttag) {
158                if (!in_array($birttag, $opt_tags, true)) {
159                    $event = $individual->facts([$birttag])->first();
160                    if ($event instanceof Fact) {
161                        echo $event->summary();
162                        break;
163                    }
164                }
165            }
166            // Show optional events (before death)
167            foreach ($opt_tags as $key => $tag) {
168                if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
169                    $event = $individual->facts([$tag])->first();
170                    if ($event instanceof Fact) {
171                        echo $event->summary();
172                        unset($opt_tags[$key]);
173                    }
174                }
175            }
176            // Show DEAT or equivalent event
177            foreach (Gedcom::DEATH_EVENTS as $deattag) {
178                $event = $individual->facts([$deattag])->first();
179                if ($event instanceof Fact) {
180                    echo $event->summary();
181                    if (in_array($deattag, $opt_tags, true)) {
182                        unset($opt_tags[array_search($deattag, $opt_tags, true)]);
183                    }
184                    break;
185                }
186            }
187            // Show remaining optional events (after death)
188            foreach ($opt_tags as $tag) {
189                $event = $individual->facts([$tag])->first();
190                if ($event instanceof Fact) {
191                    echo $event->summary();
192                }
193            }
194            ?>
195        </div>
196    </div>
197</div>
198