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