WIP Impelement more stuff

This commit is contained in:
Björn Fromme
2023-10-04 15:10:16 +02:00
parent dec8feedf2
commit cc1ab396af
35 changed files with 928 additions and 177 deletions
+4
View File
@@ -15,6 +15,10 @@ class AppExtension extends AbstractExtension
new TwigFilter('file_icon', [AppRuntime::class, 'fileIconFilter'], ['is_safe' => ['html']]),
new TwigFilter('date_diff', [AppRuntime::class, 'dateDiffForHumans']),
new TwigFilter('format_money', [AppRuntime::class, 'formatMoney']),
new TwigFilter('license_label', [AppRuntime::class, 'licenseLabel']),
new TwigFilter('teamer_status_label', [AppRuntime::class, 'teamerStatusLabel']),
new TwigFilter('bpn_country_label', [AppRuntime::class, 'bpnCountryLabel']),
new TwigFilter('bpn_pickup_label', [AppRuntime::class, 'bpnPickupLabel']),
];
}
+42
View File
@@ -2,6 +2,10 @@
namespace App\Twig;
use App\BusProNet\DataProvider\Countries;
use App\BusProNet\DataProvider\Pickups;
use App\BusProNet\Model\Country;
use App\Entity\Teamer;
use Carbon\Carbon;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Environment;
@@ -13,10 +17,48 @@ class AppRuntime implements RuntimeExtensionInterface
public function __construct(
private readonly RequestStack $requestStack,
private readonly IntlExtension $intlExtension,
private readonly Countries $countries,
private readonly Pickups $pickups,
private readonly string $environment
) {
}
public function teamerStatusLabel(string $status): string
{
if (Teamer::STATUS_NEW === $status) {
return 'Neuteamer';
}
return 'Bestandsteamer';
}
public function licenseLabel(string $type): string
{
return sprintf('Offizielle %slehrer*innenlizenz', ucfirst(strtolower($type)));
}
public function bpnCountryLabel(string $token, string $property = 'name'): string
{
$country = $this->countries->get($token);
if (null === $country) {
return 'unbekannt';
}
return 'nationality' === $property ? $country->getNationality() : $country->getName();
}
public function bpnPickupLabel(int $id): string
{
$pickup = $this->pickups->get($id);
if (null === $pickup) {
return 'unbekannt';
}
return $pickup->getCity();
}
public function fileIconFilter(Environment $environment, string $mimeType, ?string $classes = 'w-4 h-4'): string
{
$icon = match ($mimeType) {