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