xref: /webtrees/resources/views/lists/media-table.phtml (revision 37f4d1f0a7a5610284a8bb3182a07ec4441c9fc7)
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_sources = DB::table('sources')
39    ->join('link', static function (JoinClause $join): void {
40        $join->on('l_from', '=', 's_id');
41        $join->on('l_file', '=', 's_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
51<table
52    class="table table-bordered table-sm wt-table-media datatables d-none"
53    <?= view('lists/datatables-attributes') ?>
54    data-columns="<?= e(json_encode([
55        null,
56        null,
57        ['visible' => array_sum($count_individuals) > 0],
58        ['visible' => array_sum($count_families) > 0],
59        ['visible' => array_sum($count_sources) > 0],
60        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
61    ])) ?>"
62>
63    <caption class="sr-only">
64        <?= $caption ?? I18N::translate('Media objects') ?>
65    </caption>
66
67    <thead>
68        <tr>
69            <th><?= I18N::translate('Media') ?></th>
70            <th><?= I18N::translate('Title') ?></th>
71            <th><?= I18N::translate('Individuals') ?></th>
72            <th><?= I18N::translate('Families') ?></th>
73            <th><?= I18N::translate('Sources') ?></th>
74            <th><?= I18N::translate('Last change') ?></th>
75        </tr>
76    </thead>
77
78    <tbody>
79        <?php foreach ($media_objects as $media_object) : ?>
80            <tr class="<?= $media_object->isPendingDeletion() ? 'wt-old' : ($media_object->isPendingAddition() ? 'wt-new' : '') ?>">
81                <!-- Thumbnails-->
82                <td data-sort="<?= e($media_object->sortName()) ?>">
83                    <?php foreach ($media_object->mediaFiles() as $media_file) : ?>
84                        <?= $media_file->displayImage(100, 100, 'contain', []) ?>
85                    <?php endforeach ?>
86                </td>
87
88                <!-- Title -->
89                <td data-sort="<?= e($media_object->sortName()) ?>">
90                    <a href="<?= e($media_object->url()) ?>">
91                        <?= $media_object->fullName() ?>
92                    </a>
93                </td>
94
95                <!-- Count of linked individuals -->
96                <td class="text-center" data-sort="<?= $count_individuals[$media_object->xref()] ?? 0 ?>">
97                    <?= I18N::number($count_individuals[$media_object->xref()] ?? 0) ?>
98                </td>
99
100                <!-- Count of linked families -->
101                <td class="text-center" data-sort="<?= $count_families[$media_object->xref()] ?? 0 ?>">
102                    <?= I18N::number($count_families[$media_object->xref()] ?? 0) ?>
103                </td>
104
105                <!-- Count of sources -->
106                <td class="text-center" data-sort="<?= $count_sources[$media_object->xref()] ?? 0 ?>">
107                    <?= I18N::number($count_sources[$media_object->xref()] ?? 0) ?>
108                </td>
109
110                <!-- Last change -->
111                <td data-sort="<?= $media_object->lastChangeTimestamp()->unix() ?>">
112                    <?= view('components/datetime', ['timestamp' => $media_object->lastChangeTimestamp()]) ?>
113                </td>
114            </tr>
115        <?php endforeach ?>
116    </tbody>
117</table>
118