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