xref: /webtrees/resources/views/lists/sources-table.phtml (revision e759aebbec359cf7148227a725fea81907659ae8)
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_individuals = DB::table('individuals')
10    ->join('link', function (JoinClause $join): void {
11        $join->on('l_from', '=', 'i_id');
12        $join->on('l_file', '=', 'i_file');
13    })
14    ->where('l_type', '=', 'SOUR')
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$count_families = DB::table('families')
22    ->join('link', function (JoinClause $join): void {
23        $join->on('l_from', '=', 'f_id');
24        $join->on('l_file', '=', 'f_file');
25    })
26    ->where('l_type', '=', 'SOUR')
27    ->where('l_file', '=', $tree->id())
28    ->groupBy('l_to')
29    ->select(['l_to', DB::raw('COUNT(*) AS total')])
30    ->pluck('total', 'l_to')
31    ->all();
32
33$count_media = DB::table('media')
34    ->join('link', function (JoinClause $join): void {
35        $join->on('l_from', '=', 'm_id');
36        $join->on('l_file', '=', 'm_file');
37    })
38    ->where('l_type', '=', 'SOUR')
39    ->where('l_file', '=', $tree->id())
40    ->groupBy('l_to')
41    ->select(['l_to', DB::raw('COUNT(*) AS total')])
42    ->pluck('total', 'l_to')
43    ->all();
44
45$count_notes = DB::table('other')
46    ->join('link', function (JoinClause $join): void {
47        $join->on('l_from', '=', 'o_id');
48        $join->on('l_file', '=', 'o_file');
49    })
50    ->where('o_type', '=', 'NOTE')
51    ->where('l_type', '=', 'SOUR')
52    ->where('l_file', '=', $tree->id())
53    ->groupBy('l_to')
54    ->select(['l_to', DB::raw('COUNT(*) AS total')])
55    ->pluck('total', 'l_to')
56    ->all();
57?>
58
59<table
60    class="table table-bordered table-sm wt-table-source datatables d-none"
61    <?= view('lists/datatables-attributes') ?>
62    data-columns="<?= e(json_encode([
63        null,
64        null,
65        ['visible' => array_sum($count_individuals) > 0],
66        ['visible' => array_sum($count_families) > 0],
67        ['visible' => array_sum($count_media) > 0],
68        ['visible' => array_sum($count_notes) > 0],
69        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
70    ])) ?>"
71>
72    <caption class="sr-only">
73        <?= $caption ?? I18N::translate('Sources') ?>
74    </caption>
75
76    <thead>
77        <tr>
78            <th><?= I18N::translate('Title') ?></th>
79            <th><?= I18N::translate('Author') ?></th>
80            <th><?= I18N::translate('Individuals') ?></th>
81            <th><?= I18N::translate('Families') ?></th>
82            <th><?= I18N::translate('Media objects') ?></th>
83            <th><?= I18N::translate('Shared notes') ?></th>
84            <th><?= I18N::translate('Last change') ?></th>
85        </tr>
86    </thead>
87
88    <tbody>
89        <?php foreach ($sources as $source) : ?>
90            <tr class="<?= $source->isPendingDeletion() ? 'old' : ($source->isPendingAddition() ? 'new' : '') ?>">
91                <!-- Title -->
92                <td data-sort="<?= e($source->getSortName()) ?>">
93                    <a href="<?= e($source->url()) ?>">
94                        <?= $source->getFullName() ?>
95                    </a>
96                </td>
97
98                <!-- Author -->
99                <td>
100                    <?= e($source->getFirstFact('AUTH') ? $source->getFirstFact('AUTH')->value() : '') ?>
101                </td>
102
103                <!-- Count of linked individuals -->
104                <td class="text-center" data-sort="<?= $count_individuals[$source->xref()] ?? 0 ?>">
105                    <?= I18N::number($count_individuals[$source->xref()] ?? 0) ?>
106                </td>
107
108                <!-- Count of linked families -->
109                <td class="text-center" data-sort="<?= $count_families[$source->xref()] ?? 0 ?>">
110                    <?= I18N::number($count_families[$source->xref()] ?? 0) ?>
111                </td>
112
113                <!-- Count of linked media objects -->
114                <td class="text-center" data-sort="<?= $count_media[$source->xref()] ?? 0 ?>">
115                    <?= I18N::number($count_media[$source->xref()] ?? 0) ?>
116                </td>
117
118                <!-- Count of linked notes -->
119                <td class="text-center" data-sort="<?= $count_notes[$source->xref()] ?? 0 ?>">
120                    <?= I18N::number($count_notes[$source->xref()] ?? 0) ?>
121                </td>
122
123                <!-- Last change -->
124                <td data-sort="<?= $source->lastChangeTimestamp(true) ?>">
125                    <?= $source->lastChangeTimestamp() ?>
126                </td>
127            </tr>
128        <?php endforeach ?>
129    </tbody>
130</table>
131