xref: /webtrees/resources/views/lists/notes-table.phtml (revision 9af6b024736711ef85eba12979344b0241b8b348)
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_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', '=', '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-auto-width="false"
62    data-columns="<?= e(json_encode([
63        null,
64        ['visible' => array_sum($count_individuals) > 0],
65        ['visible' => array_sum($count_families) > 0],
66        ['visible' => array_sum($count_media) > 0],
67        ['visible' => array_sum($count_sources) > 0],
68        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
69    ])) ?>"
70>
71    <caption class="sr-only">
72        <?= $caption ?? I18N::translate('Sources') ?>
73    </caption>
74
75    <thead>
76        <tr>
77            <th><?= I18N::translate('Title') ?></th>
78            <th><?= I18N::translate('Individuals') ?></th>
79            <th><?= I18N::translate('Families') ?></th>
80            <th><?= I18N::translate('Media objects') ?></th>
81            <th><?= I18N::translate('Sources') ?></th>
82            <th><?= I18N::translate('Last change') ?></th>
83        </tr>
84    </thead>
85
86    <tbody>
87        <?php foreach ($notes as $note) : ?>
88            <tr class="<?= $note->isPendingDeletion() ? 'old' : ($note->isPendingAddition() ? 'new' : '') ?>">
89                <!-- Title -->
90                <td data-sort="<?= e($note->sortName()) ?>">
91                    <a href="<?= e($note->url()) ?>">
92                        <?= $note->fullName() ?>
93                    </a>
94                </td>
95
96                <!-- Count of linked individuals -->
97                <td class="text-center" data-sort="<?= $count_individuals[$note->xref()] ?? 0 ?>">
98                    <?= I18N::number($count_individuals[$note->xref()] ?? 0) ?>
99                </td>
100
101                <!-- Count of linked families -->
102                <td class="text-center" data-sort="<?= $count_families[$note->xref()] ?? 0 ?>">
103                    <?= I18N::number($count_families[$note->xref()] ?? 0) ?>
104                </td>
105
106                <!-- Count of linked media objects -->
107                <td class="text-center" data-sort="<?= $count_media[$note->xref()] ?? 0 ?>">
108                    <?= I18N::number($count_media[$note->xref()] ?? 0) ?>
109                </td>
110
111                <!-- Count of sources -->
112                <td class="text-center" data-sort="<?= $count_sources[$note->xref()] ?? 0 ?>">
113                    <?= I18N::number($count_sources[$note->xref()] ?? 0) ?>
114                </td>
115
116                <!-- Last change -->
117                <td data-sort="<?= $note->lastChangeTimestamp()->unix() ?>">
118                    <?= view('components/datetime', ['timestamp' => $note->lastChangeTimestamp()]) ?>
119                </td>
120            </tr>
121        <?php endforeach ?>
122    </tbody>
123</table>
124