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