Files
mareike/app/Enumerations/RefundReason.php

66 lines
1.8 KiB
PHP

<?php
namespace App\Enumerations;
use App\Scopes\CommonModel;
/**
* Gründe für die Erstattung eines Teilnahmebeitrags -- DB-gestützt (analog {@see TaxExemptionReason}),
* damit Label und der auf dem Beleg ausgewiesene Text zentral pflegbar sind.
*
* @property string $slug
* @property string $name
* @property string|null $document_text
* @property bool $requires_note
* @property int $sort_order
*/
class RefundReason extends CommonModel
{
public const string SICKNESS = 'sickness';
public const string EVENT_CANCELLED = 'event_cancelled';
public const string OTHER = 'other';
protected $table = 'refund_reasons';
protected $primaryKey = 'slug';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'slug',
'name',
'document_text',
'requires_note',
'sort_order',
];
protected $casts = [
'requires_note' => 'boolean',
'sort_order' => 'integer',
];
/**
* Der Text, der auf dem Beleg unter „Grund" steht. Bei einem Grund, der einen Freitext verlangt,
* ist der hinterlegte Text der der Aktionsleitung.
*/
public function documentText(?string $note = null): string
{
return $this->requires_note ? trim((string) $note) : (string) $this->document_text;
}
/**
* Optionen für das Frontend. `requiresNote` steuert dort das Freitextfeld.
*
* @return array<int, array{value: string, label: string, requiresNote: bool}>
*/
public static function options(): array
{
return self::orderBy('sort_order')->get()
->map(static fn (self $reason): array => [
'value' => $reason->slug,
'label' => $reason->name,
'requiresNote' => $reason->requires_note,
])
->all();
}
}