xref: /webtrees/resources/views/lists/notes-table.phtml (revision 6f4ec3cadc983f0a7294108c634bef48846b4311)
1a69f5655SGreg Roach<?php
2d70512abSGreg Roach
310e06497SGreg Roachdeclare(strict_types=1);
410e06497SGreg Roach
5*6f4ec3caSGreg Roachuse Fisharebest\Webtrees\DB;
6a69f5655SGreg Roachuse Fisharebest\Webtrees\I18N;
77c2c99faSGreg Roachuse Fisharebest\Webtrees\Note;
87c2c99faSGreg Roachuse Fisharebest\Webtrees\Tree;
9a69f5655SGreg Roachuse Illuminate\Database\Query\Expression;
10a69f5655SGreg Roachuse Illuminate\Database\Query\JoinClause;
117c2c99faSGreg Roachuse Illuminate\Support\Collection;
127c2c99faSGreg Roach
137c2c99faSGreg Roach/**
1436779af1SGreg Roach * @var Collection<int,Note> $notes
157c2c99faSGreg Roach * @var Tree                 $tree
167c2c99faSGreg Roach */
17d70512abSGreg Roach
18a69f5655SGreg Roach?>
19dd6b2bfcSGreg Roach
20dd6b2bfcSGreg Roach<?php
21dd6b2bfcSGreg Roach// Count the number of linked records. These numbers include private records.
22dd6b2bfcSGreg Roach// It is not good to bypass privacy, but many servers do not have the resources
23dd6b2bfcSGreg Roach// to process privacy for every record in the tree
243fa66c66SGreg Roach$count_individuals = DB::table('individuals')
250b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
263fa66c66SGreg Roach        $join->on('l_from', '=', 'i_id');
273fa66c66SGreg Roach        $join->on('l_file', '=', 'i_file');
283fa66c66SGreg Roach    })
293fa66c66SGreg Roach    ->where('l_type', '=', 'NOTE')
303fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
317f5c2944SGreg Roach    ->groupBy(['l_to'])
32059898c9SGreg Roach    ->pluck(new Expression('COUNT(*) AS total'), 'l_to')
33a962cdb5SGreg Roach    ->map(static fn ($n) => (int) $n)
343fa66c66SGreg Roach    ->all();
353fa66c66SGreg Roach
362dfebe3fSGreg Roach$count_families = DB::table('families')
370b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
383fa66c66SGreg Roach        $join->on('l_from', '=', 'f_id');
393fa66c66SGreg Roach        $join->on('l_file', '=', 'f_file');
403fa66c66SGreg Roach    })
413fa66c66SGreg Roach    ->where('l_type', '=', 'NOTE')
423fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
437f5c2944SGreg Roach    ->groupBy(['l_to'])
44059898c9SGreg Roach    ->pluck(new Expression('COUNT(*) AS total'), 'l_to')
45a962cdb5SGreg Roach    ->map(static fn ($n) => (int) $n)
463fa66c66SGreg Roach    ->all();
473fa66c66SGreg Roach
483fa66c66SGreg Roach$count_media = DB::table('media')
490b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
503fa66c66SGreg Roach        $join->on('l_from', '=', 'm_id');
513fa66c66SGreg Roach        $join->on('l_file', '=', 'm_file');
523fa66c66SGreg Roach    })
533fa66c66SGreg Roach    ->where('l_type', '=', 'NOTE')
543fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
557f5c2944SGreg Roach    ->groupBy(['l_to'])
56059898c9SGreg Roach    ->pluck(new Expression('COUNT(*) AS total'), 'l_to')
57a962cdb5SGreg Roach    ->map(static fn ($n) => (int) $n)
583fa66c66SGreg Roach    ->all();
593fa66c66SGreg Roach
603fa66c66SGreg Roach$count_sources = DB::table('sources')
610b5fd0a6SGreg Roach    ->join('link', static function (JoinClause $join): void {
623fa66c66SGreg Roach        $join->on('l_from', '=', 's_id');
633fa66c66SGreg Roach        $join->on('l_file', '=', 's_file');
643fa66c66SGreg Roach    })
653fa66c66SGreg Roach    ->where('l_type', '=', 'NOTE')
663fa66c66SGreg Roach    ->where('l_file', '=', $tree->id())
677f5c2944SGreg Roach    ->groupBy(['l_to'])
68059898c9SGreg Roach    ->pluck(new Expression('COUNT(*) AS total'), 'l_to')
69a962cdb5SGreg Roach    ->map(static fn ($n) => (int) $n)
703fa66c66SGreg Roach    ->all();
71dd6b2bfcSGreg Roach?>
72dd6b2bfcSGreg Roach
73dd6b2bfcSGreg Roach<table
74b4139381SGreg Roach    class="table table-bordered table-sm wt-table-note datatables d-none"
7571d313c5SGreg Roach    <?= view('lists/datatables-attributes') ?>
76dd6b2bfcSGreg Roach    data-columns="<?= e(json_encode([
77eef4add8SGreg Roach        ['type' => 'html'],
78dd6b2bfcSGreg Roach        ['visible' => array_sum($count_individuals) > 0],
79dd6b2bfcSGreg Roach        ['visible' => array_sum($count_families) > 0],
80dd6b2bfcSGreg Roach        ['visible' => array_sum($count_media) > 0],
81dd6b2bfcSGreg Roach        ['visible' => array_sum($count_sources) > 0],
82dd6b2bfcSGreg Roach        ['visible' => (bool) $tree->getPreference('SHOW_LAST_CHANGE'), 'searchable' => false],
83728c8c27SGreg Roach    ], JSON_THROW_ON_ERROR)) ?>"
84dd6b2bfcSGreg Roach>
85315eb316SGreg Roach    <caption class="visually-hidden">
86dd6b2bfcSGreg Roach        <?= $caption ?? I18N::translate('Sources') ?>
87dd6b2bfcSGreg Roach    </caption>
88dd6b2bfcSGreg Roach
89dd6b2bfcSGreg Roach    <thead>
90dd6b2bfcSGreg Roach        <tr>
91dd6b2bfcSGreg Roach            <th><?= I18N::translate('Title') ?></th>
92dd6b2bfcSGreg Roach            <th><?= I18N::translate('Individuals') ?></th>
93dd6b2bfcSGreg Roach            <th><?= I18N::translate('Families') ?></th>
94dd6b2bfcSGreg Roach            <th><?= I18N::translate('Media objects') ?></th>
95dd6b2bfcSGreg Roach            <th><?= I18N::translate('Sources') ?></th>
96dd6b2bfcSGreg Roach            <th><?= I18N::translate('Last change') ?></th>
97dd6b2bfcSGreg Roach        </tr>
98dd6b2bfcSGreg Roach    </thead>
99dd6b2bfcSGreg Roach
100dd6b2bfcSGreg Roach    <tbody>
101dd6b2bfcSGreg Roach        <?php foreach ($notes as $note) : ?>
102b16bf9d4SGreg Roach            <tr class="<?= $note->isPendingAddition() ? 'wt-new' : '' ?> <?= $note->isPendingDeletion() ? 'wt-old' : '' ?>">
103dd6b2bfcSGreg Roach                <!-- Title -->
10439ca88baSGreg Roach                <td data-sort="<?= e($note->sortName()) ?>">
105dd6b2bfcSGreg Roach                    <a href="<?= e($note->url()) ?>">
10639ca88baSGreg Roach                        <?= $note->fullName() ?>
107dd6b2bfcSGreg Roach                    </a>
108dd6b2bfcSGreg Roach                </td>
109dd6b2bfcSGreg Roach
110dd6b2bfcSGreg Roach                <!-- Count of linked individuals -->
111242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_individuals[$note->xref()] ?? 0 ?>">
112c0935879SGreg Roach                    <?= I18N::number($count_individuals[$note->xref()] ?? 0) ?>
113dd6b2bfcSGreg Roach                </td>
114dd6b2bfcSGreg Roach
115dd6b2bfcSGreg Roach                <!-- Count of linked families -->
116242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_families[$note->xref()] ?? 0 ?>">
117c0935879SGreg Roach                    <?= I18N::number($count_families[$note->xref()] ?? 0) ?>
118dd6b2bfcSGreg Roach                </td>
119dd6b2bfcSGreg Roach
120dd6b2bfcSGreg Roach                <!-- Count of linked media objects -->
121242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_media[$note->xref()] ?? 0 ?>">
122c0935879SGreg Roach                    <?= I18N::number($count_media[$note->xref()] ?? 0) ?>
123dd6b2bfcSGreg Roach                </td>
124dd6b2bfcSGreg Roach
125dd6b2bfcSGreg Roach                <!-- Count of sources -->
126242a7862SGreg Roach                <td class="text-center" data-sort="<?= $count_sources[$note->xref()] ?? 0 ?>">
127c0935879SGreg Roach                    <?= I18N::number($count_sources[$note->xref()] ?? 0) ?>
128dd6b2bfcSGreg Roach                </td>
129dd6b2bfcSGreg Roach
130dd6b2bfcSGreg Roach                <!-- Last change -->
131d97083feSGreg Roach                <td data-sort="<?= $note->lastChangeTimestamp()->timestamp() ?>">
1324459dc9aSGreg Roach                    <?= view('components/datetime', ['timestamp' => $note->lastChangeTimestamp()]) ?>
133dd6b2bfcSGreg Roach                </td>
134dd6b2bfcSGreg Roach            </tr>
135dd6b2bfcSGreg Roach        <?php endforeach ?>
136dd6b2bfcSGreg Roach    </tbody>
137dd6b2bfcSGreg Roach</table>
138