xref: /webtrees/resources/views/lists/submitters-table.phtml (revision ef475b14d08542378dc3f165515f9182552984ef)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\I18N;
6use Fisharebest\Webtrees\Submitter;
7use Fisharebest\Webtrees\Tree;
8use Illuminate\Database\Capsule\Manager as DB;
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    ->select(['l_to', new Expression('COUNT(*) AS total')])
36    ->pluck('total', 'l_to')
37    ->map(static fn (string $n) => (int) $n)
38    ->all();
39
40$count_families = DB::table('families')
41    ->join('link', static function (JoinClause $join): void {
42        $join->on('l_from', '=', 'f_id');
43        $join->on('l_file', '=', 'f_file');
44    })
45    ->where('l_type', '=', Submitter::RECORD_TYPE)
46    ->where('l_file', '=', $tree->id())
47    ->groupBy(['l_to'])
48    ->select(['l_to', new Expression('COUNT(*) AS total')])
49    ->pluck('total', 'l_to')
50    ->map(static fn (string $n) => (int) $n)
51    ->all();
52?>
53
54<table
55    class="table table-bordered table-sm wt-table-submitter datatables d-none"
56    <?= view('lists/datatables-attributes') ?>
57    data-columns="<?= e(json_encode([
58        ['type' => 'html'],
59        ['visible' => array_sum($count_individuals) > 0],
60        ['visible' => array_sum($count_families) > 0],
61        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
62    ], JSON_THROW_ON_ERROR)) ?>"
63    data-searchable="true"
64>
65    <caption class="visually-hidden">
66        <?= $caption ?? I18N::translate('Submitters') ?>
67    </caption>
68
69    <thead>
70        <tr>
71            <th><?= I18N::translate('Submitter name') ?></th>
72            <th><?= I18N::translate('Individuals') ?></th>
73            <th><?= I18N::translate('Families') ?></th>
74            <th><?= I18N::translate('Last change') ?></th>
75        </tr>
76    </thead>
77
78    <tbody>
79        <?php foreach ($submitters as $submitter) : ?>
80            <tr class="<?= $submitter->isPendingAddition() ? 'wt-new' : '' ?> <?= $submitter->isPendingDeletion() ? 'wt-old' : '' ?>">
81                <td data-sort="<?= e($submitter->sortName()) ?>">
82                    <a href="<?= e($submitter->url()) ?>">
83                        <?= $submitter->fullName() ?>
84                    </a>
85                </td>
86
87                <td class="text-center" data-sort="<?= $count_individuals[$submitter->xref()] ?? 0 ?>">
88                    <?= I18N::number($count_individuals[$submitter->xref()] ?? 0) ?>
89                </td>
90
91                <td class="text-center" data-sort="<?= $count_families[$submitter->xref()] ?? 0 ?>">
92                    <?= I18N::number($count_families[$submitter->xref()] ?? 0) ?>
93                </td>
94
95                <td data-sort="<?= $submitter->lastChangeTimestamp()->timestamp() ?>">
96                    <?= view('components/datetime', ['timestamp' => $submitter->lastChangeTimestamp()]) ?>
97                </td>
98            </tr>
99        <?php endforeach ?>
100    </tbody>
101</table>
102