1dd6b2bfcSGreg Roach<?php use Fisharebest\Webtrees\I18N; ?> 23fa66c66SGreg Roach<?php use Illuminate\Database\Query\JoinClause; ?> 33fa66c66SGreg Roach<?php use Illuminate\Database\Capsule\Manager as DB; ?> 4dd6b2bfcSGreg Roach 5dd6b2bfcSGreg Roach<?php 6dd6b2bfcSGreg Roach// Count the number of linked records. These numbers include private records. 7dd6b2bfcSGreg Roach// It is not good to bypass privacy, but many servers do not have the resources 8dd6b2bfcSGreg Roach// to process privacy for every record in the tree 93fa66c66SGreg Roach$count_individuals = DB::table('individuals') 103fa66c66SGreg Roach ->join('link', function (JoinClause $join): void { 113fa66c66SGreg Roach $join->on('l_from', '=', 'i_id'); 123fa66c66SGreg Roach $join->on('l_file', '=', 'i_file'); 133fa66c66SGreg Roach }) 143fa66c66SGreg Roach ->where('l_type', '=', 'SOUR') 153fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 163fa66c66SGreg Roach ->groupBy('l_to') 173fa66c66SGreg Roach ->select(['l_to', DB::raw('COUNT(*) AS total')]) 183fa66c66SGreg Roach ->pluck('total', 'l_to') 193fa66c66SGreg Roach ->all(); 203fa66c66SGreg Roach 213fa66c66SGreg Roach$count_families = DB::table('families') 223fa66c66SGreg Roach ->join('link', function (JoinClause $join): void { 233fa66c66SGreg Roach $join->on('l_from', '=', 'f_id'); 243fa66c66SGreg Roach $join->on('l_file', '=', 'f_file'); 253fa66c66SGreg Roach }) 263fa66c66SGreg Roach ->where('l_type', '=', 'SOUR') 273fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 283fa66c66SGreg Roach ->groupBy('l_to') 293fa66c66SGreg Roach ->select(['l_to', DB::raw('COUNT(*) AS total')]) 303fa66c66SGreg Roach ->pluck('total', 'l_to') 313fa66c66SGreg Roach ->all(); 323fa66c66SGreg Roach 333fa66c66SGreg Roach$count_media = DB::table('media') 343fa66c66SGreg Roach ->join('link', function (JoinClause $join): void { 353fa66c66SGreg Roach $join->on('l_from', '=', 'm_id'); 363fa66c66SGreg Roach $join->on('l_file', '=', 'm_file'); 373fa66c66SGreg Roach }) 383fa66c66SGreg Roach ->where('l_type', '=', 'SOUR') 393fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 403fa66c66SGreg Roach ->groupBy('l_to') 413fa66c66SGreg Roach ->select(['l_to', DB::raw('COUNT(*) AS total')]) 423fa66c66SGreg Roach ->pluck('total', 'l_to') 433fa66c66SGreg Roach ->all(); 443fa66c66SGreg Roach 453fa66c66SGreg Roach$count_notes = DB::table('other') 463fa66c66SGreg Roach ->join('link', function (JoinClause $join): void { 473fa66c66SGreg Roach $join->on('l_from', '=', 'o_id'); 483fa66c66SGreg Roach $join->on('l_file', '=', 'o_file'); 493fa66c66SGreg Roach }) 503fa66c66SGreg Roach ->where('o_type', '=', 'NOTE') 513fa66c66SGreg Roach ->where('l_type', '=', 'SOUR') 523fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 533fa66c66SGreg Roach ->groupBy('l_to') 543fa66c66SGreg Roach ->select(['l_to', DB::raw('COUNT(*) AS total')]) 553fa66c66SGreg Roach ->pluck('total', 'l_to') 563fa66c66SGreg Roach ->all(); 57dd6b2bfcSGreg Roach?> 58dd6b2bfcSGreg Roach 59dd6b2bfcSGreg Roach<table 60dd6b2bfcSGreg Roach class="table table-bordered table-sm wt-table-source datatables d-none" 6171d313c5SGreg 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_media) > 0], 68dd6b2bfcSGreg Roach ['visible' => array_sum($count_notes) > 0], 69dd6b2bfcSGreg Roach ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false], 70dd6b2bfcSGreg Roach ])) ?>" 71dd6b2bfcSGreg Roach> 72dd6b2bfcSGreg Roach <caption class="sr-only"> 73dd6b2bfcSGreg Roach <?= $caption ?? I18N::translate('Sources') ?> 74dd6b2bfcSGreg Roach </caption> 75dd6b2bfcSGreg Roach 76dd6b2bfcSGreg Roach <thead> 77dd6b2bfcSGreg Roach <tr> 78dd6b2bfcSGreg Roach <th><?= I18N::translate('Title') ?></th> 79dd6b2bfcSGreg Roach <th><?= I18N::translate('Author') ?></th> 80dd6b2bfcSGreg Roach <th><?= I18N::translate('Individuals') ?></th> 81dd6b2bfcSGreg Roach <th><?= I18N::translate('Families') ?></th> 82dd6b2bfcSGreg Roach <th><?= I18N::translate('Media objects') ?></th> 83dd6b2bfcSGreg Roach <th><?= I18N::translate('Shared notes') ?></th> 84dd6b2bfcSGreg Roach <th><?= I18N::translate('Last change') ?></th> 85dd6b2bfcSGreg Roach </tr> 86dd6b2bfcSGreg Roach </thead> 87dd6b2bfcSGreg Roach 88dd6b2bfcSGreg Roach <tbody> 89dd6b2bfcSGreg Roach <?php foreach ($sources as $source) : ?> 90dd6b2bfcSGreg Roach <tr class="<?= $source->isPendingDeletion() ? 'old' : ($source->isPendingAddition() ? 'new' : '') ?>"> 91dd6b2bfcSGreg Roach <!-- Title --> 92*39ca88baSGreg Roach <td data-sort="<?= e($source->sortName()) ?>"> 93dd6b2bfcSGreg Roach <a href="<?= e($source->url()) ?>"> 94*39ca88baSGreg Roach <?= $source->fullName() ?> 95dd6b2bfcSGreg Roach </a> 96dd6b2bfcSGreg Roach </td> 97dd6b2bfcSGreg Roach 98dd6b2bfcSGreg Roach <!-- Author --> 99dd6b2bfcSGreg Roach <td> 100*39ca88baSGreg Roach <?= e($source->firstFact('AUTH') ? $source->firstFact('AUTH')->value() : '') ?> 101dd6b2bfcSGreg Roach </td> 102dd6b2bfcSGreg Roach 103dd6b2bfcSGreg Roach <!-- Count of linked individuals --> 104242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_individuals[$source->xref()] ?? 0 ?>"> 105c0935879SGreg Roach <?= I18N::number($count_individuals[$source->xref()] ?? 0) ?> 106dd6b2bfcSGreg Roach </td> 107dd6b2bfcSGreg Roach 108dd6b2bfcSGreg Roach <!-- Count of linked families --> 109242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_families[$source->xref()] ?? 0 ?>"> 110c0935879SGreg Roach <?= I18N::number($count_families[$source->xref()] ?? 0) ?> 111dd6b2bfcSGreg Roach </td> 112dd6b2bfcSGreg Roach 113dd6b2bfcSGreg Roach <!-- Count of linked media objects --> 114242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_media[$source->xref()] ?? 0 ?>"> 115c0935879SGreg Roach <?= I18N::number($count_media[$source->xref()] ?? 0) ?> 116dd6b2bfcSGreg Roach </td> 117dd6b2bfcSGreg Roach 118dd6b2bfcSGreg Roach <!-- Count of linked notes --> 119242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_notes[$source->xref()] ?? 0 ?>"> 120c0935879SGreg Roach <?= I18N::number($count_notes[$source->xref()] ?? 0) ?> 121dd6b2bfcSGreg Roach </td> 122dd6b2bfcSGreg Roach 123dd6b2bfcSGreg Roach <!-- Last change --> 124dd6b2bfcSGreg Roach <td data-sort="<?= $source->lastChangeTimestamp(true) ?>"> 125dd6b2bfcSGreg Roach <?= $source->lastChangeTimestamp() ?> 126dd6b2bfcSGreg Roach </td> 127dd6b2bfcSGreg Roach </tr> 128dd6b2bfcSGreg Roach <?php endforeach ?> 129dd6b2bfcSGreg Roach </tbody> 130dd6b2bfcSGreg Roach</table> 131