xref: /webtrees/resources/views/lists/repositories-table.phtml (revision 00b1984e374faddab4698e73088f0c964e529b65)
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-columns="<?= e(json_encode([
31        null,
32        ['visible' => array_sum($count_sources) > 0],
33        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
34    ])) ?>"
35>
36    <caption class="sr-only">
37        <?= $caption ?? I18N::translate('Repositories') ?>
38    </caption>
39
40    <thead>
41        <tr>
42            <th><?= I18N::translate('Repository name') ?></th>
43            <th><?= I18N::translate('Sources') ?></th>
44            <th><?= I18N::translate('Last change') ?></th>
45        </tr>
46    </thead>
47
48    <tbody>
49        <?php foreach ($repositories as $repository) : ?>
50            <tr class="<?= $repository->isPendingDeletion() ? 'wt-old' : ($repository->isPendingAddition() ? 'wt-new' : '') ?>">
51                <!-- Repository name -->
52                <td data-sort="<?= e($repository->sortName()) ?>">
53                    <a href="<?= e($repository->url()) ?>">
54                        <?= $repository->fullName() ?>
55                    </a>
56                </td>
57
58                <!-- Count of linked sources -->
59                <td class="text-center" data-sort="<?= $count_sources[$repository->xref()] ?? 0 ?>">
60                    <?= I18N::number($count_sources[$repository->xref()] ?? 0) ?>
61                </td>
62
63                <!-- Last change -->
64                <td data-sort="<?= $repository->lastChangeTimestamp()->unix() ?>">
65                    <?= view('components/datetime', ['timestamp' => $repository->lastChangeTimestamp()]) ?>
66                </td>
67            </tr>
68        <?php endforeach ?>
69    </tbody>
70</table>
71