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