xref: /webtrees/resources/views/lists/media-table.phtml (revision c09358794665832df009408551d8543ccb6e3783)
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_sources     = Database::prepare(
15    "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"
16)->execute(['tree_id' => $tree->id()])->fetchAssoc();
17?>
18
19<table
20    class="table table-bordered table-sm wt-table-media datatables"
21    data-columns="<?= e(json_encode([
22        null,
23        null,
24        ['visible' => array_sum($count_individuals) > 0],
25        ['visible' => array_sum($count_families) > 0],
26        ['visible' => array_sum($count_sources) > 0],
27        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
28    ])) ?>"
29    data-state-save="true"
30>
31    <caption class="sr-only">
32        <?= $caption ?? I18N::translate('Media objects') ?>
33    </caption>
34
35    <thead>
36        <tr>
37            <th><?= I18N::translate('Media') ?></th>
38            <th><?= I18N::translate('Title') ?></th>
39            <th><?= I18N::translate('Individuals') ?></th>
40            <th><?= I18N::translate('Families') ?></th>
41            <th><?= I18N::translate('Sources') ?></th>
42            <th><?= I18N::translate('Last change') ?></th>
43        </tr>
44    </thead>
45
46    <tbody>
47        <?php foreach ($media_objects as $media_object) : ?>
48            <tr class="<?= $media_object->isPendingDeletion() ? 'old' : ($media_object->isPendingAddition() ? 'new' : '') ?>">
49                <!-- Thumbnails-->
50                <td data-sort="<?= e($media_object->getSortName()) ?>">
51                    <?php foreach ($media_object->mediaFiles() as $media_file) : ?>
52                        <?= $media_file->displayImage(100, 100, 'contain', []) ?>
53                    <?php endforeach ?>
54                </td>
55
56                <!-- Title -->
57                <td data-sort="<?= e($media_object->getSortName()) ?>">
58                    <a href="<?= e($media_object->url()) ?>">
59                        <?= $media_object->getFullName() ?>
60                    </a>
61                </td>
62
63                <!-- Count of linked individuals -->
64                <td class="center" data-sort="<?= $count_individuals[$media_object->xref()] ?? 0 ?>">
65                    <?= I18N::number($count_individuals[$media_object->xref()] ?? 0) ?>
66                </td>
67
68                <!-- Count of linked families -->
69                <td class="center" data-sort="<?= $count_families[$media_object->xref()] ?? 0 ?>">
70                    <?= I18N::number($count_families[$media_object->xref()] ?? 0) ?>
71                </td>
72
73                <!-- Count of sources -->
74                <td class="center" data-sort="<?= $count_sources[$media_object->xref()] ?? 0 ?>">
75                    <?= I18N::number($count_sources[$media_object->xref()] ?? 0) ?>
76                </td>
77
78                <!-- Last change -->
79                <td data-sort="<?= $media_object->lastChangeTimestamp(true) ?>">
80                    <?= $media_object->lastChangeTimestamp() ?>
81                </td>
82            </tr>
83        <?php endforeach ?>
84    </tbody>
85</table>
86