1a69f5655SGreg Roach<?php 2d70512abSGreg Roach 310e06497SGreg Roachdeclare(strict_types=1); 410e06497SGreg Roach 5*6f4ec3caSGreg Roachuse Fisharebest\Webtrees\DB; 6a69f5655SGreg Roachuse Fisharebest\Webtrees\I18N; 71197bb9cSGreg Roachuse Fisharebest\Webtrees\Registry; 87c2c99faSGreg Roachuse Fisharebest\Webtrees\Source; 97c2c99faSGreg Roachuse Fisharebest\Webtrees\Tree; 10a69f5655SGreg Roachuse Illuminate\Database\Query\Expression; 11a69f5655SGreg Roachuse Illuminate\Database\Query\JoinClause; 127c2c99faSGreg Roachuse Illuminate\Support\Collection; 137c2c99faSGreg Roach 147c2c99faSGreg Roach/** 1536779af1SGreg Roach * @var Collection<int,Source> $sources 167c2c99faSGreg Roach * @var Tree $tree 177c2c99faSGreg Roach */ 18d70512abSGreg Roach 19a69f5655SGreg Roach?> 20dd6b2bfcSGreg Roach 21dd6b2bfcSGreg Roach<?php 22dd6b2bfcSGreg Roach// Count the number of linked records. These numbers include private records. 23dd6b2bfcSGreg Roach// It is not good to bypass privacy, but many servers do not have the resources 24dd6b2bfcSGreg Roach// to process privacy for every record in the tree 253fa66c66SGreg Roach$count_individuals = DB::table('individuals') 260b5fd0a6SGreg Roach ->join('link', static function (JoinClause $join): void { 273fa66c66SGreg Roach $join->on('l_from', '=', 'i_id'); 283fa66c66SGreg Roach $join->on('l_file', '=', 'i_file'); 293fa66c66SGreg Roach }) 303fa66c66SGreg Roach ->where('l_type', '=', 'SOUR') 313fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 327f5c2944SGreg Roach ->groupBy(['l_to']) 33059898c9SGreg Roach ->pluck(new Expression('COUNT(*) AS total'), 'l_to') 34a962cdb5SGreg Roach ->map(static fn ($n) => (int) $n) 353fa66c66SGreg Roach ->all(); 363fa66c66SGreg Roach 373fa66c66SGreg Roach$count_families = DB::table('families') 380b5fd0a6SGreg Roach ->join('link', static function (JoinClause $join): void { 393fa66c66SGreg Roach $join->on('l_from', '=', 'f_id'); 403fa66c66SGreg Roach $join->on('l_file', '=', 'f_file'); 413fa66c66SGreg Roach }) 423fa66c66SGreg Roach ->where('l_type', '=', 'SOUR') 433fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 447f5c2944SGreg Roach ->groupBy(['l_to']) 45059898c9SGreg Roach ->pluck(new Expression('COUNT(*) AS total'), 'l_to') 46a962cdb5SGreg Roach ->map(static fn ($n) => (int) $n) 473fa66c66SGreg Roach ->all(); 483fa66c66SGreg Roach 493fa66c66SGreg Roach$count_media = DB::table('media') 500b5fd0a6SGreg Roach ->join('link', static function (JoinClause $join): void { 513fa66c66SGreg Roach $join->on('l_from', '=', 'm_id'); 523fa66c66SGreg Roach $join->on('l_file', '=', 'm_file'); 533fa66c66SGreg Roach }) 543fa66c66SGreg Roach ->where('l_type', '=', 'SOUR') 553fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 567f5c2944SGreg Roach ->groupBy(['l_to']) 57059898c9SGreg Roach ->pluck(new Expression('COUNT(*) AS total'), 'l_to') 58a962cdb5SGreg Roach ->map(static fn ($n) => (int) $n) 593fa66c66SGreg Roach ->all(); 603fa66c66SGreg Roach 613fa66c66SGreg Roach$count_notes = DB::table('other') 620b5fd0a6SGreg Roach ->join('link', static function (JoinClause $join): void { 633fa66c66SGreg Roach $join->on('l_from', '=', 'o_id'); 643fa66c66SGreg Roach $join->on('l_file', '=', 'o_file'); 653fa66c66SGreg Roach }) 663fa66c66SGreg Roach ->where('o_type', '=', 'NOTE') 673fa66c66SGreg Roach ->where('l_type', '=', 'SOUR') 683fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 697f5c2944SGreg Roach ->groupBy(['l_to']) 70059898c9SGreg Roach ->pluck(new Expression('COUNT(*) AS total'), 'l_to') 71a962cdb5SGreg Roach ->map(static fn ($n) => (int) $n) 723fa66c66SGreg Roach ->all(); 73dd6b2bfcSGreg Roach?> 74dd6b2bfcSGreg Roach 75dd6b2bfcSGreg Roach<table 76dd6b2bfcSGreg Roach class="table table-bordered table-sm wt-table-source datatables d-none" 7771d313c5SGreg Roach <?= view('lists/datatables-attributes') ?> 78dd6b2bfcSGreg Roach data-columns="<?= e(json_encode([ 79eef4add8SGreg Roach ['type' => 'html'], 80dd6b2bfcSGreg Roach null, 816718d7f2SGreg Roach null, 826718d7f2SGreg Roach null, 83dd6b2bfcSGreg Roach ['visible' => array_sum($count_individuals) > 0], 84dd6b2bfcSGreg Roach ['visible' => array_sum($count_families) > 0], 85dd6b2bfcSGreg Roach ['visible' => array_sum($count_media) > 0], 86dd6b2bfcSGreg Roach ['visible' => array_sum($count_notes) > 0], 87dd6b2bfcSGreg Roach ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false], 88728c8c27SGreg Roach ], JSON_THROW_ON_ERROR)) ?>" 89dd6b2bfcSGreg Roach> 90315eb316SGreg Roach <caption class="visually-hidden"> 91dd6b2bfcSGreg Roach <?= $caption ?? I18N::translate('Sources') ?> 92dd6b2bfcSGreg Roach </caption> 93dd6b2bfcSGreg Roach 94dd6b2bfcSGreg Roach <thead> 95dd6b2bfcSGreg Roach <tr> 96dd6b2bfcSGreg Roach <th><?= I18N::translate('Title') ?></th> 976718d7f2SGreg Roach <th class="d-none d-md-table-cell"><?= I18N::translate('Abbreviation') ?></th> 986718d7f2SGreg Roach <th class="d-none d-md-table-cell"><?= I18N::translate('Author') ?></th> 991061e22bSGreg Roach <th class="d-none d-md-table-cell"><?= I18N::translate('Publication') ?></th> 100dd6b2bfcSGreg Roach <th><?= I18N::translate('Individuals') ?></th> 101dd6b2bfcSGreg Roach <th><?= I18N::translate('Families') ?></th> 102dd6b2bfcSGreg Roach <th><?= I18N::translate('Media objects') ?></th> 103dd6b2bfcSGreg Roach <th><?= I18N::translate('Shared notes') ?></th> 104dd6b2bfcSGreg Roach <th><?= I18N::translate('Last change') ?></th> 105dd6b2bfcSGreg Roach </tr> 106dd6b2bfcSGreg Roach </thead> 107dd6b2bfcSGreg Roach 108dd6b2bfcSGreg Roach <tbody> 109dd6b2bfcSGreg Roach <?php foreach ($sources as $source) : ?> 110b16bf9d4SGreg Roach <tr class="<?= $source->isPendingAddition() ? 'wt-new' : '' ?> <?= $source->isPendingDeletion() ? 'wt-old' : '' ?>"> 111dd6b2bfcSGreg Roach <!-- Title --> 11239ca88baSGreg Roach <td data-sort="<?= e($source->sortName()) ?>"> 113dd6b2bfcSGreg Roach <a href="<?= e($source->url()) ?>"> 11439ca88baSGreg Roach <?= $source->fullName() ?> 115dd6b2bfcSGreg Roach </a> 116dd6b2bfcSGreg Roach </td> 117dd6b2bfcSGreg Roach 1186718d7f2SGreg Roach <!-- Abbreviation --> 1196718d7f2SGreg Roach <td class="d-none d-md-table-cell"> 1206718d7f2SGreg Roach <?= e($source->facts(['ABBR'])->isNotEmpty() ? $source->facts(['ABBR'])->first()->value() : '') ?> 1216718d7f2SGreg Roach </td> 1226718d7f2SGreg Roach 123dd6b2bfcSGreg Roach <!-- Author --> 1246718d7f2SGreg Roach <td class="d-none d-md-table-cell"> 125820b62dfSGreg Roach <?= e($source->facts(['AUTH'])->isNotEmpty() ? $source->facts(['AUTH'])->first()->value() : '') ?> 126dd6b2bfcSGreg Roach </td> 127dd6b2bfcSGreg Roach 1286718d7f2SGreg Roach <!-- Publisher --> 1296718d7f2SGreg Roach <td class="d-none d-md-table-cell"> 1301197bb9cSGreg Roach <?= Registry::elementFactory()->make('SOUR:PUBL')->value($source->facts(['PUBL'])->isNotEmpty() ? $source->facts(['PUBL'])->first()->value() : '', $tree) ?> 1316718d7f2SGreg Roach </td> 1326718d7f2SGreg Roach 133dd6b2bfcSGreg Roach <!-- Count of linked individuals --> 134242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_individuals[$source->xref()] ?? 0 ?>"> 135c0935879SGreg Roach <?= I18N::number($count_individuals[$source->xref()] ?? 0) ?> 136dd6b2bfcSGreg Roach </td> 137dd6b2bfcSGreg Roach 138dd6b2bfcSGreg Roach <!-- Count of linked families --> 139242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_families[$source->xref()] ?? 0 ?>"> 140c0935879SGreg Roach <?= I18N::number($count_families[$source->xref()] ?? 0) ?> 141dd6b2bfcSGreg Roach </td> 142dd6b2bfcSGreg Roach 143dd6b2bfcSGreg Roach <!-- Count of linked media objects --> 144242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_media[$source->xref()] ?? 0 ?>"> 145c0935879SGreg Roach <?= I18N::number($count_media[$source->xref()] ?? 0) ?> 146dd6b2bfcSGreg Roach </td> 147dd6b2bfcSGreg Roach 148dd6b2bfcSGreg Roach <!-- Count of linked notes --> 149242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_notes[$source->xref()] ?? 0 ?>"> 150c0935879SGreg Roach <?= I18N::number($count_notes[$source->xref()] ?? 0) ?> 151dd6b2bfcSGreg Roach </td> 152dd6b2bfcSGreg Roach 153dd6b2bfcSGreg Roach <!-- Last change --> 154d97083feSGreg Roach <td data-sort="<?= $source->lastChangeTimestamp()->timestamp() ?>"> 1554459dc9aSGreg Roach <?= view('components/datetime', ['timestamp' => $source->lastChangeTimestamp()]) ?> 156dd6b2bfcSGreg Roach </td> 157dd6b2bfcSGreg Roach </tr> 158dd6b2bfcSGreg Roach <?php endforeach ?> 159dd6b2bfcSGreg Roach </tbody> 160dd6b2bfcSGreg Roach</table> 161