76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Enumerations;
|
|
|
|
use App\Models\GlobalSetting;
|
|
use App\Repositories\GlobalSettingRepository;
|
|
|
|
/**
|
|
* Wonach eine Veranstaltung bei der Anmeldung fragt: nach der Local Group (Mandant, im UI z. B. „Stamm") oder nach
|
|
* der Parent Group (übergeordnete Gruppe, im UI z. B. „Bund"). Die Bezeichnungen kommen aus den globalen
|
|
* Einstellungen.
|
|
*/
|
|
enum ParticipantGroupType: string
|
|
{
|
|
case LocalGroup = 'local_group';
|
|
case ParentGroup = 'parent_group';
|
|
|
|
public function label(): string
|
|
{
|
|
return match ($this) {
|
|
self::LocalGroup => self::setting(GlobalSetting::LOCAL_GROUP_LABEL, 'Stamm'),
|
|
self::ParentGroup => self::setting(GlobalSetting::PARENT_GROUP_LABEL, 'Bund'),
|
|
};
|
|
}
|
|
|
|
public function pluralLabel(): string
|
|
{
|
|
return match ($this) {
|
|
self::LocalGroup => self::setting(GlobalSetting::LOCAL_GROUP_LABEL_PLURAL, 'Stämme'),
|
|
self::ParentGroup => self::setting(GlobalSetting::PARENT_GROUP_LABEL_PLURAL, 'Bünde'),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Optionen für das Frontend: [['value' => ..., 'label' => ...], ...].
|
|
*
|
|
* @return array<int, array{value: string, label: string}>
|
|
*/
|
|
public static function options(): array
|
|
{
|
|
return array_map(
|
|
static fn (self $type): array => [
|
|
'value' => $type->value,
|
|
'label' => $type->label(),
|
|
],
|
|
self::cases(),
|
|
);
|
|
}
|
|
|
|
/** Typ zu einem gespeicherten Wert; Unbekanntes fällt auf die Local Group zurück. */
|
|
public static function fromStored(?string $value): self
|
|
{
|
|
return self::tryFrom((string) $value) ?? self::LocalGroup;
|
|
}
|
|
|
|
/**
|
|
* Alle Bezeichnungen fürs Frontend (Shared Prop).
|
|
*
|
|
* @return array{localGroup: string, localGroupPlural: string, parentGroup: string, parentGroupPlural: string}
|
|
*/
|
|
public static function labels(): array
|
|
{
|
|
return [
|
|
'localGroup' => self::LocalGroup->label(),
|
|
'localGroupPlural' => self::LocalGroup->pluralLabel(),
|
|
'parentGroup' => self::ParentGroup->label(),
|
|
'parentGroupPlural' => self::ParentGroup->pluralLabel(),
|
|
];
|
|
}
|
|
|
|
private static function setting(string $key, string $default): string
|
|
{
|
|
return app(GlobalSettingRepository::class)->get($key, $default);
|
|
}
|
|
}
|