summaryrefslogtreecommitdiff
path: root/resources/views/lists/families-table.phtml
blob: da78983866dbe06e0d3e7df3ed3f44450feca04d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Age;
use Fisharebest\Webtrees\Date;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\View;
use Illuminate\Support\Collection;

// lists require a unique ID in case there are multiple lists per page
$table_id          = Registry::idFactory()->id();
$today             = new Date(strtoupper(date('d M Y')));
$today_jd          = Registry::timestampFactory()->now()->julianDay();
$hundred_years_ago = Registry::timestampFactory()->now()->subtractYears(100)->julianDay();

/**
 * @var Tree                   $tree
 * @var Collection<int,Family> $families
 */

?>

<?php View::push('javascript') ?>
<script>
$("#<?= e($table_id) ?> > .wt-table-family").dataTable();

$("#<?= e($table_id) ?>")
    /* Hide/show parents */
    .on("click", "#btn-toggle-parents", function() {
        $(".wt-individual-list-parents").slideToggle();
    })
    /* Filter buttons in the table header */
    .on("click", "input[data-filter-column]", function() {
        let checkbox = $(this);

        // Deselect other options
        let siblings = checkbox.siblings("input[type='checkbox']");
        siblings.prop("checked", false).removeAttr("checked");

        // Apply (or clear) this filter
        let checked = checkbox.prop("checked");
        let filter  = checked ? checkbox.data("filter-value") : "";
        let column  = $("#<?= e($table_id) ?> .wt-table-family").DataTable().column(checkbox.data("filter-column"));
        column.search(filter).draw();
    });
</script>
<?php View::endpush() ?>

<div id="<?= e($table_id) ?>">
    <table class="table table-bordered table-sm wt-table-family"
        <?= view('lists/datatables-attributes') ?>
        data-columns='[{"type":"text"},{"type":"text"},{"type":"num"},{"type":"text"},{"type":"text"},{"type":"num"},{"type":"text"},{"type":"num"},{"type":"text"},{"type":"num"},{"visible":"<?= $tree->getPreference('SHOW_LAST_CHANGE')==='1' ? 'true' : 'false'?>"},{"sortable":false},{"sortable":false},{"sortable":false}]'
        data-sorting='[[1,"asc"]]'
    >
        <thead>
            <tr>
                <th colspan="14">
                    <div class="btn-toolbar d-flex justify-content-between mb-2">
                        <div class="btn-group btn-group-sm" role="group">
                            <input id="<?= e($table_id) ?>-bg-dead-N" class="btn-check" type="checkbox" data-filter-column="12" data-filter-value="N" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-dead-N" class="btn btn-outline-secondary btn-sm" title="' . I18N::translate('Show individuals who are alive or couples where both partners are alive.') ?>">
                                <?= I18N::translate('Both alive') ?>
                            </label>

                            <input id="<?= e($table_id) ?>-bg-dead-W" class="btn-check" type="checkbox" data-filter-column="12" data-filter-value="W" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-dead-W" class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples where only the female partner is dead.') ?>">
                                <?= I18N::translate('Widower') ?>
                            </label>

                            <input id="<?= e($table_id) ?>-bg-dead-H" class="btn-check" type="checkbox" data-filter-column="12" data-filter-value="H" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-dead-H" class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples where only the male partner is dead.') ?>">
                                <?= I18N::translate('Widow') ?>
                            </label>

                            <input id="<?= e($table_id) ?>-bg-dead-Y" class="btn-check" type="checkbox" data-filter-column="12" data-filter-value="Y" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-dead-Y" class="btn btn-outline-secondary" title="<?= I18N::translate('Show individuals who are dead or couples where both partners are dead.') ?>">
                                <?= I18N::translate('Both dead') ?>
                            </label>
                        </div>

                        <div class="btn-group btn-group-sm" role="group">
                            <input id="<?= e($table_id) ?>-bg-roots-R" class="btn-check" type="checkbox" data-filter-column="13" data-filter-value="R" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-roots-R" class="btn btn-outline-secondary" title="<?= I18N::translate('Show “roots” couples or individuals. These individuals may also be called “patriarchs”. They are individuals who have no parents recorded in the database.') ?>">
                                <?= I18N::translate('Roots') ?>
                            </label>

                            <input id="<?= e($table_id) ?>-bg-roots-L" class="btn-check" type="checkbox" data-filter-column="13" data-filter-value="L" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-roots-L" class="btn btn-outline-secondary" title="<?= I18N::translate('Show “leaves” couples or individuals. These are individuals who are alive but have no children recorded in the database.') ?>">
                                <?= I18N::translate('Leaves') ?>
                            </label>
                        </div>

                        <div class="btn-group btn-group-sm" role="group">
                            <input id="<?= e($table_id) ?>-bg-marr-U" class="btn-check" type="checkbox" data-filter-column="11" data-filter-value="U" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-marr-U" class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples with an unknown marriage date.') ?>">
                                <?= I18N::translate('Not married') ?>
                            </label>

                            <input id="<?= e($table_id) ?>-bg-marr-YES" class="btn-check" type="checkbox" data-filter-column="11" data-filter-value="YES" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-marr-YES" class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples who married more than 100 years ago.') ?>">
                                <?= I18N::translate('Marriage') ?>&gt;100
                            </label>

                            <input id="<?= e($table_id) ?>-bg-marr-Y100" class="btn-check" type="checkbox" data-filter-column="11" data-filter-value="Y100" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-marr-Y100" class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples who married within the last 100 years.') ?>">
                                <?= I18N::translate('Marriage') ?>&lt;=100
                            </label>

                            <input id="<?= e($table_id) ?>-bg-marr-D" class="btn-check" type="checkbox" data-filter-column="11" data-filter-value="D" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-marr-D" class="btn btn-outline-secondary" title="<?= I18N::translate('Show divorced couples.') ?>">
                                <?= I18N::translate('Divorce') ?>
                            </label>

                            <input id="<?= e($table_id) ?>-bg-marr-M" class="btn-check" type="checkbox" data-filter-column="11" data-filter-value="M" autocomplete="off">
                            <label for="<?= e($table_id) ?>-bg-marr-M" class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples where either partner married more than once.') ?>">
                                <?= I18N::translate('Multiple marriages') ?>
                            </label>
                        </div>
                    </div>
                </th>
            </tr>
            <tr>
                <th><?= I18N::translate('Given names') ?></th>
                <th><?= I18N::translate('Surname') ?></th>
                <th><?= I18N::translate('Age') ?></th>
                <th><?= I18N::translate('Given names') ?></th>
                <th><?= I18N::translate('Surname') ?></th>
                <th><?= I18N::translate('Age') ?></th>
                <th><?= I18N::translate('Marriage') ?></th>
                <th title="<?= I18N::translate('Anniversary') ?>">
                    <?= view('icons/anniversary') ?>
                </th>
                <th><?= I18N::translate('Place') ?></th>
                <th title="<?= I18N::translate('Children') ?>">
                    <?= view('icons/children') ?>
                </th>
                <th <?= $tree->getPreference('SHOW_LAST_CHANGE')==='1' ? '' : 'hidden="hidden"'?>>
                    <?= I18N::translate('Last change') ?>
                </th>
                <th hidden="hidden"></th>
                <th hidden="hidden"></th>
                <th hidden="hidden"></th>
            </tr>
        </thead>

        <tbody>
            <?php foreach ($families as $family) : ?>
                <?php $husb = $family->husband() ?? Registry::individualFactory()->new('H', '0 @H@ INDI', null, $family->tree()) ?>
                <?php $wife = $family->wife() ?? Registry::individualFactory()->new('W', '0 @W@ INDI', null, $family->tree()) ?>

                <tr class="<?= $family->isPendingAddition() ? 'wt-new' : '' ?> <?= $family->isPendingDeletion() ? 'wt-old' : '' ?>">
                    <!-- Husband name -->
                    <td colspan="2" data-sort="<?= e(str_replace([',', Individual::PRAENOMEN_NESCIO, Individual::NOMEN_NESCIO], 'AAAA', implode(',', array_reverse(explode(',', $husb->sortName()))))) ?>">
                        <?php foreach ($husb->getAllNames() as $num => $name) : ?>
                            <?php if ($name['type'] !== '_MARNM' || $num === $husb->getPrimaryName()) : ?>
                                <div>
                                    <a title="<?= $name['type'] === '_MARNM' ? I18N::translate('Married name') :  '' ?>" href="<?= e($family->url()) ?>" class="<?= $num === $husb->getPrimaryName() ? '' : 'text-muted' ?>">
                                        <?= $name['full'] ?>
                                    </a>
                                    <?php if ($num === $husb->getPrimaryName()) : ?>
                                        <small><?= view('icons/sex', ['sex' => $husb->sex()]) ?></small>
                                    <?php endif ?>
                                </div>
                            <?php endif ?>
                        <?php endforeach ?>
                        <?= view('lists/individual-table-parents', ['individual' => $husb]) ?>
                    </td>

                    <td hidden data-sort="<?= e(str_replace([',', Individual::PRAENOMEN_NESCIO, Individual::NOMEN_NESCIO], 'AAAA', $husb->sortName())) ?>"></td>

                    <!-- Husband age -->
                    <?php $age  = new Age($husb->getBirthDate(), $family->getMarriageDate()) ?>
                    <td class="text-center" data-sort="<?= $age->ageDays() ?>">
                        <?= $age->ageYearsString() ?>
                    </td>

                    <!-- Wife name -->
                    <td colspan="2" data-sort="<?= e(str_replace([',', Individual::PRAENOMEN_NESCIO, Individual::NOMEN_NESCIO], 'AAAA', implode(',', array_reverse(explode(',', $wife->sortName()))))) ?>">
                        <?php foreach ($wife->getAllNames() as $num => $name) : ?>
                            <?php if ($name['type'] !== '_MARNM' || $num === $wife->getPrimaryName()) : ?>
                                <div>
                                    <a title="<?= $name['type'] === '_MARNM' ? I18N::translate('Married name') :  '' ?>" href="<?= e($family->url()) ?>" class="<?= $num === $wife->getPrimaryName() ? '' : 'text-muted' ?>">
                                        <?= $name['full'] ?>
                                    </a>
                                    <?php if ($num === $wife->getPrimaryName()) : ?>
                                        <small><?= view('icons/sex', ['sex' => $wife->sex()]) ?></small>
                                    <?php endif ?>
                                </div>
                            <?php endif ?>
                        <?php endforeach ?>
                        <?= view('lists/individual-table-parents', ['individual' => $wife]) ?>
                    </td>

                    <td hidden data-sort="<?= e(str_replace([',', Individual::PRAENOMEN_NESCIO, Individual::NOMEN_NESCIO], 'AAAA', $wife->sortName())) ?>"></td>

                    <!-- Wife age -->
                    <?php $age = new Age($wife->getBirthDate(), $family->getMarriageDate()) ?>
                    <td class="text-center" data-sort="<?= $age->ageDays() ?>">
                        <?= $age->ageYearsString() ?>
                    </td>

                    <!-- Marriage date -->
                    <?php $marriage_dates = $family->getAllMarriageDates() ?>
                    <td data-sort="<?= sprintf('x%07d', $family->getMarriageDate()->julianDay()) ?>">
                        <?php if ($marriage_dates !== []) : ?>
                            <?php foreach ($marriage_dates as $marriage_date) : ?>
                                <div><?= $marriage_date->display($tree, null, true) ?></div>
                            <?php endforeach ?>
                        <?php elseif ($family->facts(['MARR'])->isEmpty()) : ?>
                            <?= I18N::translate('no') ?>
                        <?php elseif ($family->facts(['MARR'])->isNotEmpty()) : ?>
                            <?= I18N::translate('yes') ?>
                        <?php endif ?>
                    </td>

                    <!-- Marriage anniversary -->
                    <?php $age = new Age($family->getMarriageDate(), $today) ?>
                    <td class="text-center" data-sort="<?= $age->ageDays() ?>">
                        <?= $age->ageYearsString() ?>
                    </td>

                    <!-- Marriage place -->
                    <td data-sort="<?= e($family->getMarriagePlace()->gedcomName()) ?>">
                        <?php foreach ($family->getAllMarriagePlaces() as $marriage_place) : ?>
                            <div><?= $marriage_place->shortName(true) ?></div>
                        <?php endforeach ?>
                    </td>

                    <!-- Number of children -->
                    <td class="text-center" data-sort="<?= $family->numberOfChildren() ?>">
                        <?= I18N::number($family->numberOfChildren()) ?>
                    </td>

                    <!-- Last change -->
                    <td
                        <?= $tree->getPreference('SHOW_LAST_CHANGE') === '1' ? '' : 'hidden="hidden"' ?>
                        data-sort="<?= sprintf('x%07d', $family->lastChangeTimestamp()->timestamp()) ?>"
                    >
                        <?= view('components/datetime', ['timestamp' => $family->lastChangeTimestamp()]) ?>
                    </td>

                    <!-- Filter by marriage date -->
                    <td hidden="hidden">
                        <?php if ($family->getMarriageDate()->maximumJulianDay() > $hundred_years_ago && $family->getMarriageDate()->maximumJulianDay() <= $today_jd) : ?>
                            Y100
                        <?php elseif ($family->facts(['MARR'])->isNotEmpty()) : ?>
                            YES
                        <?php else : ?>
                            U
                        <?php endif ?>
                        <?php if ($family->facts(['DIV'])->isNotEmpty()) : ?>
                            D
                        <?php endif ?>
                        <?php if (count($husb->spouseFamilies()) > 1 || count($wife->spouseFamilies()) > 1) : ?>
                            M
                        <?php endif ?>
                    </td>

                    <!-- Filter by alive/dead -->
                    <td hidden="hidden">
                        <?php if ($husb->isDead() && $wife->isDead()) : ?>
                            Y
                        <?php endif ?>
                        <?php if ($husb->isDead() && !$wife->isDead()) : ?>
                            <?php if ($wife->sex() === 'F') : ?>
                                H
                            <?php endif ?>
                            <?php if ($wife->sex() === 'M') : ?>
                                W
                            <?php endif ?>
                        <?php endif ?>
                        <?php if (!$husb->isDead() && $wife->isDead()) : ?>
                            <?php if ($husb->sex() === 'M') : ?>
                                W
                            <?php endif ?>
                            <?php if ($husb->sex() === 'F') : ?>
                                H
                            <?php endif ?>
                        <?php endif ?>
                        <?php if (!$husb->isDead() && !$wife->isDead()) : ?>
                            N
                        <?php endif ?>
                    </td>

                    <!-- Filter by roots/leaves -->
                    <td hidden="hidden">
                        <?php if ($husb->childFamilies()->isEmpty() && $wife->childFamilies()->isEmpty()) : ?>
                            R
                        <?php elseif (!$husb->isDead() && !$wife->isDead() && $family->numberOfChildren() === 0) : ?>
                            L
                        <?php endif ?>
                    </td>
                </tr>
            <?php endforeach ?>
        </tbody>

        <tfoot>
            <tr>
                <th colspan="14">
                    <div class="btn-group btn-group-sm">
                        <input type="checkbox" class="btn-check" id="btn-toggle-parents" aria-expanded="false" autocomplete="off">
                        <label class="btn btn-secondary" for="btn-toggle-parents">
                            <?= I18N::translate('Show parents') ?>
                        </label>
                    </div>
                </th>
            </tr>
        </tfoot>
    </table>
</div>