xref: /webtrees/resources/views/lists/notes-table.phtml (revision 30158ae76837ce51811d3e0fca2ea5852182f42e)
1<?php use Fisharebest\Webtrees\Database; ?>
2<?php use Fisharebest\Webtrees\I18N; ?>
3
4<?php
5// Count the number of linked records. These numbers include private records.
6// It is not good to bypass privacy, but many servers do not have the resources
7// to process privacy for every record in the tree
8$count_individuals = Database::prepare(
9    "SELECT l_to, COUNT(*) FROM `##individuals` JOIN `##link` ON l_from = i_id AND l_file = i_file AND l_type = 'NOTE' AND l_file = :tree_id GROUP BY l_to"
10)->execute(['tree_id' => $tree->id()])->fetchAssoc();
11$count_families    = Database::prepare(
12    "SELECT l_to, COUNT(*) FROM `##families` JOIN `##link` ON l_from = f_id AND l_file = f_file AND l_type = 'NOTE' AND l_file = :tree_id GROUP BY l_to"
13)->execute(['tree_id' => $tree->id()])->fetchAssoc();
14$count_media       = Database::prepare(
15    "SELECT l_to, COUNT(*) FROM `##media` JOIN `##link` ON l_from = m_id AND l_file = m_file AND l_type = 'NOTE' AND l_file = :tree_id GROUP BY l_to"
16)->execute(['tree_id' => $tree->id()])->fetchAssoc();
17$count_sources = Database::prepare(
18    "SELECT l_to, COUNT(*) FROM `##sources` JOIN `##link` ON l_from = s_id AND l_file = s_file AND l_type = 'NOTE' AND l_file = :tree_id GROUP BY l_to"
19)->execute(['tree_id' => $tree->id()])->fetchAssoc();
20?>
21
22<table
23    class="table table-bordered table-sm wt-table-note datatables"
24    <?= view('lists/datatables-attributes') ?>
25    data-columns="<?= e(json_encode([
26        null,
27        ['visible' => array_sum($count_individuals) > 0],
28        ['visible' => array_sum($count_families) > 0],
29        ['visible' => array_sum($count_media) > 0],
30        ['visible' => array_sum($count_sources) > 0],
31        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
32    ])) ?>"
33>
34    <caption class="sr-only">
35        <?= $caption ?? I18N::translate('Sources') ?>
36    </caption>
37
38    <thead>
39        <tr>
40            <th><?= I18N::translate('Title') ?></th>
41            <th><?= I18N::translate('Individuals') ?></th>
42            <th><?= I18N::translate('Families') ?></th>
43            <th><?= I18N::translate('Media objects') ?></th>
44            <th><?= I18N::translate('Sources') ?></th>
45            <th><?= I18N::translate('Last change') ?></th>
46        </tr>
47    </thead>
48
49    <tbody>
50        <?php foreach ($notes as $note) : ?>
51            <tr class="<?= $note->isPendingDeletion() ? 'old' : ($note->isPendingAddition() ? 'new' : '') ?>">
52                <!-- Title -->
53                <td data-sort="<?= e($note->getSortName()) ?>">
54                    <a href="<?= e($note->url()) ?>">
55                        <?= $note->getFullName() ?>
56                    </a>
57                </td>
58
59                <!-- Count of linked individuals -->
60                <td class="center" data-sort="<?= $count_individuals[$note->xref()] ?? 0 ?>">
61                    <?= I18N::number($count_individuals[$note->xref()] ?? 0) ?>
62                </td>
63
64                <!-- Count of linked families -->
65                <td class="center" data-sort="<?= $count_families[$note->xref()] ?? 0 ?>">
66                    <?= I18N::number($count_families[$note->xref()] ?? 0) ?>
67                </td>
68
69                <!-- Count of linked media objects -->
70                <td class="center" data-sort="<?= $count_media[$note->xref()] ?? 0 ?>">
71                    <?= I18N::number($count_media[$note->xref()] ?? 0) ?>
72                </td>
73
74                <!-- Count of sources -->
75                <td class="center" data-sort="<?= $count_sources[$note->xref()] ?? 0 ?>">
76                    <?= I18N::number($count_sources[$note->xref()] ?? 0) ?>
77                </td>
78
79                <!-- Last change -->
80                <td data-sort="<?= $note->lastChangeTimestamp(true) ?>">
81                    <?= $note->lastChangeTimestamp() ?>
82                </td>
83            </tr>
84        <?php endforeach ?>
85    </tbody>
86</table>
87