summaryrefslogtreecommitdiff
path: root/resources/views/lists/families-table.phtml
blob: 361c4790d298cdb06bb7aa9748f8f0a561a06aa1 (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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<?php use Fisharebest\Webtrees\Date; ?>
<?php use Fisharebest\Webtrees\Gedcom; ?>
<?php use Fisharebest\Webtrees\GedcomTag; ?>
<?php use Fisharebest\Webtrees\I18N; ?>
<?php use Fisharebest\Webtrees\Individual; ?>
<?php use Fisharebest\Webtrees\View; ?>
<?php use Ramsey\Uuid\Uuid; ?>

<?php
$table_id = 'table-fam-' . Uuid::uuid4()->toString(); // lists requires a unique ID in case there are multiple lists per page
$hundred_years_ago = new Date(date('Y') - 100);
?>

<?php View::push('javascript') ?>
<script>
    $("#<?= e($table_id) ?>").dataTable( {
dom: '<"H"<"filtersH_<?= e($table_id) ?>"><"dt-clear">pf<"dt-clear">irl>t<"F"pl<"dt-clear"><"filtersF_<?= e($table_id) ?>">>',
<?= I18N::datatablesI18N() ?>,
autoWidth: false,
processing: true,
retrieve: true,
columns: [
/* Given names         */ { type: "text" },
/* Surnames            */ { type: "text" },
/* Age                 */ { type: "num" },
/* Given names         */ { type: "text" },
/* Surnames            */ { type: "text" },
/* Age                 */ { type: "num" },
/* Marriage date       */ { type: "num" },
/* Anniversary         */ { type: "num" },
/* Marriage place      */ { type: "text" },
/* Children            */ { type: "num" },
/* Last change         */ { visible: <?= json_encode((bool) $tree->getPreference('SHOW_LAST_CHANGE')) ?> },
/* Filter marriage     */ { sortable: false },
/* Filter alive/dead   */ { sortable: false },
/* Filter tree         */ { sortable: false }
],
sorting: [[1, "asc"]],
displayLength: 20,
pagingType: "full_numbers"
})
/* Hide/show parents */
.on("click", ".btn-toggle-parents", function() {
$(this).toggleClass("ui-state-active");
$(".parents", $(this).closest("table").DataTable().rows().nodes()).slideToggle();
})
/* Hide/show statistics */
.on("click",  ".btn-toggle-statistics", function() {
$(this).toggleClass("ui-state-active");
$("#family-charts-<?= e($table_id) ?>").slideToggle();
})
/* Filter buttons in table header */
.on("click", "button[data-filter-column]", function() {
var btn = $(this);
// De-activate the other buttons in this button group
btn.siblings().removeClass("active");
// Apply (or clear) this filter
var col = $("#<?= e($table_id) ?>").DataTable().column(btn.data("filter-column"));
if (btn.hasClass("active")) {
col.search("").draw();
} else {
col.search(btn.data("filter-value")).draw();
}
});
</script>
<?php View::endpush() ?>

<?php
$max_age = (int) $tree->getPreference('MAX_ALIVE_AGE');

// init chart data
$marr_by_age = [];
for ($age = 0; $age <= $max_age; $age++) {
    $marr_by_age[$age] = '';
}
$birt_by_decade = [];
$marr_by_decade = [];
for ($year = 1550; $year < 2030; $year += 10) {
    $birt_by_decade[$year] = '';
    $marr_by_decade[$year] = '';
}
?>

<div class="fam-list">
    <table id="<?= e($table_id) ?>">
        <thead>
            <tr>
                <th colspan="14">
                    <div class="btn-toolbar d-flex justify-content-between mb-2">
                        <div class="btn-group" data-toggle="buttons">
                            <button
                                class="btn btn-secondary"
                                data-filter-column="12"
                                data-filter-value="N"
                                title="' . I18N::translate('Show individuals who are alive or couples where both partners are alive.') ?>"
                            >
                                <?= I18N::translate('Both alive') ?>
                            </button>
                            <button
                                class="btn btn-secondary"
                                data-filter-column="12"
                                data-filter-value="W"
                                title="<?= I18N::translate('Show couples where only the female partner is dead.') ?>"
                            >
                                <?= I18N::translate('Widower') ?>
                            </button>
                            <button
                                class="btn btn-secondary"
                                data-filter-column="12"
                                data-filter-value="H"
                                title="<?= I18N::translate('Show couples where only the male partner is dead.') ?>"
                            >
                                <?= I18N::translate('Widow') ?>
                            </button>
                            <button
                                class="btn btn-secondary"
                                data-filter-column="12"
                                data-filter-value="Y"
                                title="<?= I18N::translate('Show individuals who are dead or couples where both partners are dead.') ?>"
                            >
                                <?= I18N::translate('Both dead') ?>
                            </button>
                        </div>
                        <div class="btn-group" data-toggle="buttons">
                            <button
                                class="btn btn-secondary"
                                data-filter-column="13"
                                data-filter-value="R"
                                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') ?>
                            </button>
                            <button
                                class="btn btn-secondary"
                                data-filter-column="13"
                                data-filter-value="L"
                                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') ?>
                            </button>
                        </div>
                        <div class="btn-group" data-toggle="buttons">
                            <button
                                class="btn btn-secondary"
                                data-filter-column="11"
                                data-filter-value="U"
                                title="<?= I18N::translate('Show couples with an unknown marriage date.') ?>"
                            >
                                <?= I18N::translate('Marriage') ?>
                            </button>
                            <button
                                class="btn btn-secondary"
                                data-filter-column="11"
                                data-filter-value="YES"
                                title="<?= I18N::translate('Show couples who married more than 100 years ago.') ?>"
                            >
                                <?= I18N::translate('Marriage') ?>&gt;100
                            </button>
                            <button
                                class="btn btn-secondary"
                                data-filter-column="11"
                                data-filter-value="Y100"
                                title="<?= I18N::translate('Show couples who married within the last 100 years.') ?>"
                            >
                                <?= I18N::translate('Marriage') ?>&lt;=100
                            </button>
                            <button
                                class="btn btn-secondary"
                                data-filter-column="11"
                                data-filter-value="D"
                                title="<?= I18N::translate('Show divorced couples.') ?>"
                            >
                                <?= I18N::translate('Divorce') ?>
                            </button>
                            <button
                                class="btn btn-secondary"
                                data-filter-column="11"
                                data-filter-value="M"
                                title="<?= I18N::translate('Show couples where either partner married more than once.') ?>"
                            >
                                <?= I18N::translate('Multiple marriages') ?>
                            </button>
                        </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><i class="icon-reminder" title="<?= I18N::translate('Anniversary') ?>"></i></th>
                <th><?= I18N::translate('Place') ?></th>
                <th><i class="icon-children" title="<?= I18N::translate('Children') ?>"></i></th>
                <th><?= I18N::translate('Last change') ?></th>
                <th hidden></th>
                <th hidden></th>
                <th hidden></th>
            </tr>
        </thead>

        <tfoot>
            <tr>
                <th colspan="14">
                    <div class="btn-toolbar">
                        <div class="btn-group">
                            <button class="ui-state-default btn-toggle-parents">
                                <?= I18N::translate('Show parents') ?>
                            </button>
                            <button class="ui-state-default btn-toggle-statistics">
                                <?= I18N::translate('Show statistics charts') ?>
                            </button>
                        </div>
                    </div>
                </th>
            </tr>
        </tfoot>
        <tbody>

        <?php foreach ($families as $family) : ?>
            <?php $husb = $family->getHusband() ?? new Individual('H', '0 @H@ INDI', null, $family->tree()) ?>
            <?php $wife = $family->getWife() ?? new Individual('W', '0 @W@ INDI', null, $family->tree()) ?>

            <tr class="<?= $family->isPendingDeletion() ? 'old' : ($family->isPendingAddition() ? 'new' : '') ?>">
                <!-- Husband name -->
                <td colspan="2" data-sort="<?= e(str_replace([',', '@P.N.', '@N.N.'], 'AAAA', implode(',', array_reverse(explode(',', $husb->getSortName()))))) ?>">
                    <?php foreach ($husb->getAllNames() as $num => $name) : ?>
                        <?php if ($name['type'] != '_MARNM' || $num == $husb->getPrimaryName()) : ?>
                        <a title="<?= $name['type'] === 'NAME' ? '' : GedcomTag::getLabel($name['type'], $husb) ?>" href="<?= e($family->url()) ?>" class="<?= $num === $husb->getPrimaryName() ? 'name2' : '' ?>">
                            <?= $name['full'] ?>
                        </a>
                            <?php if ($num === $husb->getPrimaryName()) : ?>
                                <?= $husb->getSexImage() ?>
                            <?php endif ?>
                        <br>
                        <?php endif ?>
                    <?php endforeach ?>
                    <?= $husb->getPrimaryParentsNames('parents details1', 'none') ?>
                </td>

                <td hidden data-sort="<?= e(str_replace([',', '@P.N.', '@N.N.'], 'AAAA', $husb->getSortName())) ?>"></td>

                <!-- Husband age -->
                <?php
                $mdate = $family->getMarriageDate();
                $hdate = $husb->getBirthDate();
                if ($hdate->isOK() && $mdate->isOK()) {
                    if ($hdate->gregorianYear() >= 1550 && $hdate->gregorianYear() < 2030) {
                        $birt_by_decade[(int) ($hdate->gregorianYear() / 10) * 10] .= $husb->getSex();
                    }
                    $hage = Date::getAgeYears($hdate, $mdate);
                    if ($hage >= 0 && $hage <= $max_age) {
                        $marr_by_age[$hage] .= $husb->getSex();
                    }
                }
                ?>
                <td class="center" data-sort="<?= Date::getAgeDays($hdate, $mdate) ?>">
                    <?= Date::getAge($hdate, $mdate) ?>
                </td>

                <!-- Wife name -->
                <td colspan="2" data-sort="<?= e(str_replace([',', '@P.N.', '@N.N.'], 'AAAA', implode(',', array_reverse(explode(',', $wife->getSortName()))))) ?>">
                    <?php foreach ($wife->getAllNames() as $num => $name) : ?>
                        <?php if ($name['type'] != '_MARNM' || $num == $wife->getPrimaryName()) : ?>
                            <a title="<?= $name['type'] === 'NAME' ? '' : GedcomTag::getLabel($name['type'], $wife) ?>" href="<?= e($family->url()) ?>" class="<?= $num === $wife->getPrimaryName() ? 'name2' : '' ?>">
                                <?= $name['full'] ?>
                            </a>
                            <?php if ($num === $wife->getPrimaryName()) : ?>
                                <?= $wife->getSexImage() ?>
                            <?php endif ?>
                            <br>
                        <?php endif ?>
                    <?php endforeach ?>
                    <?= $wife->getPrimaryParentsNames('parents details1', 'none') ?>
                </td>

                <td hidden data-sort="<?= e(str_replace([',', '@P.N.', '@N.N.'], 'AAAA', $wife->getSortName())) ?>"></td>

                <!-- Wife age -->
                <?php
                $wdate = $wife->getBirthDate();
                if ($wdate->isOK() && $mdate->isOK()) {
                    if ($wdate->gregorianYear() >= 1550 && $wdate->gregorianYear() < 2030) {
                        $birt_by_decade[(int) ($wdate->gregorianYear() / 10) * 10] .= $wife->getSex();
                    }
                    $wage = Date::getAgeYears($wdate, $mdate);
                    if ($wage >= 0 && $wage <= $max_age) {
                        $marr_by_age[$wage] .= $wife->getSex();
                    }
                }
                ?>

                <td class="center" data-sort="<?= Date::getAgeDays($wdate, $mdate) ?>">
                    <?= Date::getAge($wdate, $mdate) ?>
                </td>

                <!-- Marriage date -->
                <td data-sort="<?= $family->getMarriageDate()->julianDay() ?>">
                    <?php if ($marriage_dates = $family->getAllMarriageDates()) : ?>
                        <?php foreach ($marriage_dates as $n => $marriage_date) : ?>
                            <div><?= $marriage_date->display(true) ?></div>
                        <?php endforeach ?>
                        <?php if ($marriage_dates[0]->gregorianYear() >= 1550 && $marriage_dates[0]->gregorianYear() < 2030) : ?>
                            <?php $marr_by_decade[(int) ($marriage_dates[0]->gregorianYear() / 10) * 10] .= $husb->getSex() . $wife->getSex() ?>
                        <?php endif ?>
                    <?php elseif ($family->facts(['_NMR'])) : ?>
                        <?= I18N::translate('no') ?>
                    <?php elseif ($family->facts(['MARR'])) : ?>
                            <?= I18N::translate('yes') ?>
                    <?php endif ?>
                </td>

                <!-- Marriage anniversary -->
                <td class="center" data-sort="<?= -$family->getMarriageDate()->julianDay() ?>">
                    <?= Date::getAge($family->getMarriageDate(), null) ?>
                </td>

                <!-- Marriage place -->
                <td>
                    <?php foreach ($family->getAllMarriagePlaces() as $n => $marriage_place) : ?>
                        <?= $marriage_place->shortName(true) ?>
                        <br>
                    <?php endforeach ?>
                </td>

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

                <!-- Last change -->
                <td data-sort="<?= $family->lastChangeTimestamp(true) ?>">
                    <?= $family->lastChangeTimestamp() ?>
                </td>

                <!-- Filter by marriage date -->
                <td hidden>
                    <?php if (!$family->canShow() || !$mdate->isOK()) : ?>
                        U
                    <?php elseif (Date::compare($mdate, $hundred_years_ago) > 0) : ?>
                        Y100
                    <?php else : ?>
                        YES
                    <?php endif ?>
                    <?php if ($family->facts(Gedcom::DIVORCE_EVENTS)) : ?>
                        D
                    <?php endif ?>
                    <?php if (count($husb->getSpouseFamilies()) > 1 || count($wife->getSpouseFamilies()) > 1) : ?>
                        M
                    <?php endif ?>
                </td>

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

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

    <div id="family-charts-<?= e($table_id) ?>" style="display:none">
        <table class="list-charts">
            <tr>
                <td>
                    <?= view('lists/chart-by-decade', ['data' => $birt_by_decade, 'title' => I18N::translate('Decade of birth')]) ?>
        </td>
        <td>
                    <?= view('lists/chart-by-decade', ['data' => $marr_by_decade, 'title' => I18N::translate('Decade of marriage')]) ?>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <?= view('lists/chart-by-age', ['data' => $marr_by_age, 'title' => I18N::translate('Age in year of marriage')]) ?>
                </td>
            </tr>
        </table>
    </div>
</div>