1a69f5655SGreg Roach<?php 2d70512abSGreg Roach 3a69f5655SGreg Roachuse Fisharebest\Webtrees\I18N; 4*7c2c99faSGreg Roachuse Fisharebest\Webtrees\Media; 5*7c2c99faSGreg Roachuse Fisharebest\Webtrees\Tree; 6a69f5655SGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 7a69f5655SGreg Roachuse Illuminate\Database\Query\Expression; 8a69f5655SGreg Roachuse Illuminate\Database\Query\JoinClause; 9*7c2c99faSGreg Roachuse Illuminate\Support\Collection; 10*7c2c99faSGreg Roach 11*7c2c99faSGreg Roach/** 12*7c2c99faSGreg Roach * @var Collection<Media> $media_objects 13*7c2c99faSGreg Roach * @var Tree $tree 14*7c2c99faSGreg 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, 64dd6b2bfcSGreg Roach null, 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], 69dd6b2bfcSGreg Roach ])) ?>" 70dd6b2bfcSGreg Roach> 71dd6b2bfcSGreg Roach <caption class="sr-only"> 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 --> 1194459dc9aSGreg Roach <td data-sort="<?= $media_object->lastChangeTimestamp()->unix() ?>"> 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