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