xref: /webtrees/resources/views/modules/relatives/family.phtml (revision f9f6fffde9a4ddea74e52e0f4c13cde4ec13f3a4)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Date;
6use Fisharebest\Webtrees\Family;
7use Fisharebest\Webtrees\Gedcom;
8use Fisharebest\Webtrees\Http\RequestHandlers\AddChildToFamilyPage;
9use Fisharebest\Webtrees\Http\RequestHandlers\AddNewFact;
10use Fisharebest\Webtrees\Http\RequestHandlers\AddSpouseToFamilyPage;
11use Fisharebest\Webtrees\Http\RequestHandlers\ReorderChildrenPage;
12use Fisharebest\Webtrees\I18N;
13use Fisharebest\Webtrees\Individual;
14use Fisharebest\Webtrees\Services\RelationshipService;
15
16/**
17 * @var Family     $family
18 * @var int        $fam_access_level
19 * @var Individual $individual
20 * @var string     $label
21 * @var string     $type
22 */
23
24?>
25
26<table class="table table-sm wt-facts-table">
27    <caption>
28        <i class="icon-cfamily"></i>
29        <a href="<?= e($family->url()) ?>"><?= $label ?></a>
30    </caption>
31
32    <tbody>
33        <?php
34        $found = false;
35        foreach ($family->facts(['HUSB'], false, $fam_access_level) as $fact) {
36            $found |= !$fact->isPendingDeletion();
37            $person = $fact->target();
38            if ($person instanceof Individual) {
39                $row_class = 'wt-sex-' . strtolower($person->sex());
40                if ($fact->isPendingAddition()) {
41                    $row_class .= ' wt-new';
42                } elseif ($fact->isPendingDeletion()) {
43                    $row_class .= ' wt-old';
44                }
45                ?>
46                <tr class="<?= $row_class ?>">
47                    <th scope="row">
48                        <?= $individual === $person ? '<i class="icon-selected"></i>' : '' ?>
49                        <?= app(RelationshipService::class)->getCloseRelationshipName($individual, $person) ?>
50                    </th>
51                    <td class="border-0 p-0">
52                        <?= view('chart-box', ['individual' => $person]) ?>
53                    </td>
54                </tr>
55                <?php
56            }
57        }
58        if (!$found && $family->canEdit()) {
59            ?>
60            <tr>
61                <th scope="row"></th>
62                <td>
63                    <a href="<?= e(route(AddSpouseToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'M', 'url' => $individual->url() . '#tab-relatives'])) ?>">
64                        <?= I18N::translate('Add a husband') ?>
65                    </a>
66                </td>
67            </tr>
68            <?php
69        }
70
71        $found = false;
72        foreach ($family->facts(['WIFE'], false, $fam_access_level) as $fact) {
73            $person = $fact->target();
74            if ($person instanceof Individual) {
75                $found |= !$fact->isPendingDeletion();
76                $row_class = 'wt-sex-' . strtolower($person->sex());
77                if ($fact->isPendingAddition()) {
78                    $row_class .= ' wt-new';
79                } elseif ($fact->isPendingDeletion()) {
80                    $row_class .= ' wt-old';
81                }
82                ?>
83
84                <tr class="<?= $row_class ?>">
85                    <th scope="row">
86                        <?= $individual === $person ? '<i class="icon-selected"></i>' : '' ?>
87                        <?= app(RelationshipService::class)->getCloseRelationshipName($individual, $person) ?>
88                    </th>
89                    <td class="border-0 p-0">
90                        <?= view('chart-box', ['individual' => $person]) ?>
91                    </td>
92                </tr>
93                <?php
94            }
95        }
96        if (!$found && $family->canEdit()) { ?>
97            <tr>
98                <th scope="row"></th>
99                <td>
100                    <a href="<?= e(route(AddSpouseToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'F', 'url' => $individual->url() . '#tab-relatives'])) ?>">
101                        <?= I18N::translate('Add a wife') ?>
102                    </a>
103                </td>
104            </tr>
105
106        <?php } ?>
107
108        <?php
109        ///// MARR /////
110        $found = false;
111        $prev  = new Date('');
112        foreach ($family->facts(array_merge(Gedcom::MARRIAGE_EVENTS, Gedcom::DIVORCE_EVENTS), true) as $fact) {
113            $found |= !$fact->isPendingDeletion();
114            if ($fact->isPendingAddition()) {
115                $row_class = 'wt-new';
116            } elseif ($fact->isPendingDeletion()) {
117                $row_class = 'wt-old';
118            } else {
119                $row_class = '';
120            }
121            ?>
122
123            <tr class="<?= $row_class ?>">
124                <th scope="row">
125                    <span class="visually-hidden"><?= $fact->label() ?></span>
126                </th>
127
128                <td>
129                    <span class="label"><?= $fact->label() ?></span>
130131                    <span class="field"><?= $fact->date()->display() ?><?= $fact->place()->fullName() ?></span>
132                </td>
133            </tr>
134
135            <?php
136            if (!$prev->isOK() && $fact->date()->isOK()) {
137                $prev = $fact->date();
138            }
139        }
140
141        if (!$found && $family->canShow() && $family->canEdit()) {
142            ?>
143            <tr>
144                <th scope="row">
145                    <span class="visually-hidden"><?= I18N::translate('Marriage') ?></span>
146                </th>
147
148                <td>
149                    <a href="<?= e(route(AddNewFact::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'fact' => 'MARR'])) ?>">
150                        <?= I18N::translate('Add marriage details') ?>
151                    </a>
152                </td>
153            </tr>
154            <?php
155        }
156
157        ///// CHIL /////
158        $child_number = 0;
159        foreach ($family->facts(['CHIL'], false, $fam_access_level) as $fact) {
160            $person = $fact->target();
161            if ($person instanceof Individual) {
162                $row_class = 'wt-sex-' . strtolower($person->sex());
163                if ($fact->isPendingAddition()) {
164                    $child_number++;
165                    $row_class .= ' new';
166                } elseif ($fact->isPendingDeletion()) {
167                    $row_class .= ' old';
168                } else {
169                    $child_number++;
170                }
171                $next = new Date('');
172                foreach ($person->facts(Gedcom::BIRTH_EVENTS, true) as $bfact) {
173                    if ($bfact->date()->isOK()) {
174                        $next = $bfact->date();
175                        break;
176                    }
177                }
178                ?>
179
180                <tr class="<?= $row_class ?>">
181                    <th scope="row">
182                        <?php if ($individual === $person) : ?>
183                            <i class="icon-selected"></i>
184                        <?php endif ?>
185
186                        <?php if ($prev->isOK() && $next->isOK()) : ?>
187                            <div class="wt-date-difference collapse small">
188                                <?php $days = $next->maximumJulianDay() - $prev->minimumJulianDay(); ?>
189                                <?php if ($days < 0 || $child_number > 1 && $days > 1 && $days < 240) : ?>
190                                    <?= view('icons/warning') ?>
191                                <?php endif ?>
192
193                                <?php $months = intdiv($days + 15, 30); ?>
194                                <?php if (abs($months) === 12 || abs($months) >= 24) : ?>
195                                    <?= I18N::plural('%s year', '%s years', intdiv($months, 12), I18N::number(round($months / 12))) ?>
196                                <?php elseif ($months !== 0) : ?>
197                                    <?= I18N::plural('%s month', '%s months', $months, I18N::number($months)) ?>
198                                <?php endif ?>
199                            </div>
200                        <?php endif ?>
201
202                        <?= app(RelationshipService::class)->getCloseRelationshipName($individual, $person) ?>
203                    </th>
204                    <td class="border-0 p-0">
205                        <?= view('chart-box', ['individual' => $person]) ?>
206                    </td>
207                </tr>
208                <?php
209                $prev = $next;
210            }
211        } ?>
212
213        <?php if ($family->canEdit()) : ?>
214            <tr>
215                <th scope="row">
216                    <span class="visually-hidden"><?= I18N::translate('Children') ?></span>
217                </th>
218
219                <td>
220                    <a href="<?= e(route(AddChildToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'M', 'url' => $individual->url() . '#tab-relatives'])) ?>">
221                        <?= $type === 'FAMS' ? I18N::translate('Add a son') : I18N::translate('Add a brother') ?>
222                    </a>
223                    |
224                    <a href="<?= e(route(AddChildToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'F', 'url' => $individual->url() . '#tab-relatives'])) ?>">
225                        <?= $type === 'FAMS' ? I18N::translate('Add a daughter') : I18N::translate('Add a sister') ?>
226                    </a>
227                    |
228                    <a href="<?= e(route(AddChildToFamilyPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref(), 'sex' => 'U', 'url' => $individual->url() . '#tab-relatives'])) ?>">
229                        <?= $type === 'FAMS' ? I18N::translate('Add a child') : I18N::translate('Add a sibling') ?>
230                    </a>
231
232                    <?php if ($family->children()->count() > 1) : ?>
233                        <br>
234                        <a href="<?= e(route(ReorderChildrenPage::class, ['tree' => $family->tree()->name(), 'xref' => $family->xref()])) ?>">
235                            <?= I18N::translate('Re-order children') ?>
236                        </a>
237                    <?php endif; ?>
238                </td>
239            </tr>
240        <?php endif ?>
241    </tbody>
242</table>
243