xref: /webtrees/resources/views/lists/repositories-table.phtml (revision 36de22acf6348b1059dac63e3cd19589574906ac)
1<?php
2
3use Fisharebest\Webtrees\I18N;
4use Fisharebest\Webtrees\Repository;
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<Repository> $repositories
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_sources = DB::table('sources')
23    ->join('link', static function (JoinClause $join): void {
24        $join->on('l_from', '=', 's_id');
25        $join->on('l_file', '=', 's_file');
26    })
27    ->where('l_type', '=', 'REPO')
28    ->where('l_file', '=', $tree->id())
29    ->groupBy(['l_to'])
30    ->select(['l_to', new Expression('COUNT(*) AS total')])
31    ->pluck('total', 'l_to')
32    ->all();
33?>
34
35<table
36    class="table table-bordered table-sm wt-table-repository datatables d-none"
37    <?= view('lists/datatables-attributes') ?>
38    data-columns="<?= e(json_encode([
39        null,
40        ['visible' => array_sum($count_sources) > 0],
41        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
42    ])) ?>"
43>
44    <caption class="sr-only">
45        <?= $caption ?? I18N::translate('Repositories') ?>
46    </caption>
47
48    <thead>
49        <tr>
50            <th><?= I18N::translate('Repository name') ?></th>
51            <th><?= I18N::translate('Sources') ?></th>
52            <th><?= I18N::translate('Last change') ?></th>
53        </tr>
54    </thead>
55
56    <tbody>
57        <?php foreach ($repositories as $repository) : ?>
58            <tr class="<?= $repository->isPendingAddition() ? 'wt-new' : '' ?> <?= $repository->isPendingDeletion() ? 'wt-old' : '' ?>">
59                <!-- Repository name -->
60                <td data-sort="<?= e($repository->sortName()) ?>">
61                    <a href="<?= e($repository->url()) ?>">
62                        <?= $repository->fullName() ?>
63                    </a>
64                </td>
65
66                <!-- Count of linked sources -->
67                <td class="text-center" data-sort="<?= $count_sources[$repository->xref()] ?? 0 ?>">
68                    <?= I18N::number($count_sources[$repository->xref()] ?? 0) ?>
69                </td>
70
71                <!-- Last change -->
72                <td data-sort="<?= $repository->lastChangeTimestamp()->unix() ?>">
73                    <?= view('components/datetime', ['timestamp' => $repository->lastChangeTimestamp()]) ?>
74                </td>
75            </tr>
76        <?php endforeach ?>
77    </tbody>
78</table>
79