1a69f5655SGreg Roach<?php 2d70512abSGreg Roach 3a69f5655SGreg Roachuse Fisharebest\Webtrees\I18N; 47c2c99faSGreg Roachuse Fisharebest\Webtrees\Note; 57c2c99faSGreg Roachuse Fisharebest\Webtrees\Tree; 6a69f5655SGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 7a69f5655SGreg Roachuse Illuminate\Database\Query\Expression; 8a69f5655SGreg Roachuse Illuminate\Database\Query\JoinClause; 97c2c99faSGreg Roachuse Illuminate\Support\Collection; 107c2c99faSGreg Roach 117c2c99faSGreg Roach/** 127c2c99faSGreg Roach * @var Collection<Note> $notes 137c2c99faSGreg Roach * @var Tree $tree 147c2c99faSGreg Roach */ 15d70512abSGreg Roach 16a69f5655SGreg Roach?> 17dd6b2bfcSGreg Roach 18dd6b2bfcSGreg Roach<?php 19dd6b2bfcSGreg Roach// Count the number of linked records. These numbers include private records. 20dd6b2bfcSGreg Roach// It is not good to bypass privacy, but many servers do not have the resources 21dd6b2bfcSGreg Roach// to process privacy for every record in the tree 223fa66c66SGreg Roach$count_individuals = DB::table('individuals') 230b5fd0a6SGreg Roach ->join('link', static function (JoinClause $join): void { 243fa66c66SGreg Roach $join->on('l_from', '=', 'i_id'); 253fa66c66SGreg Roach $join->on('l_file', '=', 'i_file'); 263fa66c66SGreg Roach }) 273fa66c66SGreg Roach ->where('l_type', '=', 'NOTE') 283fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 297f5c2944SGreg Roach ->groupBy(['l_to']) 30a69f5655SGreg Roach ->select(['l_to', new Expression('COUNT(*) AS total')]) 313fa66c66SGreg Roach ->pluck('total', 'l_to') 323fa66c66SGreg Roach ->all(); 333fa66c66SGreg Roach 342dfebe3fSGreg Roach$count_families = DB::table('families') 350b5fd0a6SGreg Roach ->join('link', static function (JoinClause $join): void { 363fa66c66SGreg Roach $join->on('l_from', '=', 'f_id'); 373fa66c66SGreg Roach $join->on('l_file', '=', 'f_file'); 383fa66c66SGreg Roach }) 393fa66c66SGreg Roach ->where('l_type', '=', 'NOTE') 403fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 417f5c2944SGreg Roach ->groupBy(['l_to']) 42a69f5655SGreg Roach ->select(['l_to', new Expression('COUNT(*) AS total')]) 433fa66c66SGreg Roach ->pluck('total', 'l_to') 443fa66c66SGreg Roach ->all(); 453fa66c66SGreg Roach 463fa66c66SGreg Roach$count_media = DB::table('media') 470b5fd0a6SGreg Roach ->join('link', static function (JoinClause $join): void { 483fa66c66SGreg Roach $join->on('l_from', '=', 'm_id'); 493fa66c66SGreg Roach $join->on('l_file', '=', 'm_file'); 503fa66c66SGreg Roach }) 513fa66c66SGreg Roach ->where('l_type', '=', 'NOTE') 523fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 537f5c2944SGreg Roach ->groupBy(['l_to']) 54a69f5655SGreg Roach ->select(['l_to', new Expression('COUNT(*) AS total')]) 553fa66c66SGreg Roach ->pluck('total', 'l_to') 563fa66c66SGreg Roach ->all(); 573fa66c66SGreg Roach 583fa66c66SGreg Roach$count_sources = DB::table('sources') 590b5fd0a6SGreg Roach ->join('link', static function (JoinClause $join): void { 603fa66c66SGreg Roach $join->on('l_from', '=', 's_id'); 613fa66c66SGreg Roach $join->on('l_file', '=', 's_file'); 623fa66c66SGreg Roach }) 633fa66c66SGreg Roach ->where('l_type', '=', 'NOTE') 643fa66c66SGreg Roach ->where('l_file', '=', $tree->id()) 657f5c2944SGreg Roach ->groupBy(['l_to']) 66a69f5655SGreg Roach ->select(['l_to', new Expression('COUNT(*) AS total')]) 673fa66c66SGreg Roach ->pluck('total', 'l_to') 683fa66c66SGreg Roach ->all(); 69dd6b2bfcSGreg Roach?> 70dd6b2bfcSGreg Roach 71dd6b2bfcSGreg Roach<table 72b4139381SGreg Roach class="table table-bordered table-sm wt-table-note datatables d-none" 7371d313c5SGreg Roach <?= view('lists/datatables-attributes') ?> 74dd6b2bfcSGreg Roach data-columns="<?= e(json_encode([ 75eef4add8SGreg Roach ['type' => 'html'], 76dd6b2bfcSGreg Roach ['visible' => array_sum($count_individuals) > 0], 77dd6b2bfcSGreg Roach ['visible' => array_sum($count_families) > 0], 78dd6b2bfcSGreg Roach ['visible' => array_sum($count_media) > 0], 79dd6b2bfcSGreg Roach ['visible' => array_sum($count_sources) > 0], 80dd6b2bfcSGreg Roach ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false], 81dd6b2bfcSGreg Roach ])) ?>" 82dd6b2bfcSGreg Roach> 83*315eb316SGreg Roach <caption class="visually-hidden"> 84dd6b2bfcSGreg Roach <?= $caption ?? I18N::translate('Sources') ?> 85dd6b2bfcSGreg Roach </caption> 86dd6b2bfcSGreg Roach 87dd6b2bfcSGreg Roach <thead> 88dd6b2bfcSGreg Roach <tr> 89dd6b2bfcSGreg Roach <th><?= I18N::translate('Title') ?></th> 90dd6b2bfcSGreg Roach <th><?= I18N::translate('Individuals') ?></th> 91dd6b2bfcSGreg Roach <th><?= I18N::translate('Families') ?></th> 92dd6b2bfcSGreg Roach <th><?= I18N::translate('Media objects') ?></th> 93dd6b2bfcSGreg Roach <th><?= I18N::translate('Sources') ?></th> 94dd6b2bfcSGreg Roach <th><?= I18N::translate('Last change') ?></th> 95dd6b2bfcSGreg Roach </tr> 96dd6b2bfcSGreg Roach </thead> 97dd6b2bfcSGreg Roach 98dd6b2bfcSGreg Roach <tbody> 99dd6b2bfcSGreg Roach <?php foreach ($notes as $note) : ?> 100b16bf9d4SGreg Roach <tr class="<?= $note->isPendingAddition() ? 'wt-new' : '' ?> <?= $note->isPendingDeletion() ? 'wt-old' : '' ?>"> 101dd6b2bfcSGreg Roach <!-- Title --> 10239ca88baSGreg Roach <td data-sort="<?= e($note->sortName()) ?>"> 103dd6b2bfcSGreg Roach <a href="<?= e($note->url()) ?>"> 10439ca88baSGreg Roach <?= $note->fullName() ?> 105dd6b2bfcSGreg Roach </a> 106dd6b2bfcSGreg Roach </td> 107dd6b2bfcSGreg Roach 108dd6b2bfcSGreg Roach <!-- Count of linked individuals --> 109242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_individuals[$note->xref()] ?? 0 ?>"> 110c0935879SGreg Roach <?= I18N::number($count_individuals[$note->xref()] ?? 0) ?> 111dd6b2bfcSGreg Roach </td> 112dd6b2bfcSGreg Roach 113dd6b2bfcSGreg Roach <!-- Count of linked families --> 114242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_families[$note->xref()] ?? 0 ?>"> 115c0935879SGreg Roach <?= I18N::number($count_families[$note->xref()] ?? 0) ?> 116dd6b2bfcSGreg Roach </td> 117dd6b2bfcSGreg Roach 118dd6b2bfcSGreg Roach <!-- Count of linked media objects --> 119242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_media[$note->xref()] ?? 0 ?>"> 120c0935879SGreg Roach <?= I18N::number($count_media[$note->xref()] ?? 0) ?> 121dd6b2bfcSGreg Roach </td> 122dd6b2bfcSGreg Roach 123dd6b2bfcSGreg Roach <!-- Count of sources --> 124242a7862SGreg Roach <td class="text-center" data-sort="<?= $count_sources[$note->xref()] ?? 0 ?>"> 125c0935879SGreg Roach <?= I18N::number($count_sources[$note->xref()] ?? 0) ?> 126dd6b2bfcSGreg Roach </td> 127dd6b2bfcSGreg Roach 128dd6b2bfcSGreg Roach <!-- Last change --> 1294459dc9aSGreg Roach <td data-sort="<?= $note->lastChangeTimestamp()->unix() ?>"> 1304459dc9aSGreg Roach <?= view('components/datetime', ['timestamp' => $note->lastChangeTimestamp()]) ?> 131dd6b2bfcSGreg Roach </td> 132dd6b2bfcSGreg Roach </tr> 133dd6b2bfcSGreg Roach <?php endforeach ?> 134dd6b2bfcSGreg Roach </tbody> 135dd6b2bfcSGreg Roach</table> 136