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