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