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