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