1<?php 2 3declare(strict_types=1); 4 5use Fisharebest\Webtrees\I18N; 6use Fisharebest\Webtrees\Location; 7use Fisharebest\Webtrees\Tree; 8use Illuminate\Database\Capsule\Manager as DB; 9use Illuminate\Database\Query\Expression; 10use Illuminate\Database\Query\JoinClause; 11use Illuminate\Support\Collection; 12 13/** 14 * @var Collection<int,Location> $locations 15 * @var Tree $tree 16 */ 17 18?> 19 20<?php 21// Count the number of linked records. These numbers include private records. 22// It is not good to bypass privacy, but many servers do not have the resources 23// to process privacy for every record in the tree 24$count_individuals = DB::table('individuals') 25 ->join('link', static function (JoinClause $join): void { 26 $join->on('l_from', '=', 'i_id'); 27 $join->on('l_file', '=', 'i_file'); 28 }) 29 ->where('l_type', '=', '_LOC') 30 ->where('l_file', '=', $tree->id()) 31 ->groupBy(['l_to']) 32 ->select(['l_to', new Expression('COUNT(*) AS total')]) 33 ->pluck('total', 'l_to') 34 ->map(static fn ($n) => (int) $n) 35 ->all(); 36 37$count_families = DB::table('families') 38 ->join('link', static function (JoinClause $join): void { 39 $join->on('l_from', '=', 'f_id'); 40 $join->on('l_file', '=', 'f_file'); 41 }) 42 ->where('l_type', '=', '_LOC') 43 ->where('l_file', '=', $tree->id()) 44 ->groupBy(['l_to']) 45 ->select(['l_to', new Expression('COUNT(*) AS total')]) 46 ->pluck('total', 'l_to') 47 ->map(static fn ($n) => (int) $n) 48 ->all(); 49?> 50 51<table 52 class="table table-bordered table-sm wt-table-location datatables d-none" 53 <?= view('lists/datatables-attributes') ?> 54 data-columns="<?= e(json_encode([ 55 ['type' => 'html'], 56 ['visible' => array_sum($count_individuals) > 0], 57 ['visible' => array_sum($count_families) > 0], 58 ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false], 59 ], JSON_THROW_ON_ERROR)) ?>" 60> 61 <caption class="visually-hidden"> 62 <?= $caption ?? I18N::translate('Locations') ?> 63 </caption> 64 65 <thead> 66 <tr> 67 <th><?= I18N::translate('Location') ?></th> 68 <th><?= I18N::translate('Individuals') ?></th> 69 <th><?= I18N::translate('Families') ?></th> 70 <th><?= I18N::translate('Last change') ?></th> 71 </tr> 72 </thead> 73 74 <tbody> 75 <?php foreach ($locations as $location) : ?> 76 <tr class="<?= $location->isPendingAddition() ? 'wt-new' : '' ?> <?= $location->isPendingDeletion() ? 'wt-old' : '' ?>"> 77 <!-- Location name --> 78 <td data-sort="<?= e($location->sortName()) ?>"> 79 <a href="<?= e($location->url()) ?>"> 80 <?= $location->fullName() ?> 81 </a> 82 </td> 83 84 <!-- Count of linked individuals --> 85 <td class="text-center" data-sort="<?= $count_individuals[$location->xref()] ?? 0 ?>"> 86 <?= I18N::number($count_individuals[$location->xref()] ?? 0) ?> 87 </td> 88 89 <!-- Count of linked families --> 90 <td class="text-center" data-sort="<?= $count_families[$location->xref()] ?? 0 ?>"> 91 <?= I18N::number($count_families[$location->xref()] ?? 0) ?> 92 </td> 93 94 <!-- Last change --> 95 <td data-sort="<?= $location->lastChangeTimestamp()->timestamp() ?>"> 96 <?= view('components/datetime', ['timestamp' => $location->lastChangeTimestamp()]) ?> 97 </td> 98 </tr> 99 <?php endforeach ?> 100 </tbody> 101</table> 102