Add world
parameter to dummy leaderboard page
This commit is contained in:
parent
23fb9eacfb
commit
378ee801f3
|
@ -13,29 +13,29 @@ use Symfony\Component\Routing\Attribute\Route;
|
|||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
#[AsController]
|
||||
#[Route(path: '/rankings/{metric}', name: self::ROUTE_NAME, methods: [Request::METHOD_GET])]
|
||||
#[Route(path: '/rankings/{metric?}/{world?}', name: self::ROUTE_NAME, methods: [Request::METHOD_GET])]
|
||||
#[Template(template: 'website/leaderboard.html.twig')]
|
||||
final readonly class LeaderboardController
|
||||
{
|
||||
public const string ROUTE_NAME = 'app_website_leaderboard';
|
||||
private const string DEFAULT_METRIC = 'frags';
|
||||
private const string DEFAULT_WORLD = 'playground';
|
||||
|
||||
public function __construct(
|
||||
private UrlGeneratorInterface $urlGenerator,
|
||||
) {}
|
||||
|
||||
public function __invoke(null | string $metric = null): array | RedirectResponse
|
||||
public function __invoke(null | string $metric = null, null | string $world = null): array | RedirectResponse
|
||||
{
|
||||
if (null === $metric) {
|
||||
$url = $this->urlGenerator->generate(
|
||||
name: self::ROUTE_NAME,
|
||||
parameters: ['metric' => self::DEFAULT_METRIC],
|
||||
);
|
||||
$parameters = ['metric' => $metric ?? self::DEFAULT_METRIC, 'world' => $world ?? self::DEFAULT_WORLD];
|
||||
$url = $this->urlGenerator->generate(name: self::ROUTE_NAME, parameters: $parameters);
|
||||
return new RedirectResponse(url: $url, status: Response::HTTP_FOUND);
|
||||
}
|
||||
|
||||
return [
|
||||
'metric' => $metric,
|
||||
'world' => $world,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,16 @@
|
|||
|
||||
{%- block init -%}
|
||||
{{- parent() -}}
|
||||
{%- do app_page_title.setPage('Leaderboards') -%}
|
||||
{%- do app_page_title.setPage(world ? 'Local leaderboard' : 'Global leaderboard') -%}
|
||||
{%- do app_page_title.setWorld(world) -%}
|
||||
{%- do app_page_title.setItem(metric) -%}
|
||||
{%- endblock -%}
|
||||
|
||||
{% block content %}
|
||||
<h1>Leaderboard page for metric <q>{{ metric }}</q></h1>
|
||||
{% if world %}
|
||||
<h1>Local leaderboard page for metric <q>{{ metric }}</q> in world <q>{{ world }}</q></h1>
|
||||
{% else %}
|
||||
<h1>Global leaderboard for metric <q>{{ metric }}</q></h1>
|
||||
{% endif %}
|
||||
<p>Lorem ipsum...</p>
|
||||
{% endblock %}
|
||||
|
|
Reference in a new issue