xref: /webtrees/resources/views/lists/surnames-compact-list.phtml (revision 80ea34ecc70d4262c6d367d07e1df0ef880f5367)
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$items = [];
19
20foreach ($surnames as $surn => $surns) {
21    foreach ($surns as $surname => $count) {
22        if ($surn === Individual::NOMEN_NESCIO) {
23            $label = I18N::translateContext('Unknown surname', '…');
24            $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['alpha' => '@']) : '';
25        } elseif ($surname === '') {
26            if ($surn === '') {
27                $label = I18N::translate('No surname');
28            } else {
29                $label = e($surn);
30            }
31            $url = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['alpha' => ',']) : '';
32        } else {
33            $label = e($surname);
34            $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['surname' => $surn]) : '';
35        }
36
37        if ($totals) {
38            $item = I18N::translate('%1$s (%2$s)', '<span class="ut">' . $label . '</span>', I18N::number($count));
39        } else {
40            $item = $label;
41        }
42
43        if ($url !== '') {
44            $items[] = '<a class="wt-surnames-compact-list-item" href="' . e($url) . '">' . $item . '</a>';
45        } else {
46            $items[] = '<span class="wt-surnames-compact-list-item">' . $item . '</span>';
47        }
48    }
49}
50?>
51<span class="wt-surnames-compact-list"><?= implode(I18N::$list_separator, $items) ?></span>
52