xref: /webtrees/resources/views/lists/notes-table.phtml (revision b43e8d2bb2c20432b6d427f0f5d9a32679a9aa4f)
1<?php
2
3use Fisharebest\Webtrees\I18N;
4use Illuminate\Database\Capsule\Manager as DB;
5use Illuminate\Database\Query\Expression;
6use Illuminate\Database\Query\JoinClause;
7
8?>
9
10<?php
11// Count the number of linked records. These numbers include private records.
12// It is not good to bypass privacy, but many servers do not have the resources
13// to process privacy for every record in the tree
14$count_individuals = DB::table('individuals')
15    ->join('link', static function (JoinClause $join): void {
16        $join->on('l_from', '=', 'i_id');
17        $join->on('l_file', '=', 'i_file');
18    })
19    ->where('l_type', '=', 'NOTE')
20    ->where('l_file', '=', $tree->id())
21    ->groupBy(['l_to'])
22    ->select(['l_to', new Expression('COUNT(*) AS total')])
23    ->pluck('total', 'l_to')
24    ->all();
25
26$count_families = DB::table('families')
27    ->join('link', static function (JoinClause $join): void {
28        $join->on('l_from', '=', 'f_id');
29        $join->on('l_file', '=', 'f_file');
30    })
31    ->where('l_type', '=', 'NOTE')
32    ->where('l_file', '=', $tree->id())
33    ->groupBy(['l_to'])
34    ->select(['l_to', new Expression('COUNT(*) AS total')])
35    ->pluck('total', 'l_to')
36    ->all();
37
38$count_media = DB::table('media')
39    ->join('link', static function (JoinClause $join): void {
40        $join->on('l_from', '=', 'm_id');
41        $join->on('l_file', '=', 'm_file');
42    })
43    ->where('l_type', '=', 'NOTE')
44    ->where('l_file', '=', $tree->id())
45    ->groupBy(['l_to'])
46    ->select(['l_to', new Expression('COUNT(*) AS total')])
47    ->pluck('total', 'l_to')
48    ->all();
49
50$count_sources = DB::table('sources')
51    ->join('link', static function (JoinClause $join): void {
52        $join->on('l_from', '=', 's_id');
53        $join->on('l_file', '=', 's_file');
54    })
55    ->where('l_type', '=', 'NOTE')
56    ->where('l_file', '=', $tree->id())
57    ->groupBy(['l_to'])
58    ->select(['l_to', new Expression('COUNT(*) AS total')])
59    ->pluck('total', 'l_to')
60    ->all();
61?>
62
63<table
64    class="table table-bordered table-sm wt-table-note datatables d-none"
65    <?= view('lists/datatables-attributes') ?>
66    data-columns="<?= e(json_encode([
67        null,
68        ['visible' => array_sum($count_individuals) > 0],
69        ['visible' => array_sum($count_families) > 0],
70        ['visible' => array_sum($count_media) > 0],
71        ['visible' => array_sum($count_sources) > 0],
72        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
73    ])) ?>"
74>
75    <caption class="sr-only">
76        <?= $caption ?? I18N::translate('Sources') ?>
77    </caption>
78
79    <thead>
80        <tr>
81            <th><?= I18N::translate('Title') ?></th>
82            <th><?= I18N::translate('Individuals') ?></th>
83            <th><?= I18N::translate('Families') ?></th>
84            <th><?= I18N::translate('Media objects') ?></th>
85            <th><?= I18N::translate('Sources') ?></th>
86            <th><?= I18N::translate('Last change') ?></th>
87        </tr>
88    </thead>
89
90    <tbody>
91        <?php foreach ($notes as $note) : ?>
92            <tr class="<?= $note->isPendingDeletion() ? 'wt-old' : ($note->isPendingAddition() ? 'wt-new' : '') ?>">
93                <!-- Title -->
94                <td data-sort="<?= e($note->sortName()) ?>">
95                    <a href="<?= e($note->url()) ?>">
96                        <?= $note->fullName() ?>
97                    </a>
98                </td>
99
100                <!-- Count of linked individuals -->
101                <td class="text-center" data-sort="<?= $count_individuals[$note->xref()] ?? 0 ?>">
102                    <?= I18N::number($count_individuals[$note->xref()] ?? 0) ?>
103                </td>
104
105                <!-- Count of linked families -->
106                <td class="text-center" data-sort="<?= $count_families[$note->xref()] ?? 0 ?>">
107                    <?= I18N::number($count_families[$note->xref()] ?? 0) ?>
108                </td>
109
110                <!-- Count of linked media objects -->
111                <td class="text-center" data-sort="<?= $count_media[$note->xref()] ?? 0 ?>">
112                    <?= I18N::number($count_media[$note->xref()] ?? 0) ?>
113                </td>
114
115                <!-- Count of sources -->
116                <td class="text-center" data-sort="<?= $count_sources[$note->xref()] ?? 0 ?>">
117                    <?= I18N::number($count_sources[$note->xref()] ?? 0) ?>
118                </td>
119
120                <!-- Last change -->
121                <td data-sort="<?= $note->lastChangeTimestamp()->unix() ?>">
122                    <?= view('components/datetime', ['timestamp' => $note->lastChangeTimestamp()]) ?>
123                </td>
124            </tr>
125        <?php endforeach ?>
126    </tbody>
127</table>
128