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