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