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