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', '=', 'NOTE') 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 212dfebe3fSGreg 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', '=', 'NOTE') 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', '=', 'NOTE') 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_sources = DB::table('sources') 463fa66c66SGreg Roach ->join('link', function (JoinClause $join): void { 473fa66c66SGreg Roach $join->on('l_from', '=', 's_id'); 483fa66c66SGreg Roach $join->on('l_file', '=', 's_file'); 493fa66c66SGreg Roach }) 503fa66c66SGreg Roach ->where('l_type', '=', 'NOTE') 513fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 523fa66c66SGreg Roach ->groupBy('l_to') 533fa66c66SGreg Roach ->select(['l_to', DB::raw('COUNT(*) AS total')]) 543fa66c66SGreg Roach ->pluck('total', 'l_to') 553fa66c66SGreg Roach ->all(); 56dd6b2bfcSGreg Roach?> 57dd6b2bfcSGreg Roach 58dd6b2bfcSGreg Roach<table 59dd6b2bfcSGreg Roach class="table table-bordered table-sm wt-table-note datatables" 6071d313c5SGreg Roach <?= view('lists/datatables-attributes') ?> 61dd6b2bfcSGreg Roach data-columns="<?= e(json_encode([ 62dd6b2bfcSGreg Roach null, 63dd6b2bfcSGreg Roach ['visible' => array_sum($count_individuals) > 0], 64dd6b2bfcSGreg Roach ['visible' => array_sum($count_families) > 0], 65dd6b2bfcSGreg Roach ['visible' => array_sum($count_media) > 0], 66dd6b2bfcSGreg Roach ['visible' => array_sum($count_sources) > 0], 67dd6b2bfcSGreg Roach ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false], 68dd6b2bfcSGreg Roach ])) ?>" 69dd6b2bfcSGreg Roach> 70dd6b2bfcSGreg Roach <caption class="sr-only"> 71dd6b2bfcSGreg Roach <?= $caption ?? I18N::translate('Sources') ?> 72dd6b2bfcSGreg Roach </caption> 73dd6b2bfcSGreg Roach 74dd6b2bfcSGreg Roach <thead> 75dd6b2bfcSGreg Roach <tr> 76dd6b2bfcSGreg Roach <th><?= I18N::translate('Title') ?></th> 77dd6b2bfcSGreg Roach <th><?= I18N::translate('Individuals') ?></th> 78dd6b2bfcSGreg Roach <th><?= I18N::translate('Families') ?></th> 79dd6b2bfcSGreg Roach <th><?= I18N::translate('Media objects') ?></th> 80dd6b2bfcSGreg Roach <th><?= I18N::translate('Sources') ?></th> 81dd6b2bfcSGreg Roach <th><?= I18N::translate('Last change') ?></th> 82dd6b2bfcSGreg Roach </tr> 83dd6b2bfcSGreg Roach </thead> 84dd6b2bfcSGreg Roach 85dd6b2bfcSGreg Roach <tbody> 86dd6b2bfcSGreg Roach <?php foreach ($notes as $note) : ?> 87dd6b2bfcSGreg Roach <tr class="<?= $note->isPendingDeletion() ? 'old' : ($note->isPendingAddition() ? 'new' : '') ?>"> 88dd6b2bfcSGreg Roach <!-- Title --> 89*39ca88baSGreg Roach <td data-sort="<?= e($note->sortName()) ?>"> 90dd6b2bfcSGreg Roach <a href="<?= e($note->url()) ?>"> 91*39ca88baSGreg Roach <?= $note->fullName() ?> 92dd6b2bfcSGreg Roach </a> 93dd6b2bfcSGreg Roach </td> 94dd6b2bfcSGreg Roach 95dd6b2bfcSGreg Roach <!-- Count of linked individuals --> 96242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_individuals[$note->xref()] ?? 0 ?>"> 97c0935879SGreg Roach <?= I18N::number($count_individuals[$note->xref()] ?? 0) ?> 98dd6b2bfcSGreg Roach </td> 99dd6b2bfcSGreg Roach 100dd6b2bfcSGreg Roach <!-- Count of linked families --> 101242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_families[$note->xref()] ?? 0 ?>"> 102c0935879SGreg Roach <?= I18N::number($count_families[$note->xref()] ?? 0) ?> 103dd6b2bfcSGreg Roach </td> 104dd6b2bfcSGreg Roach 105dd6b2bfcSGreg Roach <!-- Count of linked media objects --> 106242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_media[$note->xref()] ?? 0 ?>"> 107c0935879SGreg Roach <?= I18N::number($count_media[$note->xref()] ?? 0) ?> 108dd6b2bfcSGreg Roach </td> 109dd6b2bfcSGreg Roach 110dd6b2bfcSGreg Roach <!-- Count of sources --> 111242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_sources[$note->xref()] ?? 0 ?>"> 112c0935879SGreg Roach <?= I18N::number($count_sources[$note->xref()] ?? 0) ?> 113dd6b2bfcSGreg Roach </td> 114dd6b2bfcSGreg Roach 115dd6b2bfcSGreg Roach <!-- Last change --> 116dd6b2bfcSGreg Roach <td data-sort="<?= $note->lastChangeTimestamp(true) ?>"> 117dd6b2bfcSGreg Roach <?= $note->lastChangeTimestamp() ?> 118dd6b2bfcSGreg Roach </td> 119dd6b2bfcSGreg Roach </tr> 120dd6b2bfcSGreg Roach <?php endforeach ?> 121dd6b2bfcSGreg Roach </tbody> 122dd6b2bfcSGreg Roach</table> 123