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