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