xref: /webtrees/resources/views/lists/sources-table.phtml (revision dc124885db241fd8521088b8689a0a0d42b43764)
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 = 'SOUR' AND l_file = :tree_id GROUP BY l_to"
10)->execute(['tree_id' => $tree->getTreeId()])->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 = 'SOUR' AND l_file = :tree_id GROUP BY l_to"
13)->execute(['tree_id' => $tree->getTreeId()])->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 = 'SOUR' AND l_file = :tree_id GROUP BY l_to"
16)->execute(['tree_id' => $tree->getTreeId()])->fetchAssoc();
17$count_notes       = Database::prepare(
18    "SELECT l_to, COUNT(*) FROM `##other` JOIN `##link` ON l_from = o_id AND l_file = o_file AND o_type = 'NOTE' AND l_type = 'SOUR' AND l_file = :tree_id GROUP BY l_to"
19)->execute(['tree_id' => $tree->getTreeId()])->fetchAssoc();
20?>
21
22<table
23    class="table table-bordered table-sm wt-table-source datatables d-none"
24    <?= view('lists/datatables-attributes') ?>
25    data-columns="<?= e(json_encode([
26        null,
27        null,
28        ['visible' => array_sum($count_individuals) > 0],
29        ['visible' => array_sum($count_families) > 0],
30        ['visible' => array_sum($count_media) > 0],
31        ['visible' => array_sum($count_notes) > 0],
32        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
33    ])) ?>"
34>
35    <caption class="sr-only">
36        <?= $caption ?? I18N::translate('Sources') ?>
37    </caption>
38
39    <thead>
40        <tr>
41            <th><?= I18N::translate('Title') ?></th>
42            <th><?= I18N::translate('Author') ?></th>
43            <th><?= I18N::translate('Individuals') ?></th>
44            <th><?= I18N::translate('Families') ?></th>
45            <th><?= I18N::translate('Media objects') ?></th>
46            <th><?= I18N::translate('Shared notes') ?></th>
47            <th><?= I18N::translate('Last change') ?></th>
48        </tr>
49    </thead>
50
51    <tbody>
52        <?php foreach ($sources as $source) : ?>
53            <tr class="<?= $source->isPendingDeletion() ? 'old' : ($source->isPendingAddition() ? 'new' : '') ?>">
54                <!-- Title -->
55                <td data-sort="<?= e($source->getSortName()) ?>">
56                    <a href="<?= e($source->url()) ?>">
57                        <?= $source->getFullName() ?>
58                    </a>
59                </td>
60
61                <!-- Author -->
62                <td>
63                    <?= e($source->getFirstFact('AUTH') ? $source->getFirstFact('AUTH')->value() : '') ?>
64                </td>
65
66                <!-- Count of linked individuals -->
67                <td class="center" data-sort="<?= $count_individuals[$source->getXref()] ?? 0 ?>">
68                    <?= I18N::number($count_individuals[$source->getXref()] ?? 0) ?>
69                </td>
70
71                <!-- Count of linked families -->
72                <td class="center" data-sort="<?= $count_families[$source->getXref()] ?? 0 ?>">
73                    <?= I18N::number($count_families[$source->getXref()] ?? 0) ?>
74                </td>
75
76                <!-- Count of linked media objects -->
77                <td class="center" data-sort="<?= $count_media[$source->getXref()] ?? 0 ?>">
78                    <?= I18N::number($count_media[$source->getXref()] ?? 0) ?>
79                </td>
80
81                <!-- Count of linked notes -->
82                <td class="center" data-sort="<?= $count_notes[$source->getXref()] ?? 0 ?>">
83                    <?= I18N::number($count_notes[$source->getXref()] ?? 0) ?>
84                </td>
85
86                <!-- Last change -->
87                <td data-sort="<?= $source->lastChangeTimestamp(true) ?>">
88                    <?= $source->lastChangeTimestamp() ?>
89                </td>
90            </tr>
91        <?php endforeach ?>
92    </tbody>
93</table>
94