1<?php 2 3declare(strict_types=1); 4 5use Fisharebest\Webtrees\Age; 6use Fisharebest\Webtrees\Carbon; 7use Fisharebest\Webtrees\Date; 8use Fisharebest\Webtrees\Family; 9use Fisharebest\Webtrees\GedcomTag; 10use Fisharebest\Webtrees\I18N; 11use Fisharebest\Webtrees\Individual; 12use Fisharebest\Webtrees\Tree; 13use Fisharebest\Webtrees\View; 14use Illuminate\Support\Collection; 15use Ramsey\Uuid\Uuid; 16 17$table_id = 'table-fam-' . Uuid::uuid4()->toString(); // lists requires a unique ID in case there are multiple lists per page 18 19$today_jd = Carbon::now()->julianDay(); 20$hundred_years_ago = Carbon::now()->subYears(100)->julianDay(); 21 22/** 23 * @var Tree $tree 24 * @var Collection<Family> $families 25 */ 26 27?> 28 29<?php View::push('javascript') ?> 30<script> 31$("#<?= e($table_id) ?> > .wt-table-family").dataTable({ 32 processing: true, 33 retrieve: true, 34 columns: [ 35 /* Given names */ { type: "text" }, 36 /* Surnames */ { type: "text" }, 37 /* Age */ { type: "num" }, 38 /* Given names */ { type: "text" }, 39 /* Surnames */ { type: "text" }, 40 /* Age */ { type: "num" }, 41 /* Marriage date */ { type: "num" }, 42 /* Anniversary */ { type: "num" }, 43 /* Marriage place */ { type: "text" }, 44 /* Children */ { type: "num" }, 45 /* Last change */ { visible: <?= json_encode((bool) $tree->getPreference('SHOW_LAST_CHANGE')) ?> }, 46 /* Filter marriage */ { sortable: false }, 47 /* Filter alive/dead */ { sortable: false }, 48 /* Filter tree */ { sortable: false } 49 ], 50 sorting: [ 51 [1, "asc"] 52 ] 53}); 54 55$("#<?= e($table_id) ?>") 56 /* Hide/show parents */ 57 .on("click", "#btn-toggle-parents", function() { 58 $(".wt-individual-list-parents").slideToggle(); 59 }) 60 /* Hide/show statistics */ 61 .on("click", "#btn-toggle-statistics", function() { 62 $("#family-charts-<?= e($table_id) ?>").slideToggle({ 63 complete: function () { 64 // Trigger resize to redraw the chart 65 $('div[id^="google-chart-"]').resize(); 66 } 67 }); 68 }) 69 /* Filter buttons in table header */ 70 .on("click", "input[data-filter-column]", function() { 71 let checkbox = $(this); 72 let siblings = checkbox.parent().siblings(); 73 74 // Deselect other options 75 siblings.children().prop("checked", false).removeAttr("checked"); 76 siblings.removeClass('active'); 77 78 // Apply (or clear) this filter 79 let checked = checkbox.prop("checked"); 80 let filter = checked ? checkbox.data("filter-value") : ""; 81 let column = $("#<?= e($table_id) ?> .wt-table-family").DataTable().column(checkbox.data("filter-column")); 82 column.search(filter).draw(); 83 }); 84</script> 85<?php View::endpush() ?> 86 87<?php 88$max_age = (int) $tree->getPreference('MAX_ALIVE_AGE'); 89 90// init chart data 91$marr_by_age = []; 92for ($age = 0; $age <= $max_age; $age++) { 93 $marr_by_age[$age]['M'] = 0; 94 $marr_by_age[$age]['F'] = 0; 95 $marr_by_age[$age]['U'] = 0; 96} 97$birt_by_decade = []; 98$marr_by_decade = []; 99for ($year = 1400; $year < 2050; $year += 10) { 100 $birt_by_decade[$year]['M'] = 0; 101 $birt_by_decade[$year]['F'] = 0; 102 $birt_by_decade[$year]['U'] = 0; 103 $marr_by_decade[$year]['M'] = 0; 104 $marr_by_decade[$year]['F'] = 0; 105 $marr_by_decade[$year]['U'] = 0; 106} 107 108$birthData = [ 109 [ 110 [ 111 'label' => I18N::translate('Century'), 112 'type' => 'date', 113 ], [ 114 'label' => I18N::translate('Males'), 115 'type' => 'number', 116 ], [ 117 'label' => I18N::translate('Females'), 118 'type' => 'number', 119 ], 120 ] 121]; 122 123$marriageData = [ 124 [ 125 [ 126 'label' => I18N::translate('Century'), 127 'type' => 'date', 128 ], [ 129 'label' => I18N::translate('Males'), 130 'type' => 'number', 131 ], [ 132 'label' => I18N::translate('Females'), 133 'type' => 'number', 134 ], 135 ] 136]; 137 138$marriageAgeData = [ 139 [ 140 I18N::translate('Age'), 141 I18N::translate('Males'), 142 I18N::translate('Females'), 143 I18N::translate('Average age'), 144 ] 145]; 146 147?> 148 149<div id="<?= e($table_id) ?>"> 150 <table class="table table-bordered table-sm wt-table-family" 151 <?= view('lists/datatables-attributes') ?> 152 > 153 <thead> 154 <tr> 155 <th colspan="14"> 156 <div class="btn-toolbar d-flex justify-content-between mb-2"> 157 <div class="btn-group btn-group-toggle btn-group-sm" data-toggle="buttons"> 158 <label class="btn btn-outline-secondary btn-sm" title="' . I18N::translate('Show individuals who are alive or couples where both partners are alive.') ?>"> 159 <input type="checkbox" data-filter-column="12" data-filter-value="N"> 160 <?= I18N::translate('Both alive') ?> 161 </label> 162 <label class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples where only the female partner is dead.') ?>"> 163 <input type="checkbox" data-filter-column="12" data-filter-value="W"> 164 <?= I18N::translate('Widower') ?> 165 </label> 166 <label class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples where only the male partner is dead.') ?>"> 167 <input type="checkbox" data-filter-column="12" data-filter-value="H"> 168 <?= I18N::translate('Widow') ?> 169 </label> 170 <label class="btn btn-outline-secondary" title="<?= I18N::translate('Show individuals who are dead or couples where both partners are dead.') ?>"> 171 <input type="checkbox" data-filter-column="12" data-filter-value="Y"> 172 <?= I18N::translate('Both dead') ?> 173 </label> 174 </div> 175 176 <div class="btn-group btn-group-toggle btn-group-sm" data-toggle="buttons"> 177 <label 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.') ?>"> 178 <input type="checkbox" data-filter-column="13" data-filter-value="R"> 179 <?= I18N::translate('Roots') ?> 180 </label> 181 <label 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.') ?>"> 182 <input type="checkbox" data-filter-column="13" data-filter-value="L"> 183 <?= I18N::translate('Leaves') ?> 184 </label> 185 </div> 186 187 <div class="btn-group btn-group-toggle btn-group-sm" data-toggle="buttons"> 188 <label class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples with an unknown marriage date.') ?>"> 189 <input type="checkbox" data-filter-column="11" data-filter-value="U"> 190 <?= I18N::translate('Not married') ?> 191 </label> 192 <label class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples who married more than 100 years ago.') ?>"> 193 <input type="checkbox" data-filter-column="11" data-filter-value="YES"> 194 <?= I18N::translate('Marriage') ?>>100 195 </label> 196 <label class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples who married within the last 100 years.') ?>"> 197 <input type="checkbox" data-filter-column="11" data-filter-value="Y100"> 198 <?= I18N::translate('Marriage') ?><=100 199 </label> 200 <label class="btn btn-outline-secondary" title="<?= I18N::translate('Show divorced couples.') ?>"> 201 <input type="checkbox" data-filter-column="11" data-filter-value="D"> 202 <?= I18N::translate('Divorce') ?> 203 </label> 204 <label class="btn btn-outline-secondary" title="<?= I18N::translate('Show couples where either partner married more than once.') ?>"> 205 <input type="checkbox" data-filter-column="11" data-filter-value="M"> 206 <?= I18N::translate('Multiple marriages') ?> 207 </label> 208 </div> 209 </div> 210 </th> 211 </tr> 212 <tr> 213 <th><?= I18N::translate('Given names') ?></th> 214 <th><?= I18N::translate('Surname') ?></th> 215 <th><?= I18N::translate('Age') ?></th> 216 <th><?= I18N::translate('Given names') ?></th> 217 <th><?= I18N::translate('Surname') ?></th> 218 <th><?= I18N::translate('Age') ?></th> 219 <th><?= I18N::translate('Marriage') ?></th> 220 <th> 221 <span title="<?= I18N::translate('Anniversary') ?>"> 222 <?= view('icons/anniversary') ?> 223 </span> 224 </th> 225 <th><?= I18N::translate('Place') ?></th> 226 <th><i class="icon-children" title="<?= I18N::translate('Children') ?>"></i></th> 227 <th><?= I18N::translate('Last change') ?></th> 228 <th hidden></th> 229 <th hidden></th> 230 <th hidden></th> 231 </tr> 232 </thead> 233 234 <tbody> 235 <?php foreach ($families as $family) : ?> 236 <?php $husb = $family->husband() ?? new Individual('H', '0 @H@ INDI', null, $family->tree()) ?> 237 <?php $wife = $family->wife() ?? new Individual('W', '0 @W@ INDI', null, $family->tree()) ?> 238 239 <tr class="<?= $family->isPendingDeletion() ? 'wt-old' : ($family->isPendingAddition() ? 'wt-new' : '') ?>"> 240 <!-- Husband name --> 241 <td colspan="2" data-sort="<?= e(str_replace([',', '@P.N.', '@N.N.'], 'AAAA', implode(',', array_reverse(explode(',', $husb->sortName()))))) ?>"> 242 <?php foreach ($husb->getAllNames() as $num => $name) : ?> 243 <?php if ($name['type'] !== '_MARNM' || $num == $husb->getPrimaryName()) : ?> 244 <a title="<?= $name['type'] === 'NAME' ? '' : strip_tags(GedcomTag::getLabel($name['type'], $husb)) ?>" href="<?= e($family->url()) ?>" class="<?= $num === $husb->getPrimaryName() ? 'name2' : '' ?>"> 245 <?= $name['full'] ?> 246 </a> 247 <?php if ($num === $husb->getPrimaryName()) : ?> 248 <small><?= view('icons/sex', ['sex' => $husb->sex()]) ?></small> 249 <?php endif ?> 250 <br> 251 <?php endif ?> 252 <?php endforeach ?> 253 <?= view('lists/individual-table-parents', ['individual' => $husb]) ?> 254 </td> 255 256 <td hidden data-sort="<?= e(str_replace([',', '@P.N.', '@N.N.'], 'AAAA', $husb->sortName())) ?>"></td> 257 258 <!-- Husband age --> 259 <?php 260 $mdate = $family->getMarriageDate(); 261 $hdate = $husb->getBirthDate(); 262 263 if ($hdate->isOK() && $mdate->isOK()) { 264 $gregorian_year = $hdate->gregorianYear(); 265 266 if ($gregorian_year >= 1550 && $gregorian_year < 2030) { 267 ++$birt_by_decade[(int) ($gregorian_year / 10) * 10][$husb->sex()]; 268 } 269 270 $husband_age = new Age($hdate, $mdate); 271 $husband_age_sort = $husband_age->agedays(); 272 $husband_age_years = $husband_age->ageYears(); 273 $husband_age_display = I18N::number($husband_age_years); 274 275 if ($husband_age_years >= 0 && $husband_age_years <= $max_age) { 276 ++$marr_by_age[$husband_age_years][$husb->sex()]; 277 } 278 } else { 279 $husband_age_sort = 0; 280 $husband_age_display = ''; 281 } 282 ?> 283 <td class="text-center" data-sort="<?= $husband_age_sort ?>"> 284 <?= $husband_age_display ?> 285 </td> 286 287 <!-- Wife name --> 288 <td colspan="2" data-sort="<?= e(str_replace([',', '@P.N.', '@N.N.'], 'AAAA', implode(',', array_reverse(explode(',', $wife->sortName()))))) ?>"> 289 <?php foreach ($wife->getAllNames() as $num => $name) : ?> 290 <?php if ($name['type'] !== '_MARNM' || $num == $wife->getPrimaryName()) : ?> 291 <a title="<?= $name['type'] === 'NAME' ? '' : strip_tags(GedcomTag::getLabel($name['type'], $wife)) ?>" href="<?= e($family->url()) ?>" class="<?= $num === $wife->getPrimaryName() ? 'name2' : '' ?>"> 292 <?= $name['full'] ?> 293 </a> 294 <?php if ($num === $wife->getPrimaryName()) : ?> 295 <small><?= view('icons/sex', ['sex' => $wife->sex()]) ?></small> 296 <?php endif ?> 297 <br> 298 <?php endif ?> 299 <?php endforeach ?> 300 <?= view('lists/individual-table-parents', ['individual' => $wife]) ?> 301 </td> 302 303 <td hidden data-sort="<?= e(str_replace([',', '@P.N.', '@N.N.'], 'AAAA', $wife->sortName())) ?>"></td> 304 305 <!-- Wife age --> 306 <?php 307 $wdate = $wife->getBirthDate(); 308 if ($wdate->isOK() && $mdate->isOK()) { 309 $gregorian_year = $wdate->gregorianYear(); 310 311 if ($gregorian_year >= 1550 && $gregorian_year < 2030) { 312 ++$birt_by_decade[(int) ($gregorian_year / 10) * 10][$husb->sex()]; 313 } 314 315 $wife_age = new Age($wdate, $mdate); 316 $wife_age_sort = $wife_age->ageDays(); 317 $wife_age_years = $wife_age->ageYears(); 318 $wife_age_display = I18N::number($wife_age_years); 319 320 if ($wife_age_years >= 0 && $wife_age_years <= $max_age) { 321 ++$marr_by_age[$wife_age_years][$husb->sex()]; 322 } 323 } else { 324 $wife_age_sort = 0; 325 $wife_age_display = ''; 326 } 327 ?> 328 <td class="text-center" data-sort="<?= $wife_age_sort ?>"> 329 <?= $wife_age_display ?> 330 </td> 331 332 <!-- Marriage date --> 333 <td data-sort="<?= $family->getMarriageDate()->julianDay() ?>"> 334 <?php if ($marriage_dates = $family->getAllMarriageDates()) : ?> 335 <?php foreach ($marriage_dates as $n => $marriage_date) : ?> 336 <div><?= $marriage_date->display(true) ?></div> 337 <?php endforeach ?> 338 <?php if ($marriage_dates[0]->gregorianYear() >= 1550 && $marriage_dates[0]->gregorianYear() < 2030) : ?> 339 <?php 340 ++$marr_by_decade[(int) ($marriage_dates[0]->gregorianYear() / 10) * 10][$husb->sex()]; 341 ++$marr_by_decade[(int) ($marriage_dates[0]->gregorianYear() / 10) * 10][$wife->sex()]; 342 ?> 343 <?php endif ?> 344 <?php elseif ($family->facts(['_NMR'])->isNotEmpty()) : ?> 345 <?= I18N::translate('no') ?> 346 <?php elseif ($family->facts(['MARR'])->isNotEmpty()) : ?> 347 <?= I18N::translate('yes') ?> 348 <?php endif ?> 349 </td> 350 351 <!-- Marriage anniversary --> 352 <?php 353 $marriage_date = $family->getMarriageDate(); 354 if ($marriage_date->isOK()) { 355 $marriage_anniversary = new Age($marriage_date, new Date(strtoupper(date('d M Y')))); 356 $marriage_anniversary_sort = $marriage_anniversary->ageDays(); 357 $marriage_anniversary_display = I18N::number($marriage_anniversary->ageYears()); 358 } else { 359 $marriage_anniversary_sort = 0; 360 $marriage_anniversary_display = ''; 361 } 362 ?> 363 <td class="text-center" data-sort="<?= $marriage_anniversary_sort ?>"> 364 <?= $marriage_anniversary_display ?> 365 </td> 366 367 <!-- Marriage place --> 368 <td> 369 <?php foreach ($family->getAllMarriagePlaces() as $n => $marriage_place) : ?> 370 <?= $marriage_place->shortName(true) ?> 371 <br> 372 <?php endforeach ?> 373 </td> 374 375 <!-- Number of children --> 376 <td class="text-center" data-sort="<?= $family->numberOfChildren() ?>"> 377 <?= I18N::number($family->numberOfChildren()) ?> 378 </td> 379 380 <!-- Last change --> 381 <td data-sort="<?= $family->lastChangeTimestamp()->unix() ?>"> 382 <?= view('components/datetime', ['timestamp' => $family->lastChangeTimestamp()]) ?> 383 </td> 384 385 <!-- Filter by marriage date --> 386 <td hidden> 387 <?php if ($mdate->maximumJulianDay() > $hundred_years_ago && $mdate->maximumJulianDay() <= $today_jd) : ?> 388 Y100 389 <?php elseif ($family->facts(['MARR'])->isNotEmpty()) : ?> 390 YES 391 <?php else : ?> 392 U 393 <?php endif ?> 394 <?php if ($family->facts(['DIV'])->isNotEmpty()) : ?> 395 D 396 <?php endif ?> 397 <?php if (count($husb->spouseFamilies()) > 1 || count($wife->spouseFamilies()) > 1) : ?> 398 M 399 <?php endif ?> 400 </td> 401 402 <!-- Filter by alive/dead --> 403 <td hidden> 404 <?php if ($husb->isDead() && $wife->isDead()) : ?> 405 Y 406 <?php endif ?> 407 <?php if ($husb->isDead() && !$wife->isDead()) : ?> 408 <?php if ($wife->sex() === 'F') : ?> 409 H 410 <?php endif ?> 411 <?php if ($wife->sex() === 'M') : ?> 412 W 413 <?php endif ?> 414 <?php endif ?> 415 <?php if (!$husb->isDead() && $wife->isDead()) : ?> 416 <?php if ($husb->sex() === 'M') : ?> 417 W 418 <?php endif ?> 419 <?php if ($husb->sex() === 'F') : ?> 420 H 421 <?php endif ?> 422 <?php endif ?> 423 <?php if (!$husb->isDead() && !$wife->isDead()) : ?> 424 N 425 <?php endif ?> 426 </td> 427 428 <!-- Filter by roots/leaves --> 429 <td hidden> 430 <?php if (!$husb->childFamilies() && !$wife->childFamilies()) : ?> 431 R 432 <?php elseif (!$husb->isDead() && !$wife->isDead() && $family->numberOfChildren() === 0) : ?> 433 L 434 <?php endif ?> 435 </td> 436 </tr> 437 <?php endforeach ?> 438 </tbody> 439 440 <tfoot> 441 <tr> 442 <th colspan="14"> 443 <div class="btn-group btn-group-sm"> 444 <button id="btn-toggle-parents" class="btn btn-outline-secondary" data-toggle="button" data-persist="show-parents"> 445 <?= I18N::translate('Show parents') ?> 446 </button> 447 <button id="btn-toggle-statistics" class="btn btn-outline-secondary" data-toggle="button" data-persist="show-statistics"> 448 <?= I18N::translate('Show statistics charts') ?> 449 </button> 450 </div> 451 </th> 452 </tr> 453 </tfoot> 454 </table> 455</div> 456 457<div id="family-charts-<?= e($table_id) ?>" style="display: none;"> 458 <div class="mb-3"> 459 <div class="card-deck"> 460 <div class="col-lg-12 col-md-12 mb-3"> 461 <div class="card m-0"> 462 <div class="card-header"> 463 <?= I18N::translate('Decade of birth') ?> 464 </div><div class="card-body"> 465 <?php 466 foreach ($birt_by_decade as $century => $values) { 467 if (($values['M'] + $values['F']) > 0) { 468 $birthData[] = [ 469 [ 470 'v' => 'Date(' . $century . ', 0, 1)', 471 'f' => $century, 472 ], 473 $values['M'], 474 $values['F'], 475 ]; 476 } 477 } 478 ?> 479 <?= view('lists/chart-by-decade', ['data' => $birthData, 'title' => I18N::translate('Decade of birth')]) ?> 480 </div> 481 </div> 482 </div> 483 </div> 484 <div class="card-deck"> 485 <div class="col-lg-12 col-md-12 mb-3"> 486 <div class="card m-0"> 487 <div class="card-header"> 488 <?= I18N::translate('Decade of marriage') ?> 489 </div><div class="card-body"> 490 <?php 491 foreach ($marr_by_decade as $century => $values) { 492 if (($values['M'] + $values['F']) > 0) { 493 $marriageData[] = [ 494 [ 495 'v' => 'Date(' . $century . ', 0, 1)', 496 'f' => $century, 497 ], 498 $values['M'], 499 $values['F'], 500 ]; 501 } 502 } 503 ?> 504 <?= view('lists/chart-by-decade', ['data' => $marriageData, 'title' => I18N::translate('Decade of marriage')]) ?> 505 </div> 506 </div> 507 </div> 508 </div> 509 <div class="card-deck"> 510 <div class="col-lg-12 col-md-12 mb-3"> 511 <div class="card m-0"> 512 <div class="card-header"> 513 <?= I18N::translate('Age in year of marriage') ?> 514 </div> 515 <div class="card-body"> 516 <?php 517 $totalAge = 0; 518 $totalSum = 0; 519 $max = 0; 520 521 foreach ($marr_by_age as $age => $values) { 522 if (($values['M'] + $values['F']) > 0) { 523 if (($values['M'] + $values['F']) > $max) { 524 $max = $values['M'] + $values['F']; 525 } 526 527 $totalAge += $age * ($values['M'] + $values['F']); 528 $totalSum += $values['M'] + $values['F']; 529 530 $marriageAgeData[] = [ 531 $age, 532 $values['M'], 533 $values['F'], 534 null, 535 ]; 536 } 537 } 538 539 if ($totalSum > 0) { 540 $marriageAgeData[] = [ 541 round($totalAge / $totalSum, 1), 542 null, 543 null, 544 0, 545 ]; 546 547 $marriageAgeData[] = [ 548 round($totalAge / $totalSum, 1), 549 null, 550 null, 551 $max, 552 ]; 553 } 554 ?> 555 <?= view('lists/chart-by-age', ['data' => $marriageAgeData, 'title' => I18N::translate('Age in year of marriage')]) ?> 556 </div> 557 </div> 558 </div> 559 </div> 560 </div> 561</div> 562