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