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