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