xref: /webtrees/resources/views/lists/media-table.phtml (revision 6f4ec3cadc983f0a7294108c634bef48846b4311)
1a69f5655SGreg Roach<?php
2d70512abSGreg Roach
310e06497SGreg Roachdeclare(strict_types=1);
410e06497SGreg Roach
5*6f4ec3caSGreg Roachuse Fisharebest\Webtrees\DB;
6a69f5655SGreg Roachuse Fisharebest\Webtrees\I18N;
77c2c99faSGreg Roachuse Fisharebest\Webtrees\Media;
87c2c99faSGreg Roachuse Fisharebest\Webtrees\Tree;
9a69f5655SGreg Roachuse Illuminate\Database\Query\Expression;
10a69f5655SGreg Roachuse Illuminate\Database\Query\JoinClause;
117c2c99faSGreg Roachuse Illuminate\Support\Collection;
127c2c99faSGreg Roach
137c2c99faSGreg Roach/**
1436779af1SGreg Roach * @var Collection<int,Media> $media_objects
157c2c99faSGreg Roach * @var Tree                  $tree
167c2c99faSGreg Roach */
17d70512abSGreg Roach
18a69f5655SGreg Roach?>
19dd6b2bfcSGreg Roach
20dd6b2bfcSGreg Roach<?php
21dd6b2bfcSGreg Roach// Count the number of linked records. These numbers include private records.
22dd6b2bfcSGreg Roach// It is not good to bypass privacy, but many servers do not have the resources
23dd6b2bfcSGreg Roach// to process privacy for every record in the tree
243fa66c66SGreg Roach$count_individuals = DB::table('individuals')
250b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
263fa66c66SGreg Roach        $join->on('l_from', '=', 'i_id');
273fa66c66SGreg Roach        $join->on('l_file', '=', 'i_file');
283fa66c66SGreg Roach    })
290d214e29SRichard Cissée    ->where('l_type', '=', 'OBJE')
303fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
317f5c2944SGreg Roach    ->groupBy(['l_to'])
32059898c9SGreg Roach    ->pluck(new Expression('COUNT(*) AS total'), 'l_to')
33a962cdb5SGreg Roach    ->map(static fn ($n) => (int) $n)
343fa66c66SGreg Roach    ->all();
353fa66c66SGreg Roach
363fa66c66SGreg Roach$count_families = DB::table('families')
370b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
383fa66c66SGreg Roach        $join->on('l_from', '=', 'f_id');
393fa66c66SGreg Roach        $join->on('l_file', '=', 'f_file');
403fa66c66SGreg Roach    })
410d214e29SRichard Cissée    ->where('l_type', '=', 'OBJE')
423fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
437f5c2944SGreg Roach    ->groupBy(['l_to'])
44059898c9SGreg Roach    ->pluck(new Expression('COUNT(*) AS total'), 'l_to')
45a962cdb5SGreg Roach    ->map(static fn ($n) => (int) $n)
463fa66c66SGreg Roach    ->all();
473fa66c66SGreg Roach
483fa66c66SGreg Roach$count_sources = DB::table('sources')
490b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
503fa66c66SGreg Roach        $join->on('l_from', '=', 's_id');
513fa66c66SGreg Roach        $join->on('l_file', '=', 's_file');
523fa66c66SGreg Roach    })
530d214e29SRichard Cissée    ->where('l_type', '=', 'OBJE')
543fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
557f5c2944SGreg Roach    ->groupBy(['l_to'])
56059898c9SGreg Roach    ->pluck(new Expression('COUNT(*) AS total'), 'l_to')
57a962cdb5SGreg Roach    ->map(static fn ($n) => (int) $n)
583fa66c66SGreg Roach    ->all();
59dd6b2bfcSGreg Roach?>
60dd6b2bfcSGreg Roach
61dd6b2bfcSGreg Roach<table
62b4139381SGreg Roach    class="table table-bordered table-sm wt-table-media datatables d-none"
63b4139381SGreg Roach    <?= view('lists/datatables-attributes') ?>
64dd6b2bfcSGreg Roach    data-columns="<?= e(json_encode([
65dd6b2bfcSGreg Roach        null,
66eef4add8SGreg Roach        ['type' => 'html'],
67dd6b2bfcSGreg Roach        ['visible' => array_sum($count_individuals) > 0],
68dd6b2bfcSGreg Roach        ['visible' => array_sum($count_families) > 0],
69dd6b2bfcSGreg Roach        ['visible' => array_sum($count_sources) > 0],
70dd6b2bfcSGreg Roach        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
71728c8c27SGreg Roach    ], JSON_THROW_ON_ERROR)) ?>"
72dd6b2bfcSGreg Roach>
73315eb316SGreg Roach    <caption class="visually-hidden">
74dd6b2bfcSGreg Roach        <?= $caption ?? I18N::translate('Media objects') ?>
75dd6b2bfcSGreg Roach    </caption>
76dd6b2bfcSGreg Roach
77dd6b2bfcSGreg Roach    <thead>
78dd6b2bfcSGreg Roach        <tr>
79dd6b2bfcSGreg Roach            <th><?= I18N::translate('Media') ?></th>
80dd6b2bfcSGreg Roach            <th><?= I18N::translate('Title') ?></th>
81dd6b2bfcSGreg Roach            <th><?= I18N::translate('Individuals') ?></th>
82dd6b2bfcSGreg Roach            <th><?= I18N::translate('Families') ?></th>
83dd6b2bfcSGreg Roach            <th><?= I18N::translate('Sources') ?></th>
84dd6b2bfcSGreg Roach            <th><?= I18N::translate('Last change') ?></th>
85dd6b2bfcSGreg Roach        </tr>
86dd6b2bfcSGreg Roach    </thead>
87dd6b2bfcSGreg Roach
88dd6b2bfcSGreg Roach    <tbody>
89dd6b2bfcSGreg Roach        <?php foreach ($media_objects as $media_object) : ?>
90b16bf9d4SGreg Roach            <tr class="<?= $media_object->isPendingAddition() ? 'wt-new' : '' ?> <?= $media_object->isPendingDeletion() ? 'wt-old' : '' ?>">
91dd6b2bfcSGreg Roach                <!-- Thumbnails-->
9239ca88baSGreg Roach                <td data-sort="<?= e($media_object->sortName()) ?>">
93dd6b2bfcSGreg Roach                    <?php foreach ($media_object->mediaFiles() as $media_file) : ?>
94dd6b2bfcSGreg Roach                        <?= $media_file->displayImage(100, 100, 'contain', []) ?>
95dd6b2bfcSGreg Roach                    <?php endforeach ?>
96dd6b2bfcSGreg Roach                </td>
97dd6b2bfcSGreg Roach
98dd6b2bfcSGreg Roach                <!-- Title -->
9939ca88baSGreg Roach                <td data-sort="<?= e($media_object->sortName()) ?>">
100dd6b2bfcSGreg Roach                    <a href="<?= e($media_object->url()) ?>">
10139ca88baSGreg Roach                        <?= $media_object->fullName() ?>
102dd6b2bfcSGreg Roach                    </a>
103dd6b2bfcSGreg Roach                </td>
104dd6b2bfcSGreg Roach
105dd6b2bfcSGreg Roach                <!-- Count of linked individuals -->
106242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_individuals[$media_object->xref()] ?? 0 ?>">
107c0935879SGreg Roach                    <?= I18N::number($count_individuals[$media_object->xref()] ?? 0) ?>
108dd6b2bfcSGreg Roach                </td>
109dd6b2bfcSGreg Roach
110dd6b2bfcSGreg Roach                <!-- Count of linked families -->
111242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_families[$media_object->xref()] ?? 0 ?>">
112c0935879SGreg Roach                    <?= I18N::number($count_families[$media_object->xref()] ?? 0) ?>
113dd6b2bfcSGreg Roach                </td>
114dd6b2bfcSGreg Roach
115dd6b2bfcSGreg Roach                <!-- Count of sources -->
116242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_sources[$media_object->xref()] ?? 0 ?>">
117c0935879SGreg Roach                    <?= I18N::number($count_sources[$media_object->xref()] ?? 0) ?>
118dd6b2bfcSGreg Roach                </td>
119dd6b2bfcSGreg Roach
120dd6b2bfcSGreg Roach                <!-- Last change -->
121d97083feSGreg Roach                <td data-sort="<?= $media_object->lastChangeTimestamp()->timestamp() ?>">
1224459dc9aSGreg Roach                    <?= view('components/datetime', ['timestamp' => $media_object->lastChangeTimestamp()]) ?>
123dd6b2bfcSGreg Roach                </td>
124dd6b2bfcSGreg Roach            </tr>
125dd6b2bfcSGreg Roach        <?php endforeach ?>
126dd6b2bfcSGreg Roach    </tbody>
127dd6b2bfcSGreg Roach</table>
128