xref: /webtrees/resources/views/lists/notes-table.phtml (revision 8ae6e9f4162b4cb128ac973e1753d8fbf5d50623)
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', '=', 'NOTE')
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_individuals = 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', '=', 'NOTE')
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', '=', 'NOTE')
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_sources = DB::table('sources')
46    ->join('link', function (JoinClause $join): void {
47        $join->on('l_from', '=', 's_id');
48        $join->on('l_file', '=', 's_file');
49    })
50    ->where('l_type', '=', 'NOTE')
51    ->where('l_file', '=', $tree->id())
52    ->groupBy('l_to')
53    ->select(['l_to', DB::raw('COUNT(*) AS total')])
54    ->pluck('total', 'l_to')
55    ->all();
56?>
57
58<table
59    class="table table-bordered table-sm wt-table-note datatables"
60    <?= view('lists/datatables-attributes') ?>
61    data-columns="<?= e(json_encode([
62        null,
63        ['visible' => array_sum($count_individuals) > 0],
64        ['visible' => array_sum($count_families) > 0],
65        ['visible' => array_sum($count_media) > 0],
66        ['visible' => array_sum($count_sources) > 0],
67        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
68    ])) ?>"
69>
70    <caption class="sr-only">
71        <?= $caption ?? I18N::translate('Sources') ?>
72    </caption>
73
74    <thead>
75        <tr>
76            <th><?= I18N::translate('Title') ?></th>
77            <th><?= I18N::translate('Individuals') ?></th>
78            <th><?= I18N::translate('Families') ?></th>
79            <th><?= I18N::translate('Media objects') ?></th>
80            <th><?= I18N::translate('Sources') ?></th>
81            <th><?= I18N::translate('Last change') ?></th>
82        </tr>
83    </thead>
84
85    <tbody>
86        <?php foreach ($notes as $note) : ?>
87            <tr class="<?= $note->isPendingDeletion() ? 'old' : ($note->isPendingAddition() ? 'new' : '') ?>">
88                <!-- Title -->
89                <td data-sort="<?= e($note->getSortName()) ?>">
90                    <a href="<?= e($note->url()) ?>">
91                        <?= $note->getFullName() ?>
92                    </a>
93                </td>
94
95                <!-- Count of linked individuals -->
96                <td class="center" data-sort="<?= $count_individuals[$note->xref()] ?? 0 ?>">
97                    <?= I18N::number($count_individuals[$note->xref()] ?? 0) ?>
98                </td>
99
100                <!-- Count of linked families -->
101                <td class="center" data-sort="<?= $count_families[$note->xref()] ?? 0 ?>">
102                    <?= I18N::number($count_families[$note->xref()] ?? 0) ?>
103                </td>
104
105                <!-- Count of linked media objects -->
106                <td class="center" data-sort="<?= $count_media[$note->xref()] ?? 0 ?>">
107                    <?= I18N::number($count_media[$note->xref()] ?? 0) ?>
108                </td>
109
110                <!-- Count of sources -->
111                <td class="center" data-sort="<?= $count_sources[$note->xref()] ?? 0 ?>">
112                    <?= I18N::number($count_sources[$note->xref()] ?? 0) ?>
113                </td>
114
115                <!-- Last change -->
116                <td data-sort="<?= $note->lastChangeTimestamp(true) ?>">
117                    <?= $note->lastChangeTimestamp() ?>
118                </td>
119            </tr>
120        <?php endforeach ?>
121    </tbody>
122</table>
123