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