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