2018-07-21 18:15:07 +02:00
|
|
|
<?php
|
2022-07-01 15:10:30 +02:00
|
|
|
|
2022-08-18 22:52:01 +02:00
|
|
|
final class FrontpageAction implements ActionInterface
|
2018-07-21 18:15:07 +02:00
|
|
|
{
|
2024-08-07 00:21:06 +02:00
|
|
|
public function __invoke(Request $request): Response
|
2022-08-06 22:46:28 +02:00
|
|
|
{
|
2023-08-03 03:10:24 +02:00
|
|
|
$messages = [];
|
2022-11-07 18:22:54 +01:00
|
|
|
$activeBridges = 0;
|
2022-08-18 22:52:01 +02:00
|
|
|
|
|
|
|
$bridgeFactory = new BridgeFactory();
|
|
|
|
$bridgeClassNames = $bridgeFactory->getBridgeClassNames();
|
|
|
|
|
2023-08-03 03:10:24 +02:00
|
|
|
foreach ($bridgeFactory->getMissingEnabledBridges() as $missingEnabledBridge) {
|
|
|
|
$messages[] = [
|
|
|
|
'body' => sprintf('Warning : Bridge "%s" not found', $missingEnabledBridge),
|
|
|
|
'level' => 'warning'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-11-07 18:22:54 +01:00
|
|
|
$body = '';
|
2022-08-18 22:52:01 +02:00
|
|
|
foreach ($bridgeClassNames as $bridgeClassName) {
|
2023-06-11 03:16:03 +02:00
|
|
|
if ($bridgeFactory->isEnabled($bridgeClassName)) {
|
2024-01-25 18:20:02 +01:00
|
|
|
$body .= BridgeCard::render($bridgeClassName, $request);
|
2022-11-07 18:22:54 +01:00
|
|
|
$activeBridges++;
|
2022-07-01 15:10:30 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-21 18:15:07 +02:00
|
|
|
|
2024-01-25 13:03:00 +01:00
|
|
|
// todo: cache this renderered template?
|
2024-08-07 00:21:06 +02:00
|
|
|
return new Response(render(__DIR__ . '/../templates/frontpage.html.php', [
|
2023-08-03 03:10:24 +02:00
|
|
|
'messages' => $messages,
|
2022-11-07 18:22:54 +01:00
|
|
|
'admin_email' => Configuration::getConfig('admin', 'email'),
|
2022-11-07 18:36:52 +01:00
|
|
|
'admin_telegram' => Configuration::getConfig('admin', 'telegram'),
|
2022-11-07 18:22:54 +01:00
|
|
|
'bridges' => $body,
|
|
|
|
'active_bridges' => $activeBridges,
|
|
|
|
'total_bridges' => count($bridgeClassNames),
|
2024-08-07 00:21:06 +02:00
|
|
|
]));
|
2018-07-21 18:15:07 +02:00
|
|
|
}
|
|
|
|
}
|