39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
class ContactPrefillColumns
|
||
|
|
{
|
||
|
|
public const MAP = [
|
||
|
|
'' => '— Keine Vorbefüllung —',
|
||
|
|
'name' => 'Name',
|
||
|
|
'email' => 'E-Mail',
|
||
|
|
'vehicle_registration_place' => 'KFZ Nummernschild',
|
||
|
|
];
|
||
|
|
|
||
|
|
public static function isValid(string $column): bool
|
||
|
|
{
|
||
|
|
return $column === '' || array_key_exists($column, self::MAP);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function sanitize(string $column): string
|
||
|
|
{
|
||
|
|
return self::isValid($column) ? $column : '';
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function columns(): array
|
||
|
|
{
|
||
|
|
return array_keys(array_filter(self::MAP, static function (string $label, string $key): bool {
|
||
|
|
return $key !== '';
|
||
|
|
}, ARRAY_FILTER_USE_BOTH));
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function resolve(array $contactRow, string $column): string
|
||
|
|
{
|
||
|
|
if ($column === '' || !self::isValid($column)) {
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
|
||
|
|
return trim((string) ($contactRow[$column] ?? ''));
|
||
|
|
}
|
||
|
|
}
|