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