xref: /webtrees/resources/views/modules/relatives/family.phtml (revision 504055284fcef1c6d50f172e3cb3fa077cc9c7a8)
1d70512abSGreg Roach<?php
2d70512abSGreg Roach
310e06497SGreg Roachdeclare(strict_types=1);
410e06497SGreg Roach
5d70512abSGreg Roachuse Fisharebest\Webtrees\Date;
67c2c99faSGreg Roachuse Fisharebest\Webtrees\Family;
77d70e4a7SGreg Roachuse Fisharebest\Webtrees\Gedcom;
87d70e4a7SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddChildToFamilyPage;
97c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
107c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AddSpouseToFamilyPage;
112917771cSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ReorderChildrenPage;
127d70e4a7SGreg Roachuse Fisharebest\Webtrees\I18N;
137d70e4a7SGreg Roachuse Fisharebest\Webtrees\Individual;
146fcafd02SGreg Roachuse Fisharebest\Webtrees\Services\RelationshipService;
157d70e4a7SGreg Roach
167c2c99faSGreg Roach/**
177c2c99faSGreg Roach * @var Family     $family
187c2c99faSGreg Roach * @var int        $fam_access_level
197c2c99faSGreg Roach * @var Individual $individual
207c2c99faSGreg Roach * @var string     $label
217c2c99faSGreg Roach * @var string     $type
227c2c99faSGreg Roach */
237c2c99faSGreg Roach
247d70e4a7SGreg Roach?>
25dd6b2bfcSGreg Roach
26dd6b2bfcSGreg Roach<table class="table table-sm wt-facts-table">
27dd6b2bfcSGreg Roach    <caption>
28dd6b2bfcSGreg Roach        <i class="icon-cfamily"></i>
29dd6b2bfcSGreg Roach        <a href="<?= e($family->url()) ?>"><?= $label ?></a>
30dd6b2bfcSGreg Roach    </caption>
31dd6b2bfcSGreg Roach
32dd6b2bfcSGreg Roach    <tbody>
33dd6b2bfcSGreg Roach        <?php
34dd6b2bfcSGreg Roach        $found = false;
358d0ebef0SGreg Roach        foreach ($family->facts(['HUSB'], false, $fam_access_level) as $fact) {
36dd6b2bfcSGreg Roach            $found |= !$fact->isPendingDeletion();
37dc124885SGreg Roach            $person = $fact->target();
38dd6b2bfcSGreg Roach            if ($person instanceof Individual) {
391baf69deSGreg Roach                $row_class = 'wt-sex-' . strtolower($person->sex());
40dd6b2bfcSGreg Roach                if ($fact->isPendingAddition()) {
4171a69701SGreg Roach                    $row_class .= ' wt-new';
42dd6b2bfcSGreg Roach                } elseif ($fact->isPendingDeletion()) {
4371a69701SGreg Roach                    $row_class .= ' wt-old';
44dd6b2bfcSGreg Roach                }
45dd6b2bfcSGreg Roach                ?>
46dd6b2bfcSGreg Roach                <tr class="<?= $row_class ?>">
47dd6b2bfcSGreg Roach                    <th scope="row">
48dd6b2bfcSGreg Roach                        <?= $individual === $person ? '<i class="icon-selected"></i>' : '' ?>
496fcafd02SGreg Roach                        <?= app(RelationshipService::class)->getCloseRelationshipName($individual, $person) ?>
50dd6b2bfcSGreg Roach                    </th>
51dd6b2bfcSGreg Roach                    <td class="border-0 p-0">
52516bb6deSGreg Roach                        <?= view('chart-box', ['individual' => $person]) ?>
53dd6b2bfcSGreg Roach                    </td>
54dd6b2bfcSGreg Roach                </tr>
55dd6b2bfcSGreg Roach                <?php
56dd6b2bfcSGreg Roach            }
57dd6b2bfcSGreg Roach        }
58dd6b2bfcSGreg Roach        if (!$found && $family->canEdit()) {
59dd6b2bfcSGreg Roach            ?>
60dd6b2bfcSGreg Roach            <tr>
61dd6b2bfcSGreg Roach                <th scope="row"></th>
62dd6b2bfcSGreg Roach                <td>
63efd4768bSGreg Roach                    <a href="<?= e(route(AddSpouseToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'M', 'url' => $individual->url() . '#tab-relatives'])) ?>">
6417dd427eSGreg Roach                        <?= I18N::translate('Add a husband') ?>
65dd6b2bfcSGreg Roach                    </a>
66dd6b2bfcSGreg Roach                </td>
67dd6b2bfcSGreg Roach            </tr>
68dd6b2bfcSGreg Roach            <?php
69dd6b2bfcSGreg Roach        }
70dd6b2bfcSGreg Roach
71dd6b2bfcSGreg Roach        $found = false;
728d0ebef0SGreg Roach        foreach ($family->facts(['WIFE'], false, $fam_access_level) as $fact) {
73dc124885SGreg Roach            $person = $fact->target();
74dd6b2bfcSGreg Roach            if ($person instanceof Individual) {
75dd6b2bfcSGreg Roach                $found |= !$fact->isPendingDeletion();
761baf69deSGreg Roach                $row_class = 'wt-sex-' . strtolower($person->sex());
77dd6b2bfcSGreg Roach                if ($fact->isPendingAddition()) {
7871a69701SGreg Roach                    $row_class .= ' wt-new';
79dd6b2bfcSGreg Roach                } elseif ($fact->isPendingDeletion()) {
8071a69701SGreg Roach                    $row_class .= ' wt-old';
81dd6b2bfcSGreg Roach                }
82dd6b2bfcSGreg Roach                ?>
83dd6b2bfcSGreg Roach
84dd6b2bfcSGreg Roach                <tr class="<?= $row_class ?>">
85dd6b2bfcSGreg Roach                    <th scope="row">
86dd6b2bfcSGreg Roach                        <?= $individual === $person ? '<i class="icon-selected"></i>' : '' ?>
876fcafd02SGreg Roach                        <?= app(RelationshipService::class)->getCloseRelationshipName($individual, $person) ?>
88dd6b2bfcSGreg Roach                    </th>
89dd6b2bfcSGreg Roach                    <td class="border-0 p-0">
90516bb6deSGreg Roach                        <?= view('chart-box', ['individual' => $person]) ?>
91dd6b2bfcSGreg Roach                    </td>
92dd6b2bfcSGreg Roach                </tr>
93dd6b2bfcSGreg Roach                <?php
94dd6b2bfcSGreg Roach            }
95dd6b2bfcSGreg Roach        }
96dd6b2bfcSGreg Roach        if (!$found && $family->canEdit()) { ?>
97dd6b2bfcSGreg Roach            <tr>
98dd6b2bfcSGreg Roach                <th scope="row"></th>
99dd6b2bfcSGreg Roach                <td>
100efd4768bSGreg Roach                    <a href="<?= e(route(AddSpouseToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'F', 'url' => $individual->url() . '#tab-relatives'])) ?>">
10117dd427eSGreg Roach                        <?= I18N::translate('Add a wife') ?>
102dd6b2bfcSGreg Roach                    </a>
103dd6b2bfcSGreg Roach                </td>
104dd6b2bfcSGreg Roach            </tr>
105dd6b2bfcSGreg Roach
106dd6b2bfcSGreg Roach        <?php } ?>
107dd6b2bfcSGreg Roach
108dd6b2bfcSGreg Roach        <?php
109dd6b2bfcSGreg Roach        ///// MARR /////
110dd6b2bfcSGreg Roach        $found = false;
111dd6b2bfcSGreg Roach        $prev  = new Date('');
1128d0ebef0SGreg Roach        foreach ($family->facts(array_merge(Gedcom::MARRIAGE_EVENTS, Gedcom::DIVORCE_EVENTS), true) as $fact) {
113dd6b2bfcSGreg Roach            $found |= !$fact->isPendingDeletion();
114dd6b2bfcSGreg Roach            if ($fact->isPendingAddition()) {
11517dd427eSGreg Roach                $row_class = 'wt-new';
116dd6b2bfcSGreg Roach            } elseif ($fact->isPendingDeletion()) {
11717dd427eSGreg Roach                $row_class = 'wt-old';
118dd6b2bfcSGreg Roach            } else {
119dd6b2bfcSGreg Roach                $row_class = '';
120dd6b2bfcSGreg Roach            }
121dd6b2bfcSGreg Roach            ?>
122dd6b2bfcSGreg Roach
123dd6b2bfcSGreg Roach            <tr class="<?= $row_class ?>">
124dd6b2bfcSGreg Roach                <th scope="row">
125315eb316SGreg Roach                    <span class="visually-hidden"><?= $fact->label() ?></span>
126dd6b2bfcSGreg Roach                </th>
1270ec49c9fSGreg Roach
128dd6b2bfcSGreg Roach                <td>
12970ac1a22SGreg Roach                    <span class="label"><?= $fact->label() ?></span>
13070ac1a22SGreg Roach13170ac1a22SGreg Roach                    <span class="field"><?= $fact->date()->display() ?><?= $fact->place()->fullName() ?></span>
132dd6b2bfcSGreg Roach                </td>
133dd6b2bfcSGreg Roach            </tr>
134dd6b2bfcSGreg Roach
135dd6b2bfcSGreg Roach            <?php
1362decada7SGreg Roach            if (!$prev->isOK() && $fact->date()->isOK()) {
1372decada7SGreg Roach                $prev = $fact->date();
138dd6b2bfcSGreg Roach            }
139dd6b2bfcSGreg Roach        }
140dd6b2bfcSGreg Roach
141dd6b2bfcSGreg Roach        if (!$found && $family->canShow() && $family->canEdit()) {
142dd6b2bfcSGreg Roach            ?>
143dd6b2bfcSGreg Roach            <tr>
144dd6b2bfcSGreg Roach                <th scope="row">
145315eb316SGreg Roach                    <span class="visually-hidden"><?= I18N::translate('Marriage') ?></span>
146dd6b2bfcSGreg Roach                </th>
1470ec49c9fSGreg Roach
148dd6b2bfcSGreg Roach                <td>
1492917771cSGreg Roach                    <a href="<?= e(route(AddNewFact::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'fact' => 'MARR'])) ?>">
150dd6b2bfcSGreg Roach                        <?= I18N::translate('Add marriage details') ?>
151dd6b2bfcSGreg Roach                    </a>
152dd6b2bfcSGreg Roach                </td>
153dd6b2bfcSGreg Roach            </tr>
154dd6b2bfcSGreg Roach            <?php
155dd6b2bfcSGreg Roach        }
156dd6b2bfcSGreg Roach
157dd6b2bfcSGreg Roach        ///// CHIL /////
158dd6b2bfcSGreg Roach        $child_number = 0;
1598d0ebef0SGreg Roach        foreach ($family->facts(['CHIL'], false, $fam_access_level) as $fact) {
160dc124885SGreg Roach            $person = $fact->target();
161dd6b2bfcSGreg Roach            if ($person instanceof Individual) {
1621baf69deSGreg Roach                $row_class = 'wt-sex-' . strtolower($person->sex());
163dd6b2bfcSGreg Roach                if ($fact->isPendingAddition()) {
164dd6b2bfcSGreg Roach                    $child_number++;
165dd6b2bfcSGreg Roach                    $row_class .= ' new';
166dd6b2bfcSGreg Roach                } elseif ($fact->isPendingDeletion()) {
167dd6b2bfcSGreg Roach                    $row_class .= ' old';
168dd6b2bfcSGreg Roach                } else {
169dd6b2bfcSGreg Roach                    $child_number++;
170dd6b2bfcSGreg Roach                }
171dd6b2bfcSGreg Roach                $next = new Date('');
1728d0ebef0SGreg Roach                foreach ($person->facts(Gedcom::BIRTH_EVENTS, true) as $bfact) {
1732decada7SGreg Roach                    if ($bfact->date()->isOK()) {
1742decada7SGreg Roach                        $next = $bfact->date();
175dd6b2bfcSGreg Roach                        break;
176dd6b2bfcSGreg Roach                    }
177dd6b2bfcSGreg Roach                }
178dd6b2bfcSGreg Roach                ?>
179dd6b2bfcSGreg Roach
180dd6b2bfcSGreg Roach                <tr class="<?= $row_class ?>">
181dd6b2bfcSGreg Roach                    <th scope="row">
182dd6b2bfcSGreg Roach                        <?php if ($individual === $person) : ?>
183dd6b2bfcSGreg Roach                            <i class="icon-selected"></i>
184dd6b2bfcSGreg Roach                        <?php endif ?>
185dd6b2bfcSGreg Roach
186dd6b2bfcSGreg Roach                        <?php if ($prev->isOK() && $next->isOK()) : ?>
18764490ee2SGreg Roach                            <div class="wt-date-difference collapse small">
188dd6b2bfcSGreg Roach                                <?php $days = $next->maximumJulianDay() - $prev->minimumJulianDay(); ?>
189dd6b2bfcSGreg Roach                                <?php if ($days < 0 || $child_number > 1 && $days > 1 && $days < 240) : ?>
190e39fd5c6SGreg Roach                                    <?= view('icons/warning') ?>
191dd6b2bfcSGreg Roach                                <?php endif ?>
192dd6b2bfcSGreg Roach
193dc270d8cSGreg Roach                                <?php $months = intdiv($days + 15, 30); ?>
194dd6b2bfcSGreg Roach                                <?php if (abs($months) === 12 || abs($months) >= 24) : ?>
1955442f141SGreg Roach                                    <?= I18N::plural('%s year', '%s years', intdiv($months, 12), I18N::number(round($months / 12))) ?>
196dd6b2bfcSGreg Roach                                <?php elseif ($months !== 0) : ?>
197dd6b2bfcSGreg Roach                                    <?= I18N::plural('%s month', '%s months', $months, I18N::number($months)) ?>
198dd6b2bfcSGreg Roach                                <?php endif ?>
199dd6b2bfcSGreg Roach                            </div>
200dd6b2bfcSGreg Roach                        <?php endif ?>
201dd6b2bfcSGreg Roach
2026fcafd02SGreg Roach                        <?= app(RelationshipService::class)->getCloseRelationshipName($individual, $person) ?>
203dd6b2bfcSGreg Roach                    </th>
204dd6b2bfcSGreg Roach                    <td class="border-0 p-0">
205516bb6deSGreg Roach                        <?= view('chart-box', ['individual' => $person]) ?>
206dd6b2bfcSGreg Roach                    </td>
207dd6b2bfcSGreg Roach                </tr>
208dd6b2bfcSGreg Roach                <?php
209dd6b2bfcSGreg Roach                $prev = $next;
210dd6b2bfcSGreg Roach            }
211dd6b2bfcSGreg Roach        } ?>
212dd6b2bfcSGreg Roach
213dd6b2bfcSGreg Roach        <?php if ($family->canEdit()) : ?>
214dd6b2bfcSGreg Roach            <tr>
215dd6b2bfcSGreg Roach                <th scope="row">
216315eb316SGreg Roach                    <span class="visually-hidden"><?= I18N::translate('Children') ?></span>
2170ec49c9fSGreg Roach                </th>
2180ec49c9fSGreg Roach
2190ec49c9fSGreg Roach                <td>
220efd4768bSGreg Roach                    <a href="<?= e(route(AddChildToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'M', 'url' => $individual->url() . '#tab-relatives'])) ?>">
2210ec49c9fSGreg Roach                        <?= $type === 'FAMS' ? I18N::translate('Add a son') : I18N::translate('Add a brother') ?>
2220ec49c9fSGreg Roach                    </a>
2230ec49c9fSGreg Roach                    |
224efd4768bSGreg Roach                    <a href="<?= e(route(AddChildToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'F', 'url' => $individual->url() . '#tab-relatives'])) ?>">
2250ec49c9fSGreg Roach                        <?= $type === 'FAMS' ? I18N::translate('Add a daughter') : I18N::translate('Add a sister') ?>
2260ec49c9fSGreg Roach                    </a>
2270ec49c9fSGreg Roach                    |
228efd4768bSGreg Roach                    <a href="<?= e(route(AddChildToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'U', 'url' => $individual->url() . '#tab-relatives'])) ?>">
2290ec49c9fSGreg Roach                        <?= $type === 'FAMS' ? I18N::translate('Add a child') : I18N::translate('Add a sibling') ?>
2300ec49c9fSGreg Roach                    </a>
2310ec49c9fSGreg Roach
232820b62dfSGreg Roach                    <?php if ($family->children()->count() > 1) : ?>
2330ec49c9fSGreg Roach                        <br>
234*50405528SGreg Roach                        <a href="<?= e(route(ReorderChildrenPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'url' => $individual->url() . '#tab-relatives'])) ?>">
235e837ff07SGreg Roach                            <?= I18N::translate('Re-order children') ?>
236dd6b2bfcSGreg Roach                        </a>
237dd6b2bfcSGreg Roach                    <?php endif; ?>
238dd6b2bfcSGreg Roach                </td>
239dd6b2bfcSGreg Roach            </tr>
240dd6b2bfcSGreg Roach        <?php endif ?>
241dd6b2bfcSGreg Roach    </tbody>
242dd6b2bfcSGreg Roach</table>
243