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