xref: /webtrees/resources/views/lists/repositories-table.phtml (revision ac71572d8462e396ed5a307f05b29381e49f9e6e)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\I18N;
6use Fisharebest\Webtrees\Repository;
7use Fisharebest\Webtrees\Tree;
8use Illuminate\Database\Capsule\Manager as DB;
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    ->select(['l_to', new Expression('COUNT(*) AS total')])
33    ->pluck('total', 'l_to')
34    ->map(static fn ($n) => (int) $n)
35    ->all();
36?>
37
38<table
39    class="table table-bordered table-sm wt-table-repository datatables d-none"
40    <?= view('lists/datatables-attributes') ?>
41    data-columns="<?= e(json_encode([
42        ['type' => 'html'],
43        ['visible' => array_sum($count_sources) > 0],
44        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
45    ], JSON_THROW_ON_ERROR)) ?>"
46>
47    <caption class="visually-hidden">
48        <?= $caption ?? I18N::translate('Repositories') ?>
49    </caption>
50
51    <thead>
52        <tr>
53            <th><?= I18N::translate('Repository name') ?></th>
54            <th><?= I18N::translate('Sources') ?></th>
55            <th><?= I18N::translate('Last change') ?></th>
56        </tr>
57    </thead>
58
59    <tbody>
60        <?php foreach ($repositories as $repository) : ?>
61            <tr class="<?= $repository->isPendingAddition() ? 'wt-new' : '' ?> <?= $repository->isPendingDeletion() ? 'wt-old' : '' ?>">
62                <!-- Repository name -->
63                <td data-sort="<?= e($repository->sortName()) ?>">
64                    <a href="<?= e($repository->url()) ?>">
65                        <?= $repository->fullName() ?>
66                    </a>
67                </td>
68
69                <!-- Count of linked sources -->
70                <td class="text-center" data-sort="<?= $count_sources[$repository->xref()] ?? 0 ?>">
71                    <?= I18N::number($count_sources[$repository->xref()] ?? 0) ?>
72                </td>
73
74                <!-- Last change -->
75                <td data-sort="<?= $repository->lastChangeTimestamp()->timestamp() ?>">
76                    <?= view('components/datetime', ['timestamp' => $repository->lastChangeTimestamp()]) ?>
77                </td>
78            </tr>
79        <?php endforeach ?>
80    </tbody>
81</table>
82