xref: /webtrees/resources/views/lists/media-table.phtml (revision d97083fe315dad9b7d0a150d4fb5f563e57d1869)
1a69f5655SGreg Roach<?php
2d70512abSGreg Roach
3a69f5655SGreg Roachuse Fisharebest\Webtrees\I18N;
47c2c99faSGreg Roachuse Fisharebest\Webtrees\Media;
57c2c99faSGreg Roachuse Fisharebest\Webtrees\Tree;
6a69f5655SGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
7a69f5655SGreg Roachuse Illuminate\Database\Query\Expression;
8a69f5655SGreg Roachuse Illuminate\Database\Query\JoinClause;
97c2c99faSGreg Roachuse Illuminate\Support\Collection;
107c2c99faSGreg Roach
117c2c99faSGreg Roach/**
1236779af1SGreg Roach * @var Collection<int,Media> $media_objects
137c2c99faSGreg Roach * @var Tree                  $tree
147c2c99faSGreg Roach */
15d70512abSGreg Roach
16a69f5655SGreg Roach?>
17dd6b2bfcSGreg Roach
18dd6b2bfcSGreg Roach<?php
19dd6b2bfcSGreg Roach// Count the number of linked records. These numbers include private records.
20dd6b2bfcSGreg Roach// It is not good to bypass privacy, but many servers do not have the resources
21dd6b2bfcSGreg Roach// to process privacy for every record in the tree
223fa66c66SGreg Roach$count_individuals = DB::table('individuals')
230b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
243fa66c66SGreg Roach        $join->on('l_from', '=', 'i_id');
253fa66c66SGreg Roach        $join->on('l_file', '=', 'i_file');
263fa66c66SGreg Roach    })
270d214e29SRichard Cissée    ->where('l_type', '=', 'OBJE')
283fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
297f5c2944SGreg Roach    ->groupBy(['l_to'])
30a69f5655SGreg Roach    ->select(['l_to', new Expression('COUNT(*) AS total')])
313fa66c66SGreg Roach    ->pluck('total', 'l_to')
323fa66c66SGreg Roach    ->all();
333fa66c66SGreg Roach
343fa66c66SGreg Roach$count_families = DB::table('families')
350b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
363fa66c66SGreg Roach        $join->on('l_from', '=', 'f_id');
373fa66c66SGreg Roach        $join->on('l_file', '=', 'f_file');
383fa66c66SGreg Roach    })
390d214e29SRichard Cissée    ->where('l_type', '=', 'OBJE')
403fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
417f5c2944SGreg Roach    ->groupBy(['l_to'])
42a69f5655SGreg Roach    ->select(['l_to', new Expression('COUNT(*) AS total')])
433fa66c66SGreg Roach    ->pluck('total', 'l_to')
443fa66c66SGreg Roach    ->all();
453fa66c66SGreg Roach
463fa66c66SGreg Roach$count_sources = DB::table('sources')
470b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
483fa66c66SGreg Roach        $join->on('l_from', '=', 's_id');
493fa66c66SGreg Roach        $join->on('l_file', '=', 's_file');
503fa66c66SGreg Roach    })
510d214e29SRichard Cissée    ->where('l_type', '=', 'OBJE')
523fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
537f5c2944SGreg Roach    ->groupBy(['l_to'])
54a69f5655SGreg Roach    ->select(['l_to', new Expression('COUNT(*) AS total')])
553fa66c66SGreg Roach    ->pluck('total', 'l_to')
563fa66c66SGreg Roach    ->all();
57dd6b2bfcSGreg Roach?>
58dd6b2bfcSGreg Roach
59dd6b2bfcSGreg Roach<table
60b4139381SGreg Roach    class="table table-bordered table-sm wt-table-media datatables d-none"
61b4139381SGreg Roach    <?= view('lists/datatables-attributes') ?>
62dd6b2bfcSGreg Roach    data-columns="<?= e(json_encode([
63dd6b2bfcSGreg Roach        null,
64eef4add8SGreg Roach        ['type' => 'html'],
65dd6b2bfcSGreg Roach        ['visible' => array_sum($count_individuals) > 0],
66dd6b2bfcSGreg Roach        ['visible' => array_sum($count_families) > 0],
67dd6b2bfcSGreg Roach        ['visible' => array_sum($count_sources) > 0],
68dd6b2bfcSGreg Roach        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
69728c8c27SGreg Roach    ], JSON_THROW_ON_ERROR)) ?>"
70dd6b2bfcSGreg Roach>
71315eb316SGreg Roach    <caption class="visually-hidden">
72dd6b2bfcSGreg Roach        <?= $caption ?? I18N::translate('Media objects') ?>
73dd6b2bfcSGreg Roach    </caption>
74dd6b2bfcSGreg Roach
75dd6b2bfcSGreg Roach    <thead>
76dd6b2bfcSGreg Roach        <tr>
77dd6b2bfcSGreg Roach            <th><?= I18N::translate('Media') ?></th>
78dd6b2bfcSGreg Roach            <th><?= I18N::translate('Title') ?></th>
79dd6b2bfcSGreg Roach            <th><?= I18N::translate('Individuals') ?></th>
80dd6b2bfcSGreg Roach            <th><?= I18N::translate('Families') ?></th>
81dd6b2bfcSGreg Roach            <th><?= I18N::translate('Sources') ?></th>
82dd6b2bfcSGreg Roach            <th><?= I18N::translate('Last change') ?></th>
83dd6b2bfcSGreg Roach        </tr>
84dd6b2bfcSGreg Roach    </thead>
85dd6b2bfcSGreg Roach
86dd6b2bfcSGreg Roach    <tbody>
87dd6b2bfcSGreg Roach        <?php foreach ($media_objects as $media_object) : ?>
88b16bf9d4SGreg Roach            <tr class="<?= $media_object->isPendingAddition() ? 'wt-new' : '' ?> <?= $media_object->isPendingDeletion() ? 'wt-old' : '' ?>">
89dd6b2bfcSGreg Roach                <!-- Thumbnails-->
9039ca88baSGreg Roach                <td data-sort="<?= e($media_object->sortName()) ?>">
91dd6b2bfcSGreg Roach                    <?php foreach ($media_object->mediaFiles() as $media_file) : ?>
92dd6b2bfcSGreg Roach                        <?= $media_file->displayImage(100, 100, 'contain', []) ?>
93dd6b2bfcSGreg Roach                    <?php endforeach ?>
94dd6b2bfcSGreg Roach                </td>
95dd6b2bfcSGreg Roach
96dd6b2bfcSGreg Roach                <!-- Title -->
9739ca88baSGreg Roach                <td data-sort="<?= e($media_object->sortName()) ?>">
98dd6b2bfcSGreg Roach                    <a href="<?= e($media_object->url()) ?>">
9939ca88baSGreg Roach                        <?= $media_object->fullName() ?>
100dd6b2bfcSGreg Roach                    </a>
101dd6b2bfcSGreg Roach                </td>
102dd6b2bfcSGreg Roach
103dd6b2bfcSGreg Roach                <!-- Count of linked individuals -->
104242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_individuals[$media_object->xref()] ?? 0 ?>">
105c0935879SGreg Roach                    <?= I18N::number($count_individuals[$media_object->xref()] ?? 0) ?>
106dd6b2bfcSGreg Roach                </td>
107dd6b2bfcSGreg Roach
108dd6b2bfcSGreg Roach                <!-- Count of linked families -->
109242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_families[$media_object->xref()] ?? 0 ?>">
110c0935879SGreg Roach                    <?= I18N::number($count_families[$media_object->xref()] ?? 0) ?>
111dd6b2bfcSGreg Roach                </td>
112dd6b2bfcSGreg Roach
113dd6b2bfcSGreg Roach                <!-- Count of sources -->
114242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_sources[$media_object->xref()] ?? 0 ?>">
115c0935879SGreg Roach                    <?= I18N::number($count_sources[$media_object->xref()] ?? 0) ?>
116dd6b2bfcSGreg Roach                </td>
117dd6b2bfcSGreg Roach
118dd6b2bfcSGreg Roach                <!-- Last change -->
119*d97083feSGreg Roach                <td data-sort="<?= $media_object->lastChangeTimestamp()->timestamp() ?>">
1204459dc9aSGreg Roach                    <?= view('components/datetime', ['timestamp' => $media_object->lastChangeTimestamp()]) ?>
121dd6b2bfcSGreg Roach                </td>
122dd6b2bfcSGreg Roach            </tr>
123dd6b2bfcSGreg Roach        <?php endforeach ?>
124dd6b2bfcSGreg Roach    </tbody>
125dd6b2bfcSGreg Roach</table>
126