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', '=', 'NOTE') 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', '=', 'NOTE') 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', '=', 'NOTE') 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_sources = DB::table('sources') 51 ->join('link', static function (JoinClause $join): void { 52 $join->on('l_from', '=', 's_id'); 53 $join->on('l_file', '=', 's_file'); 54 }) 55 ->where('l_type', '=', 'NOTE') 56 ->where('l_file', '=', $tree->id()) 57 ->groupBy(['l_to']) 58 ->select(['l_to', new Expression('COUNT(*) AS total')]) 59 ->pluck('total', 'l_to') 60 ->all(); 61?> 62 63<table 64 class="table table-bordered table-sm wt-table-note datatables" 65 <?= view('lists/datatables-attributes') ?> 66 data-auto-width="false" 67 data-columns="<?= e(json_encode([ 68 null, 69 ['visible' => array_sum($count_individuals) > 0], 70 ['visible' => array_sum($count_families) > 0], 71 ['visible' => array_sum($count_media) > 0], 72 ['visible' => array_sum($count_sources) > 0], 73 ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false], 74 ])) ?>" 75> 76 <caption class="sr-only"> 77 <?= $caption ?? I18N::translate('Sources') ?> 78 </caption> 79 80 <thead> 81 <tr> 82 <th><?= I18N::translate('Title') ?></th> 83 <th><?= I18N::translate('Individuals') ?></th> 84 <th><?= I18N::translate('Families') ?></th> 85 <th><?= I18N::translate('Media objects') ?></th> 86 <th><?= I18N::translate('Sources') ?></th> 87 <th><?= I18N::translate('Last change') ?></th> 88 </tr> 89 </thead> 90 91 <tbody> 92 <?php foreach ($notes as $note) : ?> 93 <tr class="<?= $note->isPendingDeletion() ? 'wt-old' : ($note->isPendingAddition() ? 'wt-new' : '') ?>"> 94 <!-- Title --> 95 <td data-sort="<?= e($note->sortName()) ?>"> 96 <a href="<?= e($note->url()) ?>"> 97 <?= $note->fullName() ?> 98 </a> 99 </td> 100 101 <!-- Count of linked individuals --> 102 <td class="text-center" data-sort="<?= $count_individuals[$note->xref()] ?? 0 ?>"> 103 <?= I18N::number($count_individuals[$note->xref()] ?? 0) ?> 104 </td> 105 106 <!-- Count of linked families --> 107 <td class="text-center" data-sort="<?= $count_families[$note->xref()] ?? 0 ?>"> 108 <?= I18N::number($count_families[$note->xref()] ?? 0) ?> 109 </td> 110 111 <!-- Count of linked media objects --> 112 <td class="text-center" data-sort="<?= $count_media[$note->xref()] ?? 0 ?>"> 113 <?= I18N::number($count_media[$note->xref()] ?? 0) ?> 114 </td> 115 116 <!-- Count of sources --> 117 <td class="text-center" data-sort="<?= $count_sources[$note->xref()] ?? 0 ?>"> 118 <?= I18N::number($count_sources[$note->xref()] ?? 0) ?> 119 </td> 120 121 <!-- Last change --> 122 <td data-sort="<?= $note->lastChangeTimestamp()->unix() ?>"> 123 <?= view('components/datetime', ['timestamp' => $note->lastChangeTimestamp()]) ?> 124 </td> 125 </tr> 126 <?php endforeach ?> 127 </tbody> 128</table> 129