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