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