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