fisharebest/webtrees

View on GitHub
resources/views/lists/surnames-compact-list.phtml

Summary

Maintainability
Test Coverage
<?php

declare(strict_types=1);

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Module\IndividualListModule;
use Fisharebest\Webtrees\Module\ModuleListInterface;
use Fisharebest\Webtrees\Tree;

/**
 * @var IndividualListModule|null $module
 * @var array<array<int>>         $surnames
 * @var bool                      $totals
 * @var Tree                      $tree
 */

$items = [];

foreach ($surnames as $surn => $surns) {
    foreach ($surns as $surname => $count) {
        if ($surname === Individual::NOMEN_NESCIO) {
            $label = I18N::translateContext('Unknown surname', '…');
            $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['alpha' => '@']) : '';
        } elseif ($surname === '') {
            $label = e($surn);
            $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['surname' => $surn]) : '';
        } else {
            $label = e($surname);
            $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['surname' => $surn]) : '';
        }

        if ($totals) {
            $item = I18N::translate('%1$s (%2$s)', '<span class="ut">' . $label . '</span>', I18N::number($count));
        } else {
            $item = $label;
        }

        if ($url !== '') {
            $items[] = '<a class="wt-surnames-compact-list-item" href="' . e($url) . '">' . $item . '</a>';
        } else {
            $items[] = '<span class="wt-surnames-compact-list-item">' . $item . '</span>';
        }
    }
}
?>
<span class="wt-surnames-compact-list"><?= implode(I18N::$list_separator, $items) ?></span>