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', function (JoinClause $join): void { 11 $join->on('l_from', '=', 'i_id'); 12 $join->on('l_file', '=', 'i_file'); 13 }) 14 ->where('l_type', '=', 'SOUR') 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', function (JoinClause $join): void { 23 $join->on('l_from', '=', 'f_id'); 24 $join->on('l_file', '=', 'f_file'); 25 }) 26 ->where('l_type', '=', 'SOUR') 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_media = DB::table('media') 34 ->join('link', function (JoinClause $join): void { 35 $join->on('l_from', '=', 'm_id'); 36 $join->on('l_file', '=', 'm_file'); 37 }) 38 ->where('l_type', '=', 'SOUR') 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$count_notes = DB::table('other') 46 ->join('link', function (JoinClause $join): void { 47 $join->on('l_from', '=', 'o_id'); 48 $join->on('l_file', '=', 'o_file'); 49 }) 50 ->where('o_type', '=', 'NOTE') 51 ->where('l_type', '=', 'SOUR') 52 ->where('l_file', '=', $tree->id()) 53 ->groupBy('l_to') 54 ->select(['l_to', DB::raw('COUNT(*) AS total')]) 55 ->pluck('total', 'l_to') 56 ->all(); 57?> 58 59<table 60 class="table table-bordered table-sm wt-table-source datatables d-none" 61 <?= view('lists/datatables-attributes') ?> 62 data-auto-width="false" 63 data-columns="<?= e(json_encode([ 64 null, 65 null, 66 ['visible' => array_sum($count_individuals) > 0], 67 ['visible' => array_sum($count_families) > 0], 68 ['visible' => array_sum($count_media) > 0], 69 ['visible' => array_sum($count_notes) > 0], 70 ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false], 71 ])) ?>" 72> 73 <caption class="sr-only"> 74 <?= $caption ?? I18N::translate('Sources') ?> 75 </caption> 76 77 <thead> 78 <tr> 79 <th><?= I18N::translate('Title') ?></th> 80 <th><?= I18N::translate('Author') ?></th> 81 <th><?= I18N::translate('Individuals') ?></th> 82 <th><?= I18N::translate('Families') ?></th> 83 <th><?= I18N::translate('Media objects') ?></th> 84 <th><?= I18N::translate('Shared notes') ?></th> 85 <th><?= I18N::translate('Last change') ?></th> 86 </tr> 87 </thead> 88 89 <tbody> 90 <?php foreach ($sources as $source) : ?> 91 <tr class="<?= $source->isPendingDeletion() ? 'old' : ($source->isPendingAddition() ? 'new' : '') ?>"> 92 <!-- Title --> 93 <td data-sort="<?= e($source->sortName()) ?>"> 94 <a href="<?= e($source->url()) ?>"> 95 <?= $source->fullName() ?> 96 </a> 97 </td> 98 99 <!-- Author --> 100 <td> 101 <?= e($source->facts(['AUTH'])->isNotEmpty() ? $source->facts(['AUTH'])->first()->value() : '') ?> 102 </td> 103 104 <!-- Count of linked individuals --> 105 <td class="text-center" data-sort="<?= $count_individuals[$source->xref()] ?? 0 ?>"> 106 <?= I18N::number($count_individuals[$source->xref()] ?? 0) ?> 107 </td> 108 109 <!-- Count of linked families --> 110 <td class="text-center" data-sort="<?= $count_families[$source->xref()] ?? 0 ?>"> 111 <?= I18N::number($count_families[$source->xref()] ?? 0) ?> 112 </td> 113 114 <!-- Count of linked media objects --> 115 <td class="text-center" data-sort="<?= $count_media[$source->xref()] ?? 0 ?>"> 116 <?= I18N::number($count_media[$source->xref()] ?? 0) ?> 117 </td> 118 119 <!-- Count of linked notes --> 120 <td class="text-center" data-sort="<?= $count_notes[$source->xref()] ?? 0 ?>"> 121 <?= I18N::number($count_notes[$source->xref()] ?? 0) ?> 122 </td> 123 124 <!-- Last change --> 125 <td data-sort="<?= $source->lastChangeTimestamp()->unix() ?>"> 126 <?= view('components/datetime', ['timestamp' => $source->lastChangeTimestamp()]) ?> 127 </td> 128 </tr> 129 <?php endforeach ?> 130 </tbody> 131</table> 132