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