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