1<?php 2 3declare(strict_types=1); 4 5use Fisharebest\Webtrees\I18N; 6use Fisharebest\Webtrees\Media; 7use Fisharebest\Webtrees\Tree; 8use Illuminate\Database\Capsule\Manager as DB; 9use Illuminate\Database\Query\Expression; 10use Illuminate\Database\Query\JoinClause; 11use Illuminate\Support\Collection; 12 13/** 14 * @var Collection<int,Media> $media_objects 15 * @var Tree $tree 16 */ 17 18?> 19 20<?php 21// Count the number of linked records. These numbers include private records. 22// It is not good to bypass privacy, but many servers do not have the resources 23// to process privacy for every record in the tree 24$count_individuals = DB::table('individuals') 25 ->join('link', static function (JoinClause $join): void { 26 $join->on('l_from', '=', 'i_id'); 27 $join->on('l_file', '=', 'i_file'); 28 }) 29 ->where('l_type', '=', 'OBJE') 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 ->map(static fn ($n) => (int) $n) 35 ->all(); 36 37$count_families = DB::table('families') 38 ->join('link', static function (JoinClause $join): void { 39 $join->on('l_from', '=', 'f_id'); 40 $join->on('l_file', '=', 'f_file'); 41 }) 42 ->where('l_type', '=', 'OBJE') 43 ->where('l_file', '=', $tree->id()) 44 ->groupBy(['l_to']) 45 ->select(['l_to', new Expression('COUNT(*) AS total')]) 46 ->pluck('total', 'l_to') 47 ->map(static fn ($n) => (int) $n) 48 ->all(); 49 50$count_sources = DB::table('sources') 51 ->join('link', static function (JoinClause $join): void { 52 $join->on('l_from', '=', 's_id'); 53 $join->on('l_file', '=', 's_file'); 54 }) 55 ->where('l_type', '=', 'OBJE') 56 ->where('l_file', '=', $tree->id()) 57 ->groupBy(['l_to']) 58 ->select(['l_to', new Expression('COUNT(*) AS total')]) 59 ->pluck('total', 'l_to') 60 ->map(static fn ($n) => (int) $n) 61 ->all(); 62?> 63 64<table 65 class="table table-bordered table-sm wt-table-media datatables d-none" 66 <?= view('lists/datatables-attributes') ?> 67 data-columns="<?= e(json_encode([ 68 null, 69 ['type' => 'html'], 70 ['visible' => array_sum($count_individuals) > 0], 71 ['visible' => array_sum($count_families) > 0], 72 ['visible' => array_sum($count_sources) > 0], 73 ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false], 74 ], JSON_THROW_ON_ERROR)) ?>" 75> 76 <caption class="visually-hidden"> 77 <?= $caption ?? I18N::translate('Media objects') ?> 78 </caption> 79 80 <thead> 81 <tr> 82 <th><?= I18N::translate('Media') ?></th> 83 <th><?= I18N::translate('Title') ?></th> 84 <th><?= I18N::translate('Individuals') ?></th> 85 <th><?= I18N::translate('Families') ?></th> 86 <th><?= I18N::translate('Sources') ?></th> 87 <th><?= I18N::translate('Last change') ?></th> 88 </tr> 89 </thead> 90 91 <tbody> 92 <?php foreach ($media_objects as $media_object) : ?> 93 <tr class="<?= $media_object->isPendingAddition() ? 'wt-new' : '' ?> <?= $media_object->isPendingDeletion() ? 'wt-old' : '' ?>"> 94 <!-- Thumbnails--> 95 <td data-sort="<?= e($media_object->sortName()) ?>"> 96 <?php foreach ($media_object->mediaFiles() as $media_file) : ?> 97 <?= $media_file->displayImage(100, 100, 'contain', []) ?> 98 <?php endforeach ?> 99 </td> 100 101 <!-- Title --> 102 <td data-sort="<?= e($media_object->sortName()) ?>"> 103 <a href="<?= e($media_object->url()) ?>"> 104 <?= $media_object->fullName() ?> 105 </a> 106 </td> 107 108 <!-- Count of linked individuals --> 109 <td class="text-center" data-sort="<?= $count_individuals[$media_object->xref()] ?? 0 ?>"> 110 <?= I18N::number($count_individuals[$media_object->xref()] ?? 0) ?> 111 </td> 112 113 <!-- Count of linked families --> 114 <td class="text-center" data-sort="<?= $count_families[$media_object->xref()] ?? 0 ?>"> 115 <?= I18N::number($count_families[$media_object->xref()] ?? 0) ?> 116 </td> 117 118 <!-- Count of sources --> 119 <td class="text-center" data-sort="<?= $count_sources[$media_object->xref()] ?? 0 ?>"> 120 <?= I18N::number($count_sources[$media_object->xref()] ?? 0) ?> 121 </td> 122 123 <!-- Last change --> 124 <td data-sort="<?= $media_object->lastChangeTimestamp()->timestamp() ?>"> 125 <?= view('components/datetime', ['timestamp' => $media_object->lastChangeTimestamp()]) ?> 126 </td> 127 </tr> 128 <?php endforeach ?> 129 </tbody> 130</table> 131