xref: /webtrees/resources/views/lists/surnames-column-list.phtml (revision c3d23edc02a2e9156764345611bba90e6c035fc1)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\I18N;
6use Fisharebest\Webtrees\Individual;
7use Fisharebest\Webtrees\Module\IndividualListModule;
8use Fisharebest\Webtrees\Module\ModuleListInterface;
9use Fisharebest\Webtrees\Tree;
10
11/**
12 * @var IndividualListModule|null $module
13 * @var array<array<int>>         $surnames
14 * @var bool                      $totals
15 * @var Tree                      $tree
16 */
17
18$maximum = max(array_map(static fn (array $x): int => max($x), $surnames));
19$minimum = min(array_map(static fn (array $x): int => min($x), $surnames));
20
21?>
22
23<div class="wt-surnames-column-list px-3" style="columns: 15rem; column-rule: solid thin gray; border: solid thin gray;">
24    <?php foreach ($surnames as $surn => $surns) : ?>
25        <?php foreach ($surns as $surname => $count) : ?>
26            <?php
27            $size     = 1.0 + ($maximum === $minimum ? 0 : 1.5 * ($count - $minimum) / ($maximum - $minimum));
28
29            if ($surn === Individual::NOMEN_NESCIO) {
30                $label = I18N::translateContext('Unknown surname', '…');
31                $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['alpha' => '@']) : '';
32            } elseif ($surname === '') {
33                if ($surn === '') {
34                    $label = I18N::translate('No surname');
35                } else {
36                    $label = e($surn);
37                }
38                $url = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['alpha' => ',']) : '';
39            } else {
40                $label = e($surname);
41                $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['surname' => $surn]) : '';
42            }
43
44            if ($totals) {
45                $item = I18N::translate('%1$s (%2$s)', '<span class="ut">' . $label . '</span>', I18N::number($count));
46            } else {
47                $item = '<span class="ut">' . $label . '</span>';
48            }
49            ?>
50            <div class="wt-surnames-column-list-item ut">
51                <?php if ($url !== '') : ?>
52                    <a href="<?= e($url) ?>"><?= $item ?></a>
53                <?php else : ?>
54                    <?= $item ?>
55                <?php endif ?>
56            </div>
57        <?php endforeach ?>
58    <?php endforeach ?>
59</div>
60