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